termkit 0.0.0 → 0.1.0

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.ackrc +7 -0
  3. data/.editorconfig +14 -0
  4. data/.gitignore +5 -1
  5. data/.gitlab-ci.yml +70 -0
  6. data/.rdoc_options +21 -0
  7. data/.travis.yml +5 -1
  8. data/Gemfile +8 -0
  9. data/Makefile +16 -1
  10. data/Makefile.common +5 -3
  11. data/README.md +2 -1
  12. data/bin/build_info.sh +22 -0
  13. data/bin/dev +10 -0
  14. data/lib/termkit.rb +32 -0
  15. data/lib/termkit/app/app.rb +61 -0
  16. data/lib/termkit/app/app_curses.rb +159 -0
  17. data/lib/termkit/app/app_ui.rb +153 -0
  18. data/lib/termkit/controller/controller.rb +58 -0
  19. data/lib/termkit/controller/controller_app.rb +22 -0
  20. data/lib/termkit/controller/controller_view.rb +28 -0
  21. data/lib/termkit/event/event.rb +14 -0
  22. data/lib/termkit/event/event_key.rb +33 -0
  23. data/lib/termkit/event/event_later.rb +16 -0
  24. data/lib/termkit/exception/exception_event_key_unhandled.rb +11 -0
  25. data/lib/termkit/exception/exception_event_unhandled.rb +18 -0
  26. data/lib/termkit/exception/exception_initialized_not_class_parent.rb +17 -0
  27. data/lib/termkit/exception/exception_std.rb +11 -0
  28. data/lib/termkit/misc/curses_color.rb +23 -0
  29. data/lib/termkit/misc/point.rb +114 -0
  30. data/lib/termkit/misc/rect.rb +116 -0
  31. data/lib/termkit/misc/size.rb +29 -0
  32. data/lib/termkit/model/model.rb +16 -0
  33. data/lib/termkit/version.rb +5 -4
  34. data/lib/termkit/view/content_view.rb +59 -0
  35. data/lib/termkit/view/content_view_clear.rb +20 -0
  36. data/lib/termkit/view/row_grid_view.rb +12 -0
  37. data/lib/termkit/view/view.rb +825 -0
  38. data/lib/termkit/view/view_grid.rb +12 -0
  39. data/lib/termkit/view/view_table.rb +296 -0
  40. data/lib/termkit/view/view_table_cell.rb +38 -0
  41. data/lib/termkit/view/view_text.rb +63 -0
  42. data/termkit.gemspec +8 -0
  43. data/termkit.sublime-project +2 -2
  44. metadata +120 -5
  45. data/tests/ts_all.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6770eb73c73bd20e0f77c236eb37b273b06f15c
4
- data.tar.gz: c9ce9e4938d9a72abf0c884d8888983e70e86ed6
3
+ metadata.gz: f349541a321abf4e99c77c41a7f3a77549f0ef55
4
+ data.tar.gz: 690a15bd0ab52b594f140fa015446b011be0dec6
5
5
  SHA512:
6
- metadata.gz: d16a0c4b0038157e8b4ddd9b9e99a7b1a1438c145b272f9beeefc6462617e51d5f847ceb9d81bd6a8f16982d51ee4e378350040e6faf16aaa07dd3e0d668abc4
7
- data.tar.gz: 1e1a35bee654a35afd72e5691f8e0727232dbfbe018edd162dc660779ae84dbb479d09e71ded7c01a3286e5f4df0821f815e4ff58f3d7d8f695d34d6c1e20199
6
+ metadata.gz: a9697742ccb5ded5120feceab7478f57d6ed2b45f62180871eabaa32a20031afe6df6c8cc75ffcecf24d1345a0a0735483525c7edb085f3dd2a76f95c24fa027
7
+ data.tar.gz: 8d1667a59f74a3742aafb34a14b33622f6322d8621cb498c2011b12f030088de503252a93b6845d163dd32fc94103834590138d96715d63b9ea01a2ebc8e7c44
data/.ackrc ADDED
@@ -0,0 +1,7 @@
1
+
2
+ --type=ruby
3
+ --type=yaml
4
+
5
+ --ignore-dir=.bundle
6
+ --ignore-dir=releases
7
+ --ignore-dir=tmp
@@ -0,0 +1,14 @@
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ indent_style = tab
7
+ indent_size = 4
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = false
11
+ insert_final_newline = true
12
+
13
+ [*.yml]
14
+ indent_style = space
data/.gitignore CHANGED
@@ -1,5 +1,9 @@
1
1
  /.bundle/
