reterm 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,10 +1,11 @@
|
|
1
1
|
module RETerm
|
2
2
|
module Components
|
3
|
-
# Rocker component, allowing use to select one of several
|
3
|
+
# Rocker component, allowing use to select one of several items
|
4
4
|
class Rocker < Component
|
5
5
|
include ComponentInput
|
6
|
+
include ItemHelpers
|
6
7
|
|
7
|
-
attr_accessor :
|
8
|
+
attr_accessor :items, :index, :labels
|
8
9
|
|
9
10
|
# Initialize the Rocker component
|
10
11
|
#
|
@@ -14,16 +15,25 @@ module RETerm
|
|
14
15
|
# win = Window.new
|
15
16
|
# rocker = Rocker.new
|
16
17
|
# win.component = rocker
|
17
|
-
# rocker.
|
18
|
+
# rocker.items = ['Foo', 'Bar', 'Baz']
|
18
19
|
# val = rocker.activate!
|
19
20
|
#
|
20
21
|
def initialize(args={})
|
21
|
-
|
22
|
+
super
|
23
|
+
@items = []
|
22
24
|
@index = nil
|
23
25
|
@labels = true
|
24
26
|
@index = 0
|
25
27
|
end
|
26
28
|
|
29
|
+
def requested_rows
|
30
|
+
@items.size + 3
|
31
|
+
end
|
32
|
+
|
33
|
+
def requested_cols
|
34
|
+
max_item_size + 3
|
35
|
+
end
|
36
|
+
|
27
37
|
def draw!
|
28
38
|
refresh_win
|
29
39
|
end
|
@@ -32,17 +42,17 @@ module RETerm
|
|
32
42
|
true
|
33
43
|
end
|
34
44
|
|
35
|
-
def activate!
|
45
|
+
def activate!(*input)
|
36
46
|
refresh_win
|
37
|
-
handle_input
|
38
|
-
@
|
47
|
+
handle_input(*input)
|
48
|
+
@items[@index]
|
39
49
|
end
|
40
50
|
|
41
51
|
private
|
42
52
|
|
43
53
|
def on_inc
|
44
54
|
@index += 1
|
45
|
-
@index = @
|
55
|
+
@index = @items.size - 1 if @index == @items.size
|
46
56
|
refresh_win
|
47
57
|
end
|
48
58
|
|
@@ -58,11 +68,11 @@ module RETerm
|
|
58
68
|
post = '+' if @labels
|
59
69
|
|
60
70
|
window.mvaddstr(1, 1, " |#{pre}|")
|
61
|
-
@
|
71
|
+
@items.each_with_index { |v, i|
|
62
72
|
sel = @index == i ? "#" : " "
|
63
|
-
window.mvaddstr(i+2, 1, " |" + sel + "|" + @
|
73
|
+
window.mvaddstr(i+2, 1, " |" + sel + "|" + @items[i])
|
64
74
|
}
|
65
|
-
window.mvaddstr(@
|
75
|
+
window.mvaddstr(@items.size+2, 1, " |#{post}|")
|
66
76
|
window.refresh
|
67
77
|
update_reterm
|
68
78
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module RETerm
|
2
|
+
module Components
|
3
|
+
# Scrolling List CDK Component
|
4
|
+
class ScrollList < Component
|
5
|
+
include CDKComponent
|
6
|
+
include ItemHelpers
|
7
|
+
|
8
|
+
attr_reader :items
|
9
|
+
|
10
|
+
# Initialize the ScrollList component
|
11
|
+
#
|
12
|
+
# @param [Hash] args list params
|
13
|
+
# @option args [String] :title title of list
|
14
|
+
# @option args [Array<String>] :items items to
|
15
|
+
# populate list with
|
16
|
+
def initialize(args={})
|
17
|
+
super
|
18
|
+
@title = args[:title] || ""
|
19
|
+
@items = args[:items] || []
|
20
|
+
end
|
21
|
+
|
22
|
+
def quit_on_enter=(v)
|
23
|
+
component.quit_on_enter = v
|
24
|
+
end
|
25
|
+
|
26
|
+
def requested_rows
|
27
|
+
2 + @items.size
|
28
|
+
end
|
29
|
+
|
30
|
+
def requested_cols
|
31
|
+
[@title.size, max_item_size].max + 2
|
32
|
+
end
|
33
|
+
|
34
|
+
def <<(item)
|
35
|
+
@items << item
|
36
|
+
|
37
|
+
if window.expand? &&
|
38
|
+
(window.rows < (requested_rows + extra_padding) ||
|
39
|
+
window.cols < (requested_cols + extra_padding))
|
40
|
+
window.request_expansion requested_rows + extra_padding,
|
41
|
+
requested_cols + extra_padding
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset!
|
46
|
+
component.setCurrentItem(0)
|
47
|
+
end
|
48
|
+
|
49
|
+
def empty!
|
50
|
+
@items.clear
|
51
|
+
end
|
52
|
+
|
53
|
+
def selected
|
54
|
+
@items[component.getCurrentItem]
|
55
|
+
end
|
56
|
+
|
57
|
+
def current
|
58
|
+
selected
|
59
|
+
end
|
60
|
+
|
61
|
+
def current_index
|
62
|
+
component.getCurrentItem
|
63
|
+
end
|
64
|
+
|
65
|
+
def activate!(*input)
|
66
|
+
i = super
|
67
|
+
return nil unless normal_exit?
|
68
|
+
dispatch(:selected)
|
69
|
+
@items[i]
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def _component
|
75
|
+
c = CDK::SCROLL.new(window.cdk_scr, # cdkscreen,
|
76
|
+
CDK::CENTER, CDK::CENTER, # xplace, yplace,
|
77
|
+
CDK::RIGHT, # scroll pos
|
78
|
+
window.rows-2, # widget height
|
79
|
+
window.cols-3, # widget width
|
80
|
+
@title, @items, @items.size, # title and items
|
81
|
+
false, # prefix numbers
|
82
|
+
Ncurses::A_REVERSE, # highlight
|
83
|
+
true, false) # box, shadow
|
84
|
+
|
85
|
+
pp = lambda do |cdktype, list, scroll_list, key|
|
86
|
+
scroll_list.dispatch(:entry, key)
|
87
|
+
scroll_list.dispatch(:changed)
|
88
|
+
end
|
89
|
+
|
90
|
+
c.setPostProcess(pp, self)
|
91
|
+
|
92
|
+
c
|
93
|
+
end
|
94
|
+
end # ScrollList
|
95
|
+
end # module Components
|
96
|
+
end # module RETerm
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module RETerm
|
2
|
+
module Components
|
3
|
+
# Scrolling Area CDK Component
|
4
|
+
class ScrollingArea < Component
|
5
|
+
include CDKComponent
|
6
|
+
|
7
|
+
attr_accessor :title, :lines
|
8
|
+
|
9
|
+
# Initialize the ScrollingArea component
|
10
|
+
#
|
11
|
+
# @param [Hash] args scrolling area params
|
12
|
+
# @option args [String] :title title of area
|
13
|
+
# @option args [Integer] :lines number of lines
|
14
|
+
# in the area
|
15
|
+
def initialize(args={})
|
16
|
+
super
|
17
|
+
@title = args[:title] || ""
|
18
|
+
@lines = args[:lines] || 10
|
19
|
+
end
|
20
|
+
|
21
|
+
# XXX swindow results in weird keyboard interactions, disable for now
|
22
|
+
def activatable?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def requested_rows
|
27
|
+
10
|
28
|
+
end
|
29
|
+
|
30
|
+
def requested_cols
|
31
|
+
[@title.size, 10].min
|
32
|
+
end
|
33
|
+
|
34
|
+
def <<(item)
|
35
|
+
component.add item, CDK::BOTTOM
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def _component
|
41
|
+
CDK::SWINDOW.new(window.cdk_scr, # cdkscreen,
|
42
|
+
0, 1, # xplace, yplace, scroll pos
|
43
|
+
window.rows, # widget height
|
44
|
+
window.cols, # widget width
|
45
|
+
@title, @lines, # title, lines
|
46
|
+
true, false) # box, shadow
|
47
|
+
end
|
48
|
+
end # ScrollList
|
49
|
+
end # module Components
|
50
|
+
end # module RETerm
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module RETerm
|
2
|
+
module Components
|
3
|
+
# Select List CDK Component
|
4
|
+
class SelectList < Component
|
5
|
+
include CDKComponent
|
6
|
+
include ItemHelpers
|
7
|
+
|
8
|
+
# Initialize the SelectList component
|
9
|
+
#
|
10
|
+
# @param [Hash] args list params
|
11
|
+
# @option args [String] :title title of list
|
12
|
+
# @option args [Array<String>] :items items to
|
13
|
+
# populate list with
|
14
|
+
def initialize(args={})
|
15
|
+
super
|
16
|
+
@title = args[:title] || ""
|
17
|
+
@items = args[:items] || []
|
18
|
+
end
|
19
|
+
|
20
|
+
def requested_rows
|
21
|
+
5 + @items.size
|
22
|
+
end
|
23
|
+
|
24
|
+
def requested_cols
|
25
|
+
[@title.size, max_item_size].max + 2
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset!
|
29
|
+
component.setCurrentItem(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
def current
|
33
|
+
@items[component.getCurrentItem]
|
34
|
+
end
|
35
|
+
|
36
|
+
def selected
|
37
|
+
(0...@items.size).collect { |i|
|
38
|
+
component.selections[i] == 1 ? @items[i] : nil
|
39
|
+
}.compact
|
40
|
+
end
|
41
|
+
|
42
|
+
def activate!(*input)
|
43
|
+
super
|
44
|
+
selected
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def _component
|
50
|
+
choices = [
|
51
|
+
" ",
|
52
|
+
"-->"
|
53
|
+
]
|
54
|
+
|
55
|
+
CDK::SELECTION.new(window.cdk_scr, # cdkscreen,
|
56
|
+
2, 1, CDK::RIGHT, # xplace, yplace, select pos
|
57
|
+
window.rows - 2, # widget height
|
58
|
+
window.cols - 2, # widget width
|
59
|
+
@title, # title
|
60
|
+
@items, @items.size, # items
|
61
|
+
choices, choices.size, # space bar choices
|
62
|
+
Ncurses::A_REVERSE, # highlight
|
63
|
+
true, false) # box, shadow
|
64
|
+
end
|
65
|
+
end # ScrollList
|
66
|
+
end # module Components
|
67
|
+
end # module RETerm
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module RETerm
|
2
|
+
module Components
|
3
|
+
# Splash Screen
|
4
|
+
class Splash < Component
|
5
|
+
attr_reader :widget, :callback
|
6
|
+
|
7
|
+
# Initialize the Splash component
|
8
|
+
#
|
9
|
+
# @param [Hash] args splash params
|
10
|
+
# @option args [Component] :widget component
|
11
|
+
# to include in the slash window
|
12
|
+
def initialize(args={})
|
13
|
+
super
|
14
|
+
@widget = args[:widget]
|
15
|
+
@callback = args[:callback]
|
16
|
+
@terminate = false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Client may invoke this to
|
20
|
+
# - create dialog and window
|
21
|
+
# - activate it
|
22
|
+
# - periodically invoke callback,
|
23
|
+
# check return value
|
24
|
+
# - close / cleanup
|
25
|
+
def self.show(args={}, &bl)
|
26
|
+
splash = self.new args.merge(:callback => bl)
|
27
|
+
win = Window.new args.merge(:component => splash,
|
28
|
+
:x => :center,
|
29
|
+
:y => :center)
|
30
|
+
#win.component = splash
|
31
|
+
splash.activate!
|
32
|
+
update_reterm(true)
|
33
|
+
splash.close!
|
34
|
+
end
|
35
|
+
|
36
|
+
def requested_rows
|
37
|
+
@widget.requested_rows + 3
|
38
|
+
end
|
39
|
+
|
40
|
+
def requested_cols
|
41
|
+
@widget.requested_cols + 3
|
42
|
+
end
|
43
|
+
|
44
|
+
def close!
|
45
|
+
widget.erase
|
46
|
+
widget.finalize!
|
47
|
+
|
48
|
+
window.erase
|
49
|
+
window.finalize!
|
50
|
+
|
51
|
+
# get rid of all outstanding input
|
52
|
+
flush_input
|
53
|
+
end
|
54
|
+
|
55
|
+
def sync!
|
56
|
+
widget.sync!
|
57
|
+
end
|
58
|
+
|
59
|
+
def draw!
|
60
|
+
window.border!
|
61
|
+
widget.draw!
|
62
|
+
end
|
63
|
+
|
64
|
+
def window=(win)
|
65
|
+
super(win)
|
66
|
+
cw = win.create_child :rows => widget.requested_rows,
|
67
|
+
:cols => widget.requested_cols,
|
68
|
+
:x => 1,
|
69
|
+
:y => 1
|
70
|
+
raise ArgumentError, "could not create child" if cw.win.nil?
|
71
|
+
cw.component = widget
|
72
|
+
end
|
73
|
+
|
74
|
+
def activate!(*input)
|
75
|
+
until @terminate
|
76
|
+
window.draw!
|
77
|
+
|
78
|
+
sleep SYNC_TIMEOUT.to_f / 1000
|
79
|
+
run_sync!
|
80
|
+
@terminate = !!callback.call
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end # class Splash
|
84
|
+
end # module Components
|
85
|
+
end # module RETerm
|
@@ -4,6 +4,17 @@ module RETerm
|
|
4
4
|
class Template < Component
|
5
5
|
# All components must accept args hash (specified via loader)
|
6
6
|
def initialize(args={})
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
# Override this to request minimum rows
|
11
|
+
# for window allocation
|
12
|
+
def requested_rows
|
13
|
+
end
|
14
|
+
|
15
|
+
# Override this to request minimum cols
|
16
|
+
# for window allocation
|
17
|
+
def requested_cols
|
7
18
|
end
|
8
19
|
|
9
20
|
# Override this method to draw component on screen
|
@@ -16,7 +27,7 @@ module RETerm
|
|
16
27
|
end
|
17
28
|
|
18
29
|
# Method call when this component is activated
|
19
|
-
def activate!
|
30
|
+
def activate!(*input)
|
20
31
|
end
|
21
32
|
end # class Template
|
22
33
|
end # module Components
|
@@ -0,0 +1 @@
|
|
1
|
+
# TODO treeview component
|
@@ -10,6 +10,7 @@ module RETerm
|
|
10
10
|
#
|
11
11
|
# @param [Hash] args slider params
|
12
12
|
def initialize(args={})
|
13
|
+
super
|
13
14
|
@initial_value = 0
|
14
15
|
@increment = 0.01
|
15
16
|
@range = [0, 1]
|
@@ -17,6 +18,14 @@ module RETerm
|
|
17
18
|
@value = initial_value
|
18
19
|
end
|
19
20
|
|
21
|
+
def requested_rows
|
22
|
+
10
|
23
|
+
end
|
24
|
+
|
25
|
+
def requested_cols
|
26
|
+
3
|
27
|
+
end
|
28
|
+
|
20
29
|
def draw!
|
21
30
|
refresh_win
|
22
31
|
end
|
@@ -25,9 +34,9 @@ module RETerm
|
|
25
34
|
true
|
26
35
|
end
|
27
36
|
|
28
|
-
def activate!
|
37
|
+
def activate!(*input)
|
29
38
|
refresh_win
|
30
|
-
handle_input
|
39
|
+
handle_input(*input)
|
31
40
|
(range[1] - range[0]) * @value
|
32
41
|
end
|
33
42
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RETerm
|
2
|
+
module Components
|
3
|
+
# YouTube viewer, use cmds to render youtube to ascii:
|
4
|
+
# youtube-dl <url>
|
5
|
+
# mplayer -vo aa <file> -or-
|
6
|
+
# CACA_DRIVER=ncurses mplayer -vo caca <file>
|
7
|
+
class YouTube < CmdOutput
|
8
|
+
# Initialize the YouTube component
|
9
|
+
#
|
10
|
+
# @param [Hash] args youtube params
|
11
|
+
# @option args [String] :url url of the video
|
12
|
+
# to load
|
13
|
+
def initialize(args={})
|
14
|
+
@url = args[:url]
|
15
|
+
cmd = "..."
|
16
|
+
super(args.merge(:cmd => cmd))
|
17
|
+
end
|
18
|
+
end # YouTube
|
19
|
+
end # module Components
|
20
|
+
end # module RETerm
|