reterm 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +131 -0
  4. data/designer/main.rb +10 -0
  5. data/designer/src/ComponentParams.rb +120 -0
  6. data/designer/src/ComponentsList.rb +90 -0
  7. data/designer/src/CreatedList.rb +156 -0
  8. data/designer/src/Designer.rb +114 -0
  9. data/designer/src/ToggleArea.rb +67 -0
  10. data/designer/src/common.rb +1 -0
  11. data/designer/src/component_factory.rb +30 -0
  12. data/designer/src/component_map.rb +116 -0
  13. data/designer/src/glade/ComponentParams.glade +96 -0
  14. data/designer/src/glade/Designer.glade +184 -0
  15. data/designer/src/images/add.png +0 -0
  16. data/designer/src/images/asciitext.png +0 -0
  17. data/designer/src/images/blank.png +0 -0
  18. data/designer/src/images/blank_sm.png +0 -0
  19. data/designer/src/images/button.png +0 -0
  20. data/designer/src/images/dial.png +0 -0
  21. data/designer/src/images/entry.png +0 -0
  22. data/designer/src/images/hslider.png +0 -0
  23. data/designer/src/images/label.png +0 -0
  24. data/designer/src/images/matrix.png +0 -0
  25. data/designer/src/images/orig/Check.png +0 -0
  26. data/designer/src/images/orig/ascii_text.png +0 -0
  27. data/designer/src/images/orig/button.png +0 -0
  28. data/designer/src/images/orig/dial.png +0 -0
  29. data/designer/src/images/orig/entry.png +0 -0
  30. data/designer/src/images/orig/hslider.png +0 -0
  31. data/designer/src/images/orig/label.png +0 -0
  32. data/designer/src/images/orig/matrix.png +0 -0
  33. data/designer/src/images/orig/radio.png +0 -0
  34. data/designer/src/images/orig/rocker.png +0 -0
  35. data/designer/src/images/orig/slist.png +0 -0
  36. data/designer/src/images/orig/vslider.png +0 -0
  37. data/designer/src/images/radio.png +0 -0
  38. data/designer/src/images/remove.png +0 -0
  39. data/designer/src/images/rocker.png +0 -0
  40. data/designer/src/images/slist.png +0 -0
  41. data/designer/src/images/vslider.png +0 -0
  42. data/lib/reterm.rb +22 -0
  43. data/lib/reterm/color_pair.rb +66 -0
  44. data/lib/reterm/component.rb +40 -0
  45. data/lib/reterm/components.rb +32 -0
  46. data/lib/reterm/components/ascii_text.rb +46 -0
  47. data/lib/reterm/components/button.rb +31 -0
  48. data/lib/reterm/components/dial.rb +95 -0
  49. data/lib/reterm/components/dialog.rb +34 -0
  50. data/lib/reterm/components/entry.rb +38 -0
  51. data/lib/reterm/components/hslider.rb +32 -0
  52. data/lib/reterm/components/image.rb +55 -0
  53. data/lib/reterm/components/label.rb +20 -0
  54. data/lib/reterm/components/matrix.rb +43 -0
  55. data/lib/reterm/components/radio.rb +33 -0
  56. data/lib/reterm/components/rocker.rb +71 -0
  57. data/lib/reterm/components/slist.rb +32 -0
  58. data/lib/reterm/components/template.rb +23 -0
  59. data/lib/reterm/components/vslider.rb +61 -0
  60. data/lib/reterm/init.rb +95 -0
  61. data/lib/reterm/layout.rb +63 -0
  62. data/lib/reterm/layouts.rb +16 -0
  63. data/lib/reterm/layouts/horizontal.rb +19 -0
  64. data/lib/reterm/layouts/vertical.rb +19 -0
  65. data/lib/reterm/loader.rb +126 -0
  66. data/lib/reterm/menu.rb +81 -0
  67. data/lib/reterm/mixins/cdk_component.rb +45 -0
  68. data/lib/reterm/mixins/component_input.rb +37 -0
  69. data/lib/reterm/mixins/event_dispatcher.rb +20 -0
  70. data/lib/reterm/mixins/nav_input.rb +126 -0
  71. data/lib/reterm/panel.rb +37 -0
  72. data/lib/reterm/resize.rb +27 -0
  73. data/lib/reterm/terminal.rb +33 -0
  74. data/lib/reterm/version.rb +3 -0
  75. data/lib/reterm/window.rb +260 -0
  76. metadata +155 -0