2
2
  .setup
3
3
  CHANGELOG-*.txt
4
+ /coverage/
5
+ /doc/
4
6
  Gemfile.lock
5
- /releases/
7
+ /releases/
8
+ /tmp/
9
+ *.log
@@ -0,0 +1,70 @@
1
+ before_script:
2
+ - apt-get update -yqq
3
+ - 'which ssh-agent || ( apt-get install openssh-client -y )'
4
+ - 'which rsync || ( apt-get install rsync -yqq --force-yes )'
5
+ - eval $(ssh-agent -s)
6
+ - ssh-add <(echo "$SSH_PRIVATE_KEY")
7
+ - mkdir -p ~/.ssh
8
+ - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
9
+ - ruby -v
10
+ - gem update --system
11
+ - gem install bundler -v '~>1.13'
12
+ - bundler --version
13
+ - make
14
+
15
+ stages:
16
+ - test
17
+ - release
18
+ - deploy
19
+
20
+ test_21:
21
+ image: ruby:2.1
22
+ stage: test
23
+ environment: test
24
+ only:
25
+ - tags
26
+ script:
27
+ - make test
28
+
29
+ test_22:
30
+ image: ruby:2.2
31
+ stage: test
32
+ environment: test
33
+ only:
34
+ - tags
35
+ script:
36
+ - make test
37
+
38
+ test_23:
39
+ image: ruby:2.3
40
+ stage: test
41
+ environment: test
42
+ only:
43
+ - tags
44
+ script:
45
+ - make test
46
+
47
+ release_gem:
48
+ image: ruby:2.3
49
+ stage: release
50
+ environment: gem
51
+ only:
52
+ - tags
53
+ script:
54
+ - mkdir -p ~/.gem
55
+ - 'printf "%s\n:rubygems_api_key: %s" "---" "${RUBYGEMSORG_API_KEY}" > ~/.gem/credentials; chmod 0600 ~/.gem/credentials'
56
+ - make release
57
+
58
+ deploy_homepage:
59
+ image: ruby:2.3
60
+ stage: deploy
61
+ environment: homepage
62
+ only:
63
+ - tags
64
+ script:
65
+ - make cov
66
+ - make doc
67
+ - bin/build_info.sh > build.txt
68
+ - 'rsync ${RSYNC_OPTIONS} coverage ${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_REMOTE_PATH}'
69
+ - 'rsync ${RSYNC_OPTIONS} doc ${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_REMOTE_PATH}'
70
+ - 'rsync ${RSYNC_OPTIONS} build.txt ${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_REMOTE_PATH}'
@@ -0,0 +1,21 @@
1
+ --- !ruby/object:RDoc::Options
2
+ encoding: UTF-8
3
+ static_path: []
4
+ rdoc_include: []
5
+ charset: UTF-8
6
+ exclude: []
7
+ hyperlink_all: false
8
+ line_numbers: true
9
+ locale: en
10
+ locale_dir: locale
11
+ locale_name:
12
+ main_page: README.md
13
+ markup: markdown
14
+ output_decoration: true
15
+ page_dir:
16
+ show_hash: false
17
+ tab_width: 4
18
+ template_stylesheets: []
19
+ title: TermKit
20
+ visibility: :protected
21
+ webcvs:
@@ -2,10 +2,14 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1
4
4
  - 2.2
5
+ - 2.3
6
+ - 2.4.0-preview2
7
+ - ruby-head
5
8
  sudo: required
6
9
  before_install:
10
+ - gem --version
7
11
  - gem update --system
8
- - gem install bundler -v '~>1.11'
12
+ - gem install bundler -v '~>1.13'
9
13
  - bundler --version
10
14
  install:
11
15
  - make
data/Gemfile CHANGED
@@ -1,3 +1,11 @@
1
1
 
2
2
  source 'https://rubygems.org'
3
+
4
+ group(:development) do
5
+ if ENV['SIMPLECOV_PHPUNIT_LOAD_PATH']
6
+ # Load SimpleCov PHPUnit Formatter from a local path.
7
+ gem 'simplecov-phpunit', :path => ENV['SIMPLECOV_PHPUNIT_LOAD_PATH']
8
+ end
9
+ end
10
+
3
11
  gemspec
data/Makefile CHANGED
@@ -3,6 +3,21 @@ GEM_NAME = termkit
3
3
 
4
4
  include Makefile.common
5
5
 
6
+ .PHONY: dev
7
+ dev:
8
+ $(BUNDLER) exec ./bin/dev
9
+
6
10
  .PHONY: test
7
11
  test:
8
- RUBYOPT=-w $(BUNDLER) exec ./tests/ts_all.rb
12
+ RUBYOPT=-w TZ=Europe/Vienna $(BUNDLER) exec ./test/suite_all.rb -v
13
+
14
+ .PHONY: cov
15
+ cov:
16
+ RUBYOPT=-w TZ=Europe/Vienna COVERAGE=1 $(BUNDLER) exec ./test/suite_all.rb -v
17
+
18
+ .PHONY: cov_local
19
+ cov_local:
20
+ RUBYOPT=-w TZ=Europe/Vienna SIMPLECOV_PHPUNIT_LOAD_PATH=../simplecov-phpunit COVERAGE=1 $(BUNDLER) exec ./test/suite_all.rb -v
21
+
22
+ doc:
23
+ rdoc README.md lib/termkit
@@ -1,12 +1,11 @@
1
1
 
2
- # Ruby Common Big
3
- # 2016-05-20
2
+ # Ruby Common Big 2016-10-22
4
3
 
5
4
  MV = mv -nv
6
5
  RM = rm -rfd
7
6
  MKDIR = mkdir -p
8
7
  CHMOD = chmod
9
- BUNDLER = bundle
8
+ BUNDLER = bundler
10
9
  BUNDLER_OPTIONS = --jobs=5 --retry=3
11
10
  GEMSPEC_FILE = $(GEM_NAME).gemspec
12
11
 
@@ -17,6 +16,9 @@ all: setup $(ALL_TARGETS_EXT)
17
16
  setup: .setup
18
17
 
19
18
  .setup:
19
+ which ruby &> /dev/null
20
+ which $(BUNDLER) &> /dev/null
21
+ ruby -v
20
22
  $(BUNDLER) install $(BUNDLER_OPTIONS)
21
23
  touch $@
22
24
 
data/README.md CHANGED
@@ -15,12 +15,13 @@ or via `Gemfile`:
15
15
 
16
16
  ## Project Links
17
17
 
