reterm 0.4.2 → 0.5.0
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.
- checksums.yaml +4 -4
- data/designer/src/ComponentParams.rb +89 -42
- data/designer/src/ComponentsList.rb +26 -25
- data/designer/src/CreatedList.rb +9 -0
- data/designer/src/Designer.rb +23 -1
- data/designer/src/ToggleArea.rb +20 -3
- data/designer/src/about.rb +35 -0
- data/designer/src/component_factory.rb +18 -0
- data/designer/src/component_map.rb +7 -0
- data/designer/src/file_chooser.rb +25 -0
- data/designer/src/glade/Designer.glade +1 -19
- data/designer/src/images/{slist.png → scroll_list.png} +0 -0
- data/lib/reterm.rb +10 -1
- data/lib/reterm/color_pair.rb +166 -10
- data/lib/reterm/component.rb +89 -2
- data/lib/reterm/components.rb +16 -1
- data/lib/reterm/components/alphalist.rb +45 -0
- data/lib/reterm/components/ascii_text.rb +14 -1
- data/lib/reterm/components/asciimator.rb +1 -0
- data/lib/reterm/components/button.rb +35 -5
- data/lib/reterm/components/button_box.rb +108 -0
- data/lib/reterm/components/close_button.rb +22 -0
- data/lib/reterm/components/cmd_output.rb +69 -0
- data/lib/reterm/components/dial.rb +11 -2
- data/lib/reterm/components/dialog.rb +41 -1
- data/lib/reterm/components/drop_down_menu.rb +140 -0
- data/lib/reterm/components/entry.rb +42 -14
- data/lib/reterm/components/histogram.rb +55 -0
- data/lib/reterm/components/hslider.rb +9 -0
- data/lib/reterm/components/image.rb +9 -0
- data/lib/reterm/components/isometric.rb +38 -0
- data/lib/reterm/components/label.rb +20 -3
- data/lib/reterm/components/matrix.rb +9 -0
- data/lib/reterm/components/multi_line_entry.rb +54 -0
- data/lib/reterm/components/password_entry.rb +15 -0
- data/lib/reterm/components/radio.rb +10 -0
- data/lib/reterm/components/revealing_label.rb +126 -0
- data/lib/reterm/components/rocker.rb +21 -11
- data/lib/reterm/components/scroll_list.rb +96 -0
- data/lib/reterm/components/scrolling_area.rb +50 -0
- data/lib/reterm/components/select_list.rb +67 -0
- data/lib/reterm/components/splash.rb +85 -0
- data/lib/reterm/components/template.rb +12 -1
- data/lib/reterm/components/treeview.rb +1 -0
- data/lib/reterm/components/vslider.rb +11 -2
- data/lib/reterm/components/youtube.rb +20 -0
- data/lib/reterm/config.rb +22 -0
- data/lib/reterm/init.rb +131 -6
- data/lib/reterm/layout.rb +147 -11
- data/lib/reterm/layouts.rb +1 -0
- data/lib/reterm/layouts/grid.rb +69 -0
- data/lib/reterm/layouts/horizontal.rb +25 -4
- data/lib/reterm/layouts/vertical.rb +26 -5
- data/lib/reterm/loader.rb +2 -2
- data/lib/reterm/mixins/button_helpers.rb +7 -0
- data/lib/reterm/mixins/cdk_component.rb +66 -2
- data/lib/reterm/mixins/common_controls.rb +15 -0
- data/lib/reterm/mixins/common_keys.rb +20 -0
- data/lib/reterm/mixins/component_input.rb +62 -14
- data/lib/reterm/mixins/event_dispatcher.rb +2 -0
- data/lib/reterm/mixins/item_helpers.rb +8 -0
- data/lib/reterm/mixins/key_bindings.rb +23 -0
- data/lib/reterm/mixins/log_helpers.rb +13 -0
- data/lib/reterm/mixins/mouse_input.rb +58 -0
- data/lib/reterm/mixins/nav_controls.rb +33 -0
- data/lib/reterm/mixins/nav_input.rb +161 -69
- data/lib/reterm/terminal.rb +6 -2
- data/lib/reterm/util.rb +121 -0
- data/lib/reterm/version.rb +1 -1
- data/lib/reterm/window.rb +295 -29
- metadata +33 -17
- data/designer/src/images/orig/Check.png +0 -0
- data/designer/src/images/orig/ascii_text.png +0 -0
- data/designer/src/images/orig/button.png +0 -0
- data/designer/src/images/orig/dial.png +0 -0
- data/designer/src/images/orig/entry.png +0 -0
- data/designer/src/images/orig/hslider.png +0 -0
- data/designer/src/images/orig/label.png +0 -0
- data/designer/src/images/orig/matrix.png +0 -0
- data/designer/src/images/orig/radio.png +0 -0
- data/designer/src/images/orig/rocker.png +0 -0
- data/designer/src/images/orig/slist.png +0 -0
- data/designer/src/images/orig/vslider.png +0 -0
- data/lib/reterm/components/slist.rb +0 -32
- data/lib/reterm/menu.rb +0 -81
@@ -0,0 +1,25 @@
|
|
1
|
+
class FileChooser
|
2
|
+
def initialize(window)
|
3
|
+
@window = window
|
4
|
+
end
|
5
|
+
|
6
|
+
def show
|
7
|
+
dialog = Gtk::FileChooserDialog.new(
|
8
|
+
:title => "Save File",
|
9
|
+
:parent => @window,
|
10
|
+
:action => Gtk::FileChooserAction::SAVE,
|
11
|
+
:back => nil,
|
12
|
+
:buttons => [
|
13
|
+
[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
|
14
|
+
[Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT]
|
15
|
+
])
|
16
|
+
|
17
|
+
|
18
|
+
file = (dialog.run == Gtk::ResponseType::ACCEPT) ?
|
19
|
+
dialog.filename : nil
|
20
|
+
|
21
|
+
dialog.destroy
|
22
|
+
|
23
|
+
file
|
24
|
+
end
|
25
|
+
end
|
@@ -33,15 +33,6 @@
|
|
33
33
|
<property name="use_stock">True</property>
|
34
34
|
</object>
|
35
35
|
</child>
|
36
|
-
<child>
|
37
|
-
<object class="GtkImageMenuItem" id="file_menu_open">
|
38
|
-
<property name="label">gtk-open</property>
|
39
|
-
<property name="visible">True</property>
|
40
|
-
<property name="can_focus">False</property>
|
41
|
-
<property name="use_underline">True</property>
|
42
|
-
<property name="use_stock">True</property>
|
43
|
-
</object>
|
44
|
-
</child>
|
45
36
|
<child>
|
46
37
|
<object class="GtkImageMenuItem" id="file_menu_save">
|
47
38
|
<property name="label">gtk-save</property>
|
@@ -51,15 +42,6 @@
|
|
51
42
|
<property name="use_stock">True</property>
|
52
43
|
</object>
|
53
44
|
</child>
|
54
|
-
<child>
|
55
|
-
<object class="GtkImageMenuItem" id="file_menu_save_as">
|
56
|
-
<property name="label">gtk-save-as</property>
|
57
|
-
<property name="visible">True</property>
|
58
|
-
<property name="can_focus">False</property>
|
59
|
-
<property name="use_underline">True</property>
|
60
|
-
<property name="use_stock">True</property>
|
61
|
-
</object>
|
62
|
-
</child>
|
63
45
|
<child>
|
64
46
|
<object class="GtkSeparatorMenuItem">
|
65
47
|
<property name="visible">True</property>
|
@@ -90,7 +72,7 @@
|
|
90
72
|
<property name="visible">True</property>
|
91
73
|
<property name="can_focus">False</property>
|
92
74
|
<child>
|
93
|
-
<object class="GtkImageMenuItem">
|
75
|
+
<object class="GtkImageMenuItem" id="help_menu_about">
|
94
76
|
<property name="label">gtk-about</property>
|
95
77
|
<property name="visible">True</property>
|
96
78
|
<property name="can_focus">False</property>
|
File without changes
|
data/lib/reterm.rb
CHANGED
@@ -7,16 +7,25 @@ require 'reterm/init'
|
|
7
7
|
require 'reterm/color_pair'
|
8
8
|
|
9
9
|
require 'reterm/mixins/event_dispatcher'
|
10
|
+
require 'reterm/mixins/mouse_input'
|
11
|
+
require 'reterm/mixins/common_controls'
|
12
|
+
require 'reterm/mixins/common_keys'
|
10
13
|
require 'reterm/mixins/component_input'
|
14
|
+
require 'reterm/mixins/nav_controls'
|
11
15
|
require 'reterm/mixins/nav_input'
|
12
16
|
require 'reterm/mixins/cdk_component'
|
17
|
+
require 'reterm/mixins/item_helpers'
|
18
|
+
require 'reterm/mixins/key_bindings'
|
19
|
+
require 'reterm/mixins/button_helpers'
|
20
|
+
require 'reterm/mixins/log_helpers'
|
13
21
|
|
14
22
|
require 'reterm/terminal'
|
15
23
|
require 'reterm/window'
|
16
24
|
require 'reterm/panel'
|
17
|
-
require 'reterm/menu'
|
18
25
|
|
19
26
|
require 'reterm/components'
|
20
27
|
require 'reterm/layouts'
|
21
28
|
|
22
29
|
require 'reterm/loader'
|
30
|
+
require 'reterm/util'
|
31
|
+
require 'reterm/config'
|
data/lib/reterm/color_pair.rb
CHANGED
@@ -7,8 +7,74 @@ module RETerm
|
|
7
7
|
attr_accessor :id
|
8
8
|
attr_accessor :tags
|
9
9
|
|
10
|
-
|
11
|
-
attr_accessor :bg
|
10
|
+
# Color Identifiers
|
11
|
+
attr_accessor :fg, :bg
|
12
|
+
|
13
|
+
# Actual NCurses colors
|
14
|
+
attr_accessor :fgc, :bgc
|
15
|
+
|
16
|
+
# Return color in CDK format
|
17
|
+
def cdk_fmt
|
18
|
+
"</#{@id}>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.builtin
|
22
|
+
@builtin ||= Ncurses.constants.select { |c|
|
23
|
+
c =~ /^COLOR.*/
|
24
|
+
}.collect { |c|
|
25
|
+
c.to_s.gsub("COLOR_", "").downcase.intern
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.default_bkgd
|
30
|
+
@dbkgd ||= Ncurses::WINDOW.new(1, 1, 1, 1).getbkgd
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.default_bkgd_char
|
34
|
+
@dbkgdch ||= default_bkgg & Ncurses::A_CHARTEXT
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.default_bkgd_color
|
38
|
+
@dbkgdco ||= ((default_bkgd & Ncurses::A_COLOR) >> 8)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.default_fg
|
42
|
+
@dfg ||= begin
|
43
|
+
f, b = [], []
|
44
|
+
Ncurses::pair_content(default_bkgd_color, f, b)
|
45
|
+
f.first
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.default_bg
|
50
|
+
@dbg ||= begin
|
51
|
+
f, b = [], []
|
52
|
+
Ncurses::pair_content(default_bkgd_color, f, b)
|
53
|
+
b.first
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.default_color
|
58
|
+
@dcp ||= register default_fg, default_bg
|
59
|
+
end
|
60
|
+
|
61
|
+
# Reserves and returns block of N colors
|
62
|
+
def self.reserve(n=1)
|
63
|
+
@reserved ||= []
|
64
|
+
@next_color ||= 50
|
65
|
+
|
66
|
+
0.upto(n) {
|
67
|
+
@reserved << @next_color
|
68
|
+
@next_color += 1
|
69
|
+
}
|
70
|
+
|
71
|
+
@reserved[-n..-1]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Alias for reserve
|
75
|
+
def self.next_color
|
76
|
+
reserve
|
77
|
+
end
|
12
78
|
|
13
79
|
# Redefined system RGB color. Color name should be specified
|
14
80
|
# as well as new RGB components
|
@@ -19,7 +85,57 @@ module RETerm
|
|
19
85
|
# @param [Integer] g value to assign to green component
|
20
86
|
# @param [Integer] b value to assign to blue component
|
21
87
|
def self.change(color, r, g, b)
|
22
|
-
|
88
|
+
# XXX shoehorning 256 colors into ncurses 0-1000 scale here,
|
89
|
+
# possible explore if alternative solutions are better
|
90
|
+
r = r.to_f / 255 * 1000
|
91
|
+
g = g.to_f / 255 * 1000
|
92
|
+
b = b.to_f / 255 * 1000
|
93
|
+
|
94
|
+
c = builtin.include?(color.to_s.downcase.intern) ?
|
95
|
+
Ncurses.const_get("COLOR_#{color.to_s.upcase}") : color
|
96
|
+
|
97
|
+
Ncurses::init_color c, r, g, b
|
98
|
+
end
|
99
|
+
|
100
|
+
# An alias for #change
|
101
|
+
def self.define(color, r, g, b)
|
102
|
+
change(color, r, g, b)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return RGB components corresponding to system color
|
106
|
+
#
|
107
|
+
# @param [String, Symbol] color name of color to return
|
108
|
+
def self.get(color)
|
109
|
+
c = builtin.include?(color.to_s.downcase.intern) ?
|
110
|
+
Ncurses.const_get("COLOR_#{color.to_s.upcase}") : color
|
111
|
+
|
112
|
+
r, g, b = [[],[],[]]
|
113
|
+
Ncurses::color_content c, r, g, b
|
114
|
+
|
115
|
+
[r.first, g.first, b.first]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Temporarily resassign RGB to named color, invoke callback
|
119
|
+
# block, and restore to original
|
120
|
+
# @param [Hash<String,Symbol,Array<Integer>>] colors color assignments
|
121
|
+
# to use, mapping of color names to RBG pairs
|
122
|
+
# @param [Integer] r value to assign to red component
|
123
|
+
# @param [Integer] g value to assign to green component
|
124
|
+
# @param [Integer] b value to assign to blue component
|
125
|
+
def self.use(colors={})
|
126
|
+
orig = {}
|
127
|
+
colors.each { |n, rgb|
|
128
|
+
orig[n] = get(n)
|
129
|
+
change(n, *rgb)
|
130
|
+
}
|
131
|
+
|
132
|
+
yield
|
133
|
+
|
134
|
+
colors.each { |n, rgb|
|
135
|
+
change(n, *orig[n])
|
136
|
+
}
|
137
|
+
|
138
|
+
nil
|
23
139
|
end
|
24
140
|
|
25
141
|
# Instantiate a new ColorPair, specifying foreground and background
|
@@ -40,12 +156,28 @@ module RETerm
|
|
40
156
|
|
41
157
|
# FIXME need to verify input is in valid domain
|
42
158
|
# before conveRETermng it to symbol w/ "intern"
|
43
|
-
fg = fg.to_s.downcase.intern
|
44
|
-
bg = bg.to_s.downcase.intern
|
159
|
+
fg = fg.to_s.downcase.intern if fg.is_a?(String) || fg.is_a?(Symbol)
|
160
|
+
bg = bg.to_s.downcase.intern if bg.is_a?(String) || bg.is_a?(Symbol)
|
161
|
+
@fg, @bg = fg, bg
|
162
|
+
|
163
|
+
fgc = fg.is_a?(Symbol) ? Ncurses.const_get("COLOR_#{fg.to_s.upcase}") : fg
|
164
|
+
bgc = bg.is_a?(Symbol) ? Ncurses.const_get("COLOR_#{bg.to_s.upcase}") : bg
|
165
|
+
|
166
|
+
@fgc, @bgc = fgc, bgc
|
45
167
|
|
46
|
-
Ncurses.init_pair(@id,
|
47
|
-
|
48
|
-
|
168
|
+
Ncurses.init_pair(@id, fgc, bgc)
|
169
|
+
end
|
170
|
+
|
171
|
+
# Returns ncurses color pair corresponding to this instance
|
172
|
+
def nc
|
173
|
+
Ncurses::COLOR_PAIR(@id)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Encapsulates window operation in color pair attribute
|
177
|
+
def format(win)
|
178
|
+
win.win.attron(nc)
|
179
|
+
yield
|
180
|
+
win.win.attroff(nc)
|
49
181
|
end
|
50
182
|
|
51
183
|
# Create and store a new Color Pair in a static
|
@@ -56,11 +188,35 @@ module RETerm
|
|
56
188
|
@@registry.last
|
57
189
|
end
|
58
190
|
|
59
|
-
# Return
|
191
|
+
# Return all colors pairs
|
192
|
+
def self.all
|
193
|
+
@@registry ||= []
|
194
|
+
@@registry
|
195
|
+
end
|
196
|
+
|
197
|
+
# Return Color Pairs found with the given tag
|
60
198
|
# or nil for no matches
|
61
199
|
def self.for(tag)
|
62
200
|
@@registry ||= []
|
63
|
-
@@registry.
|
201
|
+
@@registry.select { |cp| cp.tags.include?(tag) }
|
202
|
+
end
|
203
|
+
|
204
|
+
# Return Color Pairs found with the given
|
205
|
+
# fg color
|
206
|
+
def self.with_fg(color)
|
207
|
+
@@registry ||= []
|
208
|
+
@@registry.select { |cp|
|
209
|
+
color == (color.is_a?(Symbol) ? cp.fg : cp.fgc)
|
210
|
+
}
|
211
|
+
end
|
212
|
+
|
213
|
+
# Return Color Pairs found with the given
|
214
|
+
# bg color
|
215
|
+
def self.with_bg(color)
|
216
|
+
@@registry ||= []
|
217
|
+
@@registry.select { |cp|
|
218
|
+
color == (color.is_a?(Symbol) ? cp.bg : cp.bgc)
|
219
|
+
}
|
64
220
|
end
|
65
221
|
end # class ColorPair
|
66
222
|
end # module RETerm
|
data/lib/reterm/component.rb
CHANGED
@@ -2,7 +2,35 @@ module RETerm
|
|
2
2
|
# A Component is a generic widget container associated with a window.
|
3
3
|
# Subclasses each implement a specific UI artifact.
|
4
4
|
class Component
|
5
|
-
|
5
|
+
include EventDispatcher
|
6
|
+
include LogHelpers
|
7
|
+
include KeyBindings
|
8
|
+
|
9
|
+
attr_reader :window
|
10
|
+
|
11
|
+
def window=(w)
|
12
|
+
@window = w
|
13
|
+
dispatch(:window_assigned)
|
14
|
+
w
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(args={})
|
18
|
+
self.highlight_focus = args[:highlight_focus] if args.key?(:highlight_focus)
|
19
|
+
self.activate_focus = args[:activate_focus] if args.key?(:activate_focus)
|
20
|
+
init_cdk(args) if cdk?
|
21
|
+
end
|
22
|
+
|
23
|
+
# This method is invoked when adding component to layout
|
24
|
+
# to determine rows needed
|
25
|
+
def requested_rows
|
26
|
+
1
|
27
|
+
end
|
28
|
+
|
29
|
+
# This method is invoked when adding component to layout
|
30
|
+
# to determine cols needed
|
31
|
+
def requested_cols
|
32
|
+
1
|
33
|
+
end
|
6
34
|
|
7
35
|
# This method is invoked to cleanup the component on shutdown.
|
8
36
|
# It should be be overriden by subclasses that needs to clean
|
@@ -33,8 +61,67 @@ module RETerm
|
|
33
61
|
# logic when the user has selected an activatable? component.
|
34
62
|
# Should be overriden by interactive subcomponents to
|
35
63
|
# process user inpute specific to that component
|
36
|
-
def activate!
|
64
|
+
def activate!(*input)
|
37
65
|
raise RuntimeError, "should not be activated"
|
38
66
|
end
|
67
|
+
|
68
|
+
# This method is invoked when component loses focus
|
69
|
+
# (when navigating to another component, window closed, etc).
|
70
|
+
# Subclasses may override to hide / cleanup resources
|
71
|
+
def deactivate!
|
72
|
+
@deactivate = true
|
73
|
+
end
|
74
|
+
|
75
|
+
# Flag indicating that this component should
|
76
|
+
# be deactivated
|
77
|
+
def deactivate?
|
78
|
+
!!(@deactivate ||= false)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Reset deactivation
|
82
|
+
def reactivate!
|
83
|
+
@deactivate = false
|
84
|
+
end
|
85
|
+
|
86
|
+
attr_writer :highlight_focus
|
87
|
+
|
88
|
+
# Return boolean indicating if this component should
|
89
|
+
# be highlighted on focus (default true)
|
90
|
+
def highlight_focus?
|
91
|
+
!defined?(@highlight_focus) || @highlight_focus
|
92
|
+
end
|
93
|
+
|
94
|
+
attr_writer :activate_focus
|
95
|
+
|
96
|
+
def activate_focus?
|
97
|
+
defined?(@activate_focus) && @activate_focus
|
98
|
+
end
|
99
|
+
|
100
|
+
# Return extra padding to be given to component
|
101
|
+
def extra_padding
|
102
|
+
(activatable? && highlight_focus?) ? 3 : 0
|
103
|
+
end
|
104
|
+
|
105
|
+
# Method to periodically synchronize component if needed
|
106
|
+
def sync!
|
107
|
+
end
|
108
|
+
|
109
|
+
# Dispatch to window.resize
|
110
|
+
def resize(rows, cols)
|
111
|
+
window.resize(rows, cols)
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
# Overridden by CDK components
|
116
|
+
def cdk?
|
117
|
+
false
|
118
|
+
end
|
119
|
+
|
120
|
+
def sync_getch
|
121
|
+
c = window.sync_getch
|
122
|
+
c = nil if key_bound?(c) &&
|
123
|
+
invoke_key_bindings(c)
|
124
|
+
c
|
125
|
+
end
|
39
126
|
end # class Component
|
40
127
|
end # module RETerm
|
data/lib/reterm/components.rb
CHANGED
@@ -19,14 +19,29 @@ require 'reterm/components/dial'
|
|
19
19
|
require 'reterm/components/rocker'
|
20
20
|
require 'reterm/components/vslider'
|
21
21
|
require 'reterm/components/label'
|
22
|
+
require 'reterm/components/revealing_label'
|
22
23
|
require 'reterm/components/ascii_text'
|
23
24
|
require 'reterm/components/image'
|
25
|
+
require 'reterm/components/splash'
|
24
26
|
|
25
27
|
# cdk
|
26
28
|
require 'reterm/components/hslider'
|
27
29
|
require 'reterm/components/button'
|
28
30
|
require 'reterm/components/dialog'
|
29
31
|
require 'reterm/components/radio'
|
30
|
-
require 'reterm/components/
|
32
|
+
require 'reterm/components/scroll_list'
|
33
|
+
require 'reterm/components/select_list'
|
31
34
|
require 'reterm/components/entry'
|
35
|
+
require 'reterm/components/password_entry'
|
32
36
|
require 'reterm/components/matrix'
|
37
|
+
require 'reterm/components/drop_down_menu'
|
38
|
+
require 'reterm/components/button_box'
|
39
|
+
require 'reterm/components/alphalist'
|
40
|
+
require 'reterm/components/multi_line_entry'
|
41
|
+
require 'reterm/components/histogram'
|
42
|
+
require 'reterm/components/scrolling_area'
|
43
|
+
|
44
|
+
# additional
|
45
|
+
require 'reterm/components/close_button'
|
46
|
+
require 'reterm/components/cmd_output'
|
47
|
+
require 'reterm/components/youtube'
|