@@ -0,0 +1,37 @@
1
+ module RETerm
2
+ # Panels provide quick ways to switch between menus, pushing and
3
+ # poping them on/off an internal stack
4
+ class Panel
5
+ include EventDispatcher
6
+
7
+ # Initialize panel from the given window.
8
+ #
9
+ # This maintains an internal registry of panels created
10
+ # for event dispatching purposes
11
+ def initialize(window)
12
+ @@registry ||= {}
13
+
14
+ # panel already associated with window
15
+ raise ArgumentError, window if @@registry.key?(window)
16
+
17
+ @@registry[window] = self
18
+
19
+ @window = window
20
+ @panel = Ncurses::Panel::PANEL.new(@window.win)
21
+ end
22
+
23
+ # Render this panel by surfacing it ot hte top of the stack
24
+ def show
25
+ Ncurses::Panel.top_panel(@panel)
26
+ update_reterm
27
+
28
+ @@registry.values.each { |panel|
29
+ if panel == self
30
+ dispatch :panel_show
31
+ else
32
+ panel.dispatch :panel_hide
33
+ end
34
+ }
35
+ end
36
+ end # class Panel
37
+ end # module RETerm
@@ -0,0 +1,27 @@
1
+ module RETerm
2
+ # Seconds between terminal size syncs
3
+ RESIZE_TIME = 0.2
4
+
5
+ # Internal helper to track size of terminal.
6
+ # This is a simple mechanism that launches a
7
+ # worker thread to periodically poll terminal size.
8
+ def track_resize
9
+ @track_resize = true
10
+ d = Terminal.dimensions
11
+
12
+ @resize_thread = Thread.new {
13
+ while @track_resize
14
+ Terminal.reset!
15
+ t = Terminal.dimensions
16
+ Terminal.resize! if t != d
17
+ sleep(RESIZE_TIME)
18
+ end
19
+ }
20
+ end
21
+
22
+ # Terminate resize tracking thread (if running)
23
+ def stop_track_resize
24
+ @track_resize = false
25
+ @resize_thread.join if @resize_thread
26
+ end
27
+ end # module RETerm
@@ -0,0 +1,33 @@
1
+ module RETerm
2
+ # Provides helper mechanisms which to retrieve terminal
3
+ # information (dimensions, etc)
4
+ class Terminal
5
+ def self.reset!
6
+ @dimensions = nil
7
+ end
8
+
9
+ def self.dimensions
10
+ require 'terminfo'
11
+ @dimensions ||= TermInfo.screen_size
12
+ end
13
+
14
+ def self.load
15
+ dimensions
16
+ nil
17
+ end
18
+
19
+ def self.cols
20
+ dimensions[1]
21
+ end
22
+
23
+ def self.rows
24
+ dimensions[0]
25
+ end
26
+
27
+ def self.resize!
28
+ Window.top.each { |w|
29
+ w.dispatch :resize
30
+ }
31
+ end
32
+ end
33
+ end # module Terminal
@@ -0,0 +1,3 @@
1
+ module RETerm
2
+ VERSION = "0.4.2"
3
+ end # module RETerm
@@ -0,0 +1,260 @@
1
+ module RETerm
2
+ # Windows are areas rendered on screen, associated with components
3
+ # to be rendered in them. They specify the position to start drawing
4
+ # component as well as the maximum width and height. A border may be
5
+ # drawn around a window and a {ColorPair} associated.
6
+ #
7
+ # If Layout is added to a Window, children may subsequently be added.
8
+ # This should be performed via the Layout#add_child method.
9
+ #
10
+ # @example adding a layout to a window
11
+ # init_reterm {
12
+ # win = Window.new :rows => 50, :cols => 30
13
+ # layout = Layouts::Horizontal.new
14
+ # win.component = layout
15
+ #
16
+ # child = layout.add_child :rows => 5, :cols => 10
17
+ # child.class # => RETerm::Window
18
+ #
19
+ # label = Components::Label.new :text => "Hello World!"
20
+ # child.component = label
21
+ #
22
+ # update_reterm
23
+ # sleep(5)
24
+ # }
25
+ #
26
+ class Window
27
+ include EventDispatcher
28
+
29
+ attr_accessor :rows, :cols
30
+ attr_accessor :x, :y
31
+
32
+ attr_accessor :vborder
33
+ attr_accessor :hborder
34
+
35
+ attr_accessor :component
36
+
37
+ attr_reader :win
38
+
39
+ attr_reader :parent
40
+ attr_accessor :children
41
+
42
+ # Return bool indicating if this window has a component
43
+ # associated with it
44
+ def component?
45
+ !!@component
46
+ end
47
+
48
+ # Assign component to window. This will autoassign local
49
+ # window to component as well.
50
+ def component=(c)
51
+ c.window = self
52
+ c.colors = @colors if colored?
53
+ @component = c
54
+ end
55
+
56
+ # Return boolean if this window is a child of another
57
+ def parent?
58
+ !!@parent
59
+ end
60
+
61
+ # Instantiate Window with given args. None are required, but
62
+ # unless :rows, :cols, :x, or :y is specified, window will be
63
+ # created in it's default position.
64
+ #
65
+ # This method will generate a unique id for each window
66
+ # and add it to a static registery for subsequent tracking.
67
+ #
68
+ # @param [Hash] args arguments used to instantiate window
69
+ # @option args [Integer] :rows number of rows to assign to window
70
+ # @option args [Integer] :cols number of cols to assign to window
71
+ # @option args [Integer] :x starting x position of window
72
+ # @option args [Integer] :y starting y position of window
73
+ # @option args [Integer] :vborder vertical border char
74
+ # @option args [Integer] :hborder horizontal border char
75
+ # @option args [Component] :component component to assign to window
76
+ # @option args [Window] :parent parent to assign to window, if
77
+ # set window will be created a a child, else it will be
78
+ # independently created & tracked.
79
+ #
80
+ def initialize(args={})
81
+ @@registry ||= []
82
+ @@registry << self
83
+
84
+ @rows = args[:rows] || (Terminal.rows - 1)
85
+ @cols = args[:cols] || (Terminal.cols - 1)
86
+
87
+ @x = args[:x] || 0
88
+ @y = args[:y] || 0
89
+
90
+ @vborder = args[:vborder] || 0
91
+ @hborder = args[:hborder] || 0
92
+
93
+ self.component = args[:component] if args.key?(:component)
94
+
95
+ if args[:parent]
96
+ @parent = args[:parent]
97
+ @win = parent.win.derwin(@rows, @cols, @y, @x)
98
+
99
+ else
100
+ @parent = nil
101
+ @win = Ncurses::WINDOW.new(@rows, @cols, @y, @x)
102
+ end
103
+
104
+ Ncurses::keypad(@win, true)
105
+
106
+ @children = []
107
+
108
+
109
+ @@wid ||= 0
110
+ @@wid += 1
111
+
112
+ @window_id = @@wid
113
+ end
114
+
115
+ # Invoke window finalization routine by destroying it
116
+ # and all children
117
+ def finalize!
118
+ children.each { |c|
119
+ del_child c
120
+ cdk_scr.destroy if cdk?
121
+ component.finalize! if component?
122
+ }
123
+ end
124
+
125
+ # Return cdk screen (only used by CDK components)
126
+ def cdk_scr
127
+ enable_cdk!
128
+ @cdk_scr ||= CDK::SCREEN.new(@win)
129
+ end
130
+
131
+ # Return bool indicating if cdk is enabled for this window/component
132
+ def cdk?
133
+ !!@cdk_scr
134
+ end
135
+
136
+ # Static method returning all tracked windows
137
+ def self.all
138
+ @@registry ||= []
139
+ @@registry
140
+ end
141
+
142
+ # Static method returning top level windows
143
+ def self.top
144
+ @@registry ||= []
145
+ @@registry.select { |w| !w.parent? }
146
+ end
147
+
148
+ # Create child window, this method should not be invoked
149
+ # by end-user, rather it is is invoked the Layout#add_child
150
+ # is called.
151
+ def create_child(h={})
152
+ c = self.class.new h.merge(:parent => self)
153
+ c.colors = @colors if colored?
154
+ children << c
155
+ c
156
+ end
157
+
158
+ # Remove child window, like #add_child, this is used internally
159
+ # and should not be invoked by the end user
160
+ def del_child(child)
161
+ @children.delete(child)
162
+ @@registry.delete(child)
163
+ child.finalize!
164
+ child.win.delwin
165
+ end
166
+
167
+ # Clear window by removing all children and reinitializing window space
168
+ def clear!
169
+ children.each { |c|
170
+ del_child(c)
171
+ }
172
+
173
+ @children = []
174
+ erase
175
+ end
176
+
177
+ # Erase window drawing area
178
+ def erase
179
+ @win.werase
180
+ end
181
+
182
+ # Refresh / resynchronize window and all children
183
+ def refresh
184
+ @win.refresh
185
+ children.each { |c|
186
+ c.refresh
187
+ }
188
+ end
189
+
190
+ # Remove Border around window
191
+ def no_border!
192
+ @win.border(' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord)
193
+ end
194
+
195
+ # Draw Border around window
196
+ def border!
197
+ @win.box(@vborder, @hborder)
198
+ end
199
+
200
+ # Blocking call to capture next character from window
201
+ def getch
202
+ @win.getch
203
+ end
204
+
205
+ # Write string at specified loc
206
+ def mvaddstr(*a)
207
+ @win.mvaddstr(*a)
208
+ end
209
+
210
+ # Return bool indiciating if colors are set
211
+ def colored?
212
+ !!@colors
213
+ end
214
+
215
+ # Set window color
216
+ def colors=(c)
217
+ @colors = c.is_a?(ColorPair) ? c : ColorPair.for(c)
218
+ @win.bkgd(Ncurses.COLOR_PAIR(@colors.id))
219
+
220
+ component.colors = @colors if component?
221
+
222
+ children.each { |ch|
223
+ ch.colors = c
224
+ }
225
+ end
226
+
227
+ # Return window dimensions as an array containing rows & cols
228
+ def dimensions
229
+ @dimensions ||=
230
+ begin
231
+ rows = []
232
+ cols = []
233
+ @win.getmaxyx(rows, cols)
234
+ rows = rows.first
235
+ cols = cols.first
236
+ [rows, cols]
237
+ end
238
+ end
239
+
240
+ # Return window rows
241
+ def rows
242
+ dimensions[0]
243
+ end
244
+
245
+ # Return window cols
246
+ def cols
247
+ dimensions[1]
248
+ end
249
+
250
+ # Draw component in window
251
+ def draw!
252
+ component.draw! if component?
253
+ end
254
+
255
+ # Activate window component
256
+ def activate!
257
+ component.activate!
258
+ end
259
+ end
260
+ end # module RETerm
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reterm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ platform: ruby
6
+ authors:
7
+ - Mo Morsi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-terminfo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ncursesw
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ description: RETerm provides a framework and components to build full featured terminal
42
+ interfaces.
43
+ email:
44
+ - mo@morsi.org
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - designer/main.rb
52
+ - designer/src/ComponentParams.rb
53
+ - designer/src/ComponentsList.rb
54
+ - designer/src/CreatedList.rb
55
+ - designer/src/Designer.rb
56
+ - designer/src/ToggleArea.rb
57
+ - designer/src/common.rb
58
+ - designer/src/component_factory.rb
59
+ - designer/src/component_map.rb
60
+ - designer/src/glade/ComponentParams.glade
61
+ - designer/src/glade/Designer.glade
62
+ - designer/src/images/add.png
63
+ - designer/src/images/asciitext.png
64
+ - designer/src/images/blank.png
65
+ - designer/src/images/blank_sm.png
66
+ - designer/src/images/button.png
67
+ - designer/src/images/dial.png
68
+ - designer/src/images/entry.png
69
+ - designer/src/images/hslider.png
70
+ - designer/src/images/label.png
71
+ - designer/src/images/matrix.png
72
+ - designer/src/images/orig/Check.png
73
+ - designer/src/images/orig/ascii_text.png
74
+ - designer/src/images/orig/button.png
75
+ - designer/src/images/orig/dial.png
76
+ - designer/src/images/orig/entry.png
77
+ - designer/src/images/orig/hslider.png
78
+ - designer/src/images/orig/label.png
79
+ - designer/src/images/orig/matrix.png
80
+ - designer/src/images/orig/radio.png
81
+ - designer/src/images/orig/rocker.png
82
+ - designer/src/images/orig/slist.png
83
+ - designer/src/images/orig/vslider.png
84
+ - designer/src/images/radio.png
85
+ - designer/src/images/remove.png
86
+ - designer/src/images/rocker.png
87
+ - designer/src/images/slist.png
88
+ - designer/src/images/vslider.png
89
+ - lib/reterm.rb
90
+ - lib/reterm/color_pair.rb
91
+ - lib/reterm/component.rb
92
+ - lib/reterm/components.rb
93
+ - lib/reterm/components/ascii_text.rb
94
+ - lib/reterm/components/button.rb
95
+ - lib/reterm/components/dial.rb
96
+ - lib/reterm/components/dialog.rb
97
+ - lib/reterm/components/entry.rb
98
+ - lib/reterm/components/hslider.rb
99
+ - lib/reterm/components/image.rb
100
+ - lib/reterm/components/label.rb
101
+ - lib/reterm/components/matrix.rb
102
+ - lib/reterm/components/radio.rb
103
+ - lib/reterm/components/rocker.rb
104
+ - lib/reterm/components/slist.rb
105
+ - lib/reterm/components/template.rb
106
+ - lib/reterm/components/vslider.rb
107
+ - lib/reterm/init.rb
108
+ - lib/reterm/layout.rb
109
+ - lib/reterm/layouts.rb
110
+ - lib/reterm/layouts/horizontal.rb
111
+ - lib/reterm/layouts/vertical.rb
112
+ - lib/reterm/loader.rb
113
+ - lib/reterm/menu.rb
114
+ - lib/reterm/mixins/cdk_component.rb
115
+ - lib/reterm/mixins/component_input.rb
116
+ - lib/reterm/mixins/event_dispatcher.rb
117
+ - lib/reterm/mixins/nav_input.rb
118
+ - lib/reterm/panel.rb
119
+ - lib/reterm/resize.rb
120
+ - lib/reterm/terminal.rb
121
+ - lib/reterm/version.rb
122
+ - lib/reterm/window.rb
123
+ homepage: http://github.com/movitto/reterm
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message: |-
128
+ ---
129
+ To use all components, the following additional gem dependencies should be installed:
130
+ artii
131
+ drawille
132
+ chunky_png
133
+ cdkTo use the interface designer you will also need to install the \"visualruby\" gem
134
+ If optional dependencies are missing the framework will still work but dependent components will fail to load
135
+ ---
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.6.13
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Text Based UI Framework built ontop of ncurses
155
+ test_files: []