18
+ - [Homepage](https://termkit.fox21.at/)
18
19
  - [TermKit Gem](https://rubygems.org/gems/termkit)
19
20
  - [Travis CI Repository](https://travis-ci.org/TheFox/termkit)
20
21
 
21
22
  ## License
22
23
 
23
- Copyright (C) 2016 Christian Mayer <http://fox21.at>
24
+ Copyright (C) 2016 Christian Mayer <https://fox21.at>
24
25
 
25
26
  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
26
27
 
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+
3
+ DATE=$(date +"%F %T %z")
4
+ SCRIPT_BASEDIR=$(dirname $0)
5
+
6
+
7
+ cd "${SCRIPT_BASEDIR}/.."
8
+
9
+ RUBY_VERSION=$(ruby -e "print RUBY_VERSION")
10
+ TERMKIT_VERSION=$(ruby -I lib/termkit -rversion -e "print %{#{TheFox::TermKit::VERSION} (#{TheFox::TermKit::DATE})}")
11
+
12
+ printf "%s
13
+
14
+ ruby: %s
15
+ termkit: %s
16
+
17
+ --- build ---
18
+ id: %s
19
+ ref: %s@%s
20
+ stage: %s
21
+ server: %s %s
22
+ " "${DATE}" "${RUBY_VERSION}" "${TERMKIT_VERSION}" "${CI_BUILD_ID}" "${CI_BUILD_REF}" "${CI_BUILD_REF_NAME}" "${CI_BUILD_STAGE}" "${CI_SERVER_NAME}" "${CI_SERVER_VERSION}"
data/bin/dev ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ require 'pry'
5
+ require 'termkit'
6
+ require 'curses'
7
+
8
+ include TheFox::TermKit
9
+
10
+ binding.pry
@@ -1,2 +1,34 @@
1
1
 
2
2
  require 'termkit/version'
3
+
4
+ require 'termkit/misc/curses_color'
5
+ require 'termkit/misc/point'
6
+ require 'termkit/misc/size'
7
+ require 'termkit/misc/rect'
8
+
9
+ require 'termkit/exception/exception_std'
10
+ require 'termkit/exception/exception_event_unhandled'
11
+ require 'termkit/exception/exception_event_key_unhandled'
12
+ require 'termkit/exception/exception_initialized_not_class_parent'
13
+
14
+ require 'termkit/event/event'
15
+ require 'termkit/event/event_key'
16
+
17
+ require 'termkit/model/model'
18
+
19
+ require 'termkit/view/content_view'
20
+ require 'termkit/view/content_view_clear'
21
+ require 'termkit/view/row_grid_view'
22
+ require 'termkit/view/view'
23
+ require 'termkit/view/view_grid'
24
+ require 'termkit/view/view_text'
25
+ require 'termkit/view/view_table'
26
+ require 'termkit/view/view_table_cell'
27
+
28
+ require 'termkit/controller/controller'
29
+ require 'termkit/controller/controller_app'
30
+ require 'termkit/controller/controller_view'
31
+
32
+ require 'termkit/app/app'
33
+ require 'termkit/app/app_ui'
34
+ require 'termkit/app/app_curses'
@@ -0,0 +1,61 @@
1
+
2
+ require 'logger'
3
+
4
+ module TheFox
5
+ module TermKit
6
+
7
+ class App
8
+
9
+ attr_accessor :logger
10
+
11
+ def initialize
12
+ @exit = false
13
+
14
+ @logger = Logger.new('termkit_app.log')
15
+ @logger.level = Logger::DEBUG
16
+ end
17
+
18
+ ##
19
+ # Calls `run_cycle()` in a loop.
20
+ def run
21
+ #puts 'App run'
22
+
23
+ loop_cycle = 0
24
+ while !@exit
25
+ loop_cycle += 1
26
+
27
+ run_cycle
28
+ #sleep @run_cycle_sleep
29
+ end
30
+ end
31
+
32
+ ##
33
+ # As single cycle of `run()`.
34
+ def run_cycle
35
+ #puts 'App run_cycle'
36
+ end
37
+
38
+ ##
39
+ # Call this to terminate the App.
40
+ def terminate
41
+ if !@exit
42
+ # puts 'App->terminate'
43
+
44
+ @exit = true
45
+
46
+ app_will_terminate
47
+ end
48
+ end
49
+
50
+ protected
51
+
52
+ ##
53
+ # This can be implemented by a sub-class of App.
54
+ def app_will_terminate
55
+ # puts 'App->app_will_terminate'
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,159 @@
1
+
2
+ require 'curses'
3
+ #require 'io/console'
4
+
5
+ module TheFox
6
+ module TermKit
7
+
8
+ # Default Curses read input timeout.
9
+ CURSES_TIMEOUT = 200
10
+
11
+ class CursesApp < UIApp
12
+
13
+ def initialize
14
+ @curses_timeout = CURSES_TIMEOUT
15
+
16
+ @ui_inited = false
17
+ @ui_closed = false
18
+
19
+ super()
20
+
21
+ #puts 'CursesApp->initialize'
22
+ end
23
+
24
+ def curses_timeout=(curses_timeout)
25
+ @curses_timeout = curses_timeout
26
+ Curses.timeout = @curses_timeout
27
+ end
28
+
29
+ ##
30
+ # See UIApp `run_cycle()` method.
31
+ def run_cycle
32
+ super()
33
+
34
+ #puts 'CursesApp->run_cycle'
35
+
36
+ handle_user_input
37
+ end
38
+
39
+ ##
40
+ # See UIApp `draw_point()` method.
41
+ def draw_point(point, content)
42
+ # @logger.debug("draw_point #{point} #{content.inspect}")
43
+
44
+ content_s = content
45
+ foreground_color = nil
46
+ background_color = nil
47
+ if content.is_a?(ViewContent)
48
+ # @logger.debug("draw_point #{point} content is ViewContent")
49
+
50
+ content_s = content.char
51
+
52
+ # @logger.debug("draw_point #{point} #{content.foreground_color} #{content.background_color}")
53
+
54
+ foreground_color = CursesColor::COLORS[content.foreground_color]
55
+ background_color = CursesColor::COLORS[content.background_color]
56
+ end
57
+
58
+ c_attr = Curses::A_NORMAL
59
+
60
+ if !foreground_color.nil? && !background_color.nil?
61
+ Curses.init_pair(1, foreground_color, background_color)
62
+ c_attr = Curses.color_pair(1)
63
+ end
64
+
65
+ # @logger.debug("draw_point #{point} '#{content_s}' #{foreground_color.inspect} #{background_color.inspect}")
66
+
67
+ begin
68
+ Curses.setpos(point.y, point.x)
69
+ Curses.attron(c_attr) do
70
+ Curses.addstr(content_s)
71
+ end
72
+ rescue Exception => e
73
+ @logger.error("draw_point: #{e}")
74
+ end
75
+
76
+ # @logger.debug("draw_point #{point} #{content.inspect} DONE")
77
+ end
78
+
79
+ ##
80
+ # See UIApp `ui_refresh()` method.
81
+ def ui_refresh
82
+ Curses.refresh
83
+ end
84
+
85
+ ##
86
+ # See UIApp `ui_max_x()` method.
87
+ def ui_max_x
88
+ Curses.cols
89
+ end
90
+
91
+ ##
92
+ # See UIApp `ui_max_y()` method.
93
+ def ui_max_y
94
+ Curses.rows
95
+ end
96
+
97
+ protected
98
+
99
+ ##
100
+ # See UIApp `ui_init()` method.
101
+ def ui_init
102
+ #puts "CursesApp->ui_init '#{@curses_timeout}'"
103
+
104
+ raise 'ui already initialized' if @ui_inited
105
+ @ui_inited = true
106
+
107
+ super()
108
+
109
+ # @logger.debug("init Curses")
110
+
111
+ Curses.noecho
112
+ Curses.timeout = @curses_timeout
113
+ Curses.curs_set(0)
114
+ Curses.init_screen
115
+ Curses.start_color
116
+ Curses.use_default_colors
117
+ Curses.crmode
118
+ Curses.stdscr.keypad(true)
119
+
120
+ # @logger.debug("color_pairs: #{Curses.color_pairs}")
121
+
122
+ # Curses.init_pair(1, Curses::COLOR_BLACK, Curses::COLOR_GREEN)
123
+
124
+ # Curses.setpos(0, 0)
125
+ # Curses.addstr('INIT OK')
126
+ # Curses.refresh
127
+ end
128
+
129
+ ##
130
+ # See UIApp `ui_close()` method.
131
+ def ui_close
132
+ #puts "CursesApp->ui_close"
133
+
134
+ raise 'ui already closed' if @ui_closed
135
+ @ui_closed = true
136
+
137
+ # Curses.setpos(10, 0)
138
+ # Curses.addstr('CLOSE ')
139
+ # Curses.refresh
140
+ # sleep(2)
141
+
142
+ Curses.refresh
143
+ Curses.stdscr.clear
144
+ Curses.stdscr.refresh
145
+ Curses.stdscr.close
146
+ Curses.close_screen
147
+ end
148
+
149
+ private
150
+
151
+ def handle_user_input
152
+ key_down(Curses.getch)
153
+ #key_down(IO.console.getch)
154
+ end
155
+
156
+ end
157
+
158
+ end
159
+ end