rndk 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/TODO +21 -1
- data/demos/appointment.rb +279 -299
- data/demos/clock.rb +13 -8
- data/demos/rss-reader.rb +84 -0
- data/examples/01-hello-world.rb +13 -11
- data/examples/02-colors.rb +14 -21
- data/examples/03-markup.rb +7 -7
- data/examples/04-quick-widgets.rb +2 -2
- data/examples/05-position-widget.rb +50 -31
- data/examples/06-callbacks.rb +77 -0
- data/examples/07-traverse.rb +90 -0
- data/examples/10-all-widgets.rb +165 -0
- data/examples/calendar.rb +20 -32
- data/examples/entry.rb +15 -20
- data/examples/label.rb +11 -11
- data/examples/scroll.rb +16 -60
- data/examples/slider.rb +18 -19
- data/examples/viewer.rb +65 -0
- data/lib/rndk.rb +28 -7
- data/lib/rndk/alphalist.rb +309 -313
- data/lib/rndk/button.rb +239 -157
- data/lib/rndk/buttonbox.rb +136 -103
- data/lib/rndk/calendar.rb +246 -203
- data/lib/rndk/core/color.rb +63 -13
- data/lib/rndk/core/display.rb +1 -1
- data/lib/rndk/core/draw.rb +11 -11
- data/lib/rndk/core/markup.rb +21 -21
- data/lib/rndk/core/quick_widgets.rb +75 -96
- data/lib/rndk/core/screen.rb +145 -102
- data/lib/rndk/core/traverse.rb +150 -136
- data/lib/rndk/core/utils.rb +5 -6
- data/lib/rndk/core/widget.rb +207 -191
- data/lib/rndk/core/widget_bind.rb +108 -0
- data/lib/rndk/dialog.rb +88 -56
- data/lib/rndk/entry.rb +79 -64
- data/lib/rndk/fscale.rb +38 -20
- data/lib/rndk/fslider.rb +38 -23
- data/lib/rndk/graph.rb +92 -53
- data/lib/rndk/itemlist.rb +80 -62
- data/lib/rndk/label.rb +111 -77
- data/lib/rndk/radio.rb +138 -128
- data/lib/rndk/scale.rb +123 -122
- data/lib/rndk/scroll.rb +444 -391
- data/lib/rndk/scroller.rb +21 -21
- data/lib/rndk/slider.rb +149 -140
- data/lib/rndk/template.rb +74 -61
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +499 -298
- metadata +8 -14
- data/demos/fileview.rb +0 -141
- data/lib/rndk/dscale.rb +0 -13
- data/lib/rndk/fselect.rb +0 -938
- data/lib/rndk/histogram.rb +0 -412
- data/lib/rndk/marquee.rb +0 -244
- data/lib/rndk/matrix.rb +0 -1189
- data/lib/rndk/mentry.rb +0 -619
- data/lib/rndk/menu.rb +0 -478
- data/lib/rndk/selection.rb +0 -630
- data/lib/rndk/swindow.rb +0 -766
- data/lib/rndk/uscale.rb +0 -14
- data/lib/rndk/uslider.rb +0 -14
data/lib/rndk/label.rb
CHANGED
@@ -11,56 +11,77 @@ module RNDK
|
|
11
11
|
|
12
12
|
# Creates a Label Widget.
|
13
13
|
#
|
14
|
-
# * `
|
14
|
+
# * `x` is the x position - can be an integer or `RNDK::LEFT`,
|
15
15
|
# `RNDK::RIGHT`, `RNDK::CENTER`.
|
16
|
-
# * `
|
16
|
+
# * `y` is the y position - can be an integer or `RNDK::TOP`,
|
17
17
|
# `RNDK::BOTTOM`, `RNDK::CENTER`.
|
18
|
-
# * `message` is an Array of Strings with all the lines you'd
|
19
|
-
# to show. RNDK markup applies (see RNDK#Markup).
|
18
|
+
# * `message` is an Array of Strings with all the lines you'd
|
19
|
+
# want to show. RNDK markup applies (see RNDK#Markup).
|
20
20
|
# * `box` if the Widget is drawn with a box outside it.
|
21
21
|
# * `shadow` turns on/off the shadow around the Widget.
|
22
22
|
#
|
23
23
|
# If the Widget cannot be created, returns `nil`.
|
24
|
-
def initialize(
|
25
|
-
return nil if mesg.class != Array or mesg.empty?
|
26
|
-
|
24
|
+
def initialize(screen, config={})
|
27
25
|
super()
|
28
|
-
|
26
|
+
@widget_type = :label
|
27
|
+
@supported_signals += [:before_message_change]
|
28
|
+
|
29
|
+
# This is UGLY AS HELL
|
30
|
+
# But I don't have time to clean this up right now
|
31
|
+
# (lots of widgets, you know) :(
|
32
|
+
x = 0
|
33
|
+
y = 0
|
34
|
+
text = "label"
|
35
|
+
box = true
|
36
|
+
shadow = false
|
37
|
+
|
38
|
+
config.each do |key, val|
|
39
|
+
x = val if key == :x
|
40
|
+
y = val if key == :y
|
41
|
+
text = val if key == :text
|
42
|
+
box = val if key == :box
|
43
|
+
shadow = val if key == :shadow
|
44
|
+
end
|
45
|
+
# End of darkness
|
46
|
+
|
47
|
+
# Adjusting if the user sent us a String
|
48
|
+
text = [text] if text.class == String
|
49
|
+
return nil if text.class != Array or text.empty?
|
50
|
+
rows = text.size
|
29
51
|
|
30
|
-
parent_width = Ncurses.getmaxx
|
31
|
-
parent_height = Ncurses.getmaxy
|
52
|
+
parent_width = Ncurses.getmaxx screen.window
|
53
|
+
parent_height = Ncurses.getmaxy screen.window
|
32
54
|
box_width = -2**30 # -INFINITY
|
33
55
|
box_height = 0
|
34
|
-
|
35
|
-
|
36
|
-
x = 0
|
56
|
+
x = [x]
|
57
|
+
y = [y]
|
37
58
|
|
38
59
|
self.set_box box
|
39
60
|
box_height = rows + 2*@border_size
|
40
61
|
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
62
|
+
@text = []
|
63
|
+
@text_len = []
|
64
|
+
@text_pos = []
|
44
65
|
|
45
66
|
# Determine the box width.
|
46
67
|
(0...rows).each do |x|
|
47
68
|
|
48
69
|
# Translate the string to a chtype array
|
49
|
-
|
50
|
-
|
51
|
-
@
|
52
|
-
@
|
53
|
-
@
|
70
|
+
text_len = []
|
71
|
+
text_pos = []
|
72
|
+
@text << RNDK.char2Chtype(text[x], text_len, text_pos)
|
73
|
+
@text_len << text_len[0]
|
74
|
+
@text_pos << text_pos[0]
|
54
75
|
|
55
|
-
box_width = [box_width, @
|
76
|
+
box_width = [box_width, @text_len[x]].max
|
56
77
|
end
|
57
78
|
box_width += 2 * @border_size
|
58
79
|
|
59
80
|
# Create the string alignments.
|
60
81
|
(0...rows).each do |x|
|
61
|
-
@
|
62
|
-
@
|
63
|
-
@
|
82
|
+
@text_pos[x] = RNDK.justifyString(box_width - 2*@border_size,
|
83
|
+
@text_len[x],
|
84
|
+
@text_pos[x])
|
64
85
|
end
|
65
86
|
|
66
87
|
# Make sure we didn't extend beyond the dimensions of the window.
|
@@ -74,20 +95,23 @@ module RNDK
|
|
74
95
|
end
|
75
96
|
|
76
97
|
# Rejustify the x and y positions if we need to
|
77
|
-
RNDK.alignxy(
|
78
|
-
|
79
|
-
@screen =
|
80
|
-
@parent =
|
81
|
-
@win = Ncurses.newwin(box_height,
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@
|
98
|
+
RNDK.alignxy(screen.window, x, y, box_width, box_height)
|
99
|
+
|
100
|
+
@screen = screen
|
101
|
+
@parent = screen.window
|
102
|
+
@win = Ncurses.newwin(box_height,
|
103
|
+
box_width,
|
104
|
+
y[0],
|
105
|
+
x[0])
|
106
|
+
@shadow_win = nil
|
107
|
+
@x = x[0]
|
108
|
+
@y = y[0]
|
109
|
+
@rows = rows
|
86
110
|
@box_width = box_width
|
87
111
|
@box_height = box_height
|
88
112
|
@input_window = @win
|
89
|
-
@has_focus
|
90
|
-
@shadow
|
113
|
+
@has_focus = false
|
114
|
+
@shadow = shadow
|
91
115
|
|
92
116
|
if @win.nil?
|
93
117
|
self.destroy
|
@@ -100,77 +124,83 @@ module RNDK
|
|
100
124
|
if shadow
|
101
125
|
@shadow_win = Ncurses.newwin(box_height,
|
102
126
|
box_width,
|
103
|
-
|
104
|
-
|
127
|
+
y[0] + 1,
|
128
|
+
x[0] + 1)
|
105
129
|
end
|
106
130
|
|
107
131
|
# Register this
|
108
|
-
|
132
|
+
screen.register(@widget_type, self)
|
109
133
|
end
|
110
134
|
|
111
135
|
# Obsolete entrypoint which calls Label#draw.
|
112
136
|
def activate(actions=[])
|
113
|
-
self.draw
|
137
|
+
self.draw
|
114
138
|
end
|
115
139
|
|
116
140
|
# Sets multiple attributes of the Widget.
|
117
141
|
#
|
118
142
|
# See Label#initialize.
|
119
|
-
def set(
|
120
|
-
|
121
|
-
|
143
|
+
def set(config)
|
144
|
+
# This is UGLY ATTRIBUTESS HELL
|
145
|
+
# But I don't have time to clean this up right now
|
146
|
+
# (lots of widgets, you know) :(
|
147
|
+
text = @text
|
148
|
+
box = @box
|
149
|
+
shadow = @shadow
|
150
|
+
|
151
|
+
config.each do |key, val|
|
152
|
+
text = val if key == :text
|
153
|
+
box = val if key == :box
|
154
|
+
shadow = val if key == :shadow
|
155
|
+
end
|
156
|
+
|
157
|
+
self.set_message text if text != @text
|
158
|
+
self.set_box box if box != @box
|
122
159
|
end
|
123
160
|
|
124
161
|
# Sets the contents of the Label Widget.
|
125
|
-
# @note `
|
126
|
-
def set_message
|
127
|
-
return if
|
162
|
+
# @note `text` is an Array of Strings.
|
163
|
+
def set_message text
|
164
|
+
return if text.class != Array or text.empty?
|
165
|
+
|
166
|
+
keep_going = self.run_signal_binding(:before_message_change)
|
167
|
+
return if not keep_going
|
128
168
|
|
129
|
-
info_size = info.size
|
130
169
|
# Clean out the old message.
|
131
170
|
(0...@rows).each do |x|
|
132
|
-
@
|
133
|
-
@
|
134
|
-
@
|
171
|
+
@text[x] = ''
|
172
|
+
@text_pos[x] = 0
|
173
|
+
@text_len[x] = 0
|
135
174
|
end
|
136
175
|
|
137
|
-
@rows = if
|
138
|
-
then
|
176
|
+
@rows = if text.size < @rows
|
177
|
+
then text.size
|
139
178
|
else @rows
|
140
179
|
end
|
141
180
|
|
142
181
|
# Copy in the new message.
|
143
182
|
(0...@rows).each do |x|
|
144
|
-
|
145
|
-
|
146
|
-
@
|
147
|
-
@
|
148
|
-
@
|
149
|
-
@
|
150
|
-
|
183
|
+
text_len = []
|
184
|
+
text_pos = []
|
185
|
+
@text[x] = RNDK.char2Chtype(text[x], text_len, text_pos)
|
186
|
+
@text_len[x] = text_len[0]
|
187
|
+
@text_pos[x] = RNDK.justifyString(@box_width - 2 * @border_size,
|
188
|
+
@text_len[x],
|
189
|
+
text_pos[0])
|
151
190
|
end
|
152
191
|
|
153
192
|
# Redraw the label widget.
|
154
193
|
self.erase
|
155
|
-
self.draw
|
194
|
+
self.draw
|
156
195
|
end
|
157
196
|
|
158
197
|
# Returns current contents of the Widget.
|
159
|
-
def get_message
|
160
|
-
|
161
|
-
return @info
|
162
|
-
end
|
163
|
-
|
164
|
-
def object_type
|
165
|
-
:label
|
166
|
-
end
|
167
|
-
|
168
|
-
def position
|
169
|
-
super(@win)
|
198
|
+
def get_message
|
199
|
+
@text
|
170
200
|
end
|
171
201
|
|
172
202
|
# Sets the background attribute/color of the widget.
|
173
|
-
def
|
203
|
+
def set_bg_color attrib
|
174
204
|
Ncurses.wbkgd(@win, attrib)
|
175
205
|
end
|
176
206
|
|
@@ -188,12 +218,12 @@ module RNDK
|
|
188
218
|
# Draw in the message.
|
189
219
|
(0...@rows).each do |x|
|
190
220
|
Draw.writeChtype(@win,
|
191
|
-
@
|
221
|
+
@text_pos[x] + @border_size,
|
192
222
|
x + @border_size,
|
193
|
-
@
|
223
|
+
@text[x],
|
194
224
|
RNDK::HORIZONTAL,
|
195
225
|
0,
|
196
|
-
@
|
226
|
+
@text_len[x])
|
197
227
|
end
|
198
228
|
|
199
229
|
Ncurses.wrefresh @win
|
@@ -211,9 +241,9 @@ module RNDK
|
|
211
241
|
RNDK.window_delete @shadow_win
|
212
242
|
RNDK.window_delete @win
|
213
243
|
|
214
|
-
self.clean_bindings
|
244
|
+
self.clean_bindings
|
215
245
|
|
216
|
-
|
246
|
+
@screen.unregister self
|
217
247
|
end
|
218
248
|
|
219
249
|
# Waits for the user to press a key.
|
@@ -235,6 +265,10 @@ module RNDK
|
|
235
265
|
code
|
236
266
|
end
|
237
267
|
|
268
|
+
def position
|
269
|
+
super(@win)
|
270
|
+
end
|
271
|
+
|
238
272
|
end
|
239
273
|
end
|
240
274
|
|
data/lib/rndk/radio.rb
CHANGED
@@ -1,41 +1,64 @@
|
|
1
1
|
require 'rndk/scroller'
|
2
2
|
|
3
3
|
module RNDK
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
class Radio < Scroller
|
6
|
+
|
7
|
+
def initialize(screen, config={})
|
7
8
|
super()
|
8
|
-
|
9
|
-
|
9
|
+
@widget_type = :radio
|
10
|
+
@supported_signals += [:before_input, :after_input]
|
11
|
+
|
12
|
+
x = 0
|
13
|
+
y = 0
|
14
|
+
splace = RNDK::RIGHT
|
15
|
+
width = 0
|
16
|
+
height = 0
|
17
|
+
title = "radio"
|
18
|
+
items = []
|
19
|
+
choice_char = '#'.ord | RNDK::Color[:reverse]
|
20
|
+
default = 0
|
21
|
+
highlight = RNDK::Color[:reverse]
|
22
|
+
box = true
|
23
|
+
shadow = false
|
24
|
+
|
25
|
+
config.each do |key, val|
|
26
|
+
x = val if key == :x
|
27
|
+
y = val if key == :y
|
28
|
+
splace = val if key == :splace
|
29
|
+
width = val if key == :width
|
30
|
+
height = val if key == :height
|
31
|
+
title = val if key == :title
|
32
|
+
items = val if key == :items
|
33
|
+
choice_char = val if key == :choice_char
|
34
|
+
default = val if key == :default
|
35
|
+
highlight = val if key == :highlight
|
36
|
+
box = val if key == :box
|
37
|
+
shadow = val if key == :shadow
|
38
|
+
end
|
39
|
+
|
40
|
+
items_size = items.size
|
41
|
+
parent_width = Ncurses.getmaxx(screen.window)
|
42
|
+
parent_height = Ncurses.getmaxy(screen.window)
|
10
43
|
box_width = width
|
11
44
|
box_height = height
|
12
45
|
widest_item = 0
|
13
46
|
|
14
|
-
|
15
|
-
RNDK::BACKCHAR => Ncurses::KEY_PPAGE,
|
16
|
-
RNDK::FORCHAR => Ncurses::KEY_NPAGE,
|
17
|
-
'g' => Ncurses::KEY_HOME,
|
18
|
-
'1' => Ncurses::KEY_HOME,
|
19
|
-
'G' => Ncurses::KEY_END,
|
20
|
-
'<' => Ncurses::KEY_HOME,
|
21
|
-
'>' => Ncurses::KEY_END,
|
22
|
-
}
|
23
|
-
|
24
|
-
self.set_box(box)
|
47
|
+
self.set_box box
|
25
48
|
|
26
49
|
# If the height is a negative value, height will be ROWS-height,
|
27
50
|
# otherwise the height will be the given height.
|
28
|
-
box_height = RNDK.
|
51
|
+
box_height = RNDK.set_widget_dimension(parent_height, height, 0)
|
29
52
|
|
30
53
|
# If the width is a negative value, the width will be COLS-width,
|
31
54
|
# otherwise the width will be the given width.
|
32
|
-
box_width = RNDK.
|
55
|
+
box_width = RNDK.set_widget_dimension(parent_width, width, 5)
|
33
56
|
|
34
57
|
box_width = self.set_title(title, box_width)
|
35
58
|
|
36
59
|
# Set the box height.
|
37
60
|
if @title_lines > box_height
|
38
|
-
box_height = @title_lines + [
|
61
|
+
box_height = @title_lines + [items_size, 8].min + 2 * @border_size
|
39
62
|
end
|
40
63
|
|
41
64
|
# Adjust the box width if there is a scroll bar.
|
@@ -50,21 +73,21 @@ module RNDK
|
|
50
73
|
@box_width = [box_width, parent_width].min
|
51
74
|
@box_height = [box_height, parent_height].min
|
52
75
|
|
53
|
-
self.
|
76
|
+
self.set_view_size(items_size)
|
54
77
|
|
55
78
|
# Each item in the needs to be converted to chtype array
|
56
|
-
widest_item = self.
|
79
|
+
widest_item = self.create_items(items, @box_width)
|
57
80
|
if widest_item > 0
|
58
81
|
self.updateViewWidth(widest_item)
|
59
|
-
elsif
|
82
|
+
elsif items_size > 0
|
60
83
|
self.destroy
|
61
84
|
return nil
|
62
85
|
end
|
63
86
|
|
64
87
|
# Rejustify the x and y positions if we need to.
|
65
|
-
xtmp = [
|
66
|
-
ytmp = [
|
67
|
-
RNDK.alignxy(
|
88
|
+
xtmp = [x]
|
89
|
+
ytmp = [y]
|
90
|
+
RNDK.alignxy(screen.window, xtmp, ytmp, @box_width, @box_height)
|
68
91
|
xpos = xtmp[0]
|
69
92
|
ypos = ytmp[0]
|
70
93
|
|
@@ -82,18 +105,18 @@ module RNDK
|
|
82
105
|
|
83
106
|
# Create the scrollbar window.
|
84
107
|
if splace == RNDK::RIGHT
|
85
|
-
@scrollbar_win = Ncurses.subwin(@win, self.
|
108
|
+
@scrollbar_win = Ncurses.subwin(@win, self.max_view_size, 1,
|
86
109
|
self.Screen_YPOS(ypos), xpos + @box_width - @border_size - 1)
|
87
110
|
elsif splace == RNDK::LEFT
|
88
|
-
@scrollbar_win = Ncurses.subwin(@win, self.
|
111
|
+
@scrollbar_win = Ncurses.subwin(@win, self.max_view_size, 1,
|
89
112
|
self.Screen_YPOS(ypos), self.Screen_XPOS(xpos))
|
90
113
|
else
|
91
114
|
@scrollbar_win = nil
|
92
115
|
end
|
93
116
|
|
94
117
|
# Set the rest of the variables
|
95
|
-
@screen =
|
96
|
-
@parent =
|
118
|
+
@screen = screen
|
119
|
+
@parent = screen.window
|
97
120
|
@scrollbar_placement = splace
|
98
121
|
@widest_item = widest_item
|
99
122
|
@left_char = 0
|
@@ -102,12 +125,12 @@ module RNDK
|
|
102
125
|
@choice_char = choice_char.ord
|
103
126
|
@left_box_char = '['.ord
|
104
127
|
@right_box_char = ']'.ord
|
105
|
-
@
|
128
|
+
@default = default
|
106
129
|
@input_window = @win
|
107
130
|
@accepts_focus = true
|
108
131
|
@shadow = shadow
|
109
132
|
|
110
|
-
self.
|
133
|
+
self.set_current_item(0)
|
111
134
|
|
112
135
|
# Do we need to create the shadow?
|
113
136
|
if shadow
|
@@ -116,11 +139,13 @@ module RNDK
|
|
116
139
|
end
|
117
140
|
|
118
141
|
# Setup the key bindings
|
119
|
-
|
120
|
-
|
121
|
-
|
142
|
+
self.bind_key('g') { self.scroll_begin }
|
143
|
+
self.bind_key('1') { self.scroll_begin }
|
144
|
+
self.bind_key('G') { self.scroll_end }
|
145
|
+
self.bind_key('<') { self.scroll_begin }
|
146
|
+
self.bind_key('>') { self.scroll_end }
|
122
147
|
|
123
|
-
|
148
|
+
screen.register(@widget_type, self)
|
124
149
|
end
|
125
150
|
|
126
151
|
# Put the cursor on the currently-selected item.
|
@@ -134,14 +159,14 @@ module RNDK
|
|
134
159
|
end
|
135
160
|
|
136
161
|
# This actually manages the radio widget.
|
137
|
-
def activate(actions)
|
138
|
-
# Draw the radio
|
139
|
-
self.draw
|
162
|
+
def activate(actions=[])
|
163
|
+
# Draw the radio items.
|
164
|
+
self.draw
|
140
165
|
|
141
166
|
if actions.nil? || actions.size == 0
|
142
167
|
while true
|
143
168
|
self.fixCursorPosition
|
144
|
-
input = self.getch
|
169
|
+
input = self.getch
|
145
170
|
|
146
171
|
# Inject the character into the widget.
|
147
172
|
ret = self.inject(input)
|
@@ -164,47 +189,38 @@ module RNDK
|
|
164
189
|
end
|
165
190
|
|
166
191
|
# This injects a single character into the widget.
|
167
|
-
def inject
|
168
|
-
pp_return =
|
169
|
-
ret =
|
192
|
+
def inject input
|
193
|
+
pp_return = true
|
194
|
+
ret = false
|
170
195
|
complete = false
|
171
196
|
|
172
197
|
# Set the exit type
|
173
198
|
self.set_exit_type(0)
|
174
199
|
|
175
|
-
# Draw the widget
|
176
|
-
self.
|
200
|
+
# Draw the widget items
|
201
|
+
self.draw_items(@box)
|
177
202
|
|
178
|
-
# Check if there is a pre-process function to be called
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
@pre_process_data, input)
|
183
|
-
end
|
203
|
+
# Check if there is a pre-process function to be called.
|
204
|
+
keep_going = self.run_signal_binding(:before_input, input)
|
205
|
+
|
206
|
+
if keep_going
|
184
207
|
|
185
|
-
# Should we continue?
|
186
|
-
if pp_return != 0
|
187
208
|
# Check for a predefined key binding.
|
188
|
-
if self.
|
189
|
-
|
209
|
+
if self.is_bound? input
|
210
|
+
self.run_key_binding input
|
211
|
+
#complete = true
|
190
212
|
else
|
191
213
|
case input
|
192
|
-
when Ncurses::KEY_UP
|
193
|
-
|
194
|
-
when Ncurses::
|
195
|
-
|
196
|
-
when Ncurses::
|
197
|
-
|
198
|
-
when Ncurses::
|
199
|
-
self.
|
200
|
-
when Ncurses::
|
201
|
-
self.
|
202
|
-
when Ncurses::KEY_NPAGE
|
203
|
-
self.KEY_NPAGE
|
204
|
-
when Ncurses::KEY_HOME
|
205
|
-
self.KEY_HOME
|
206
|
-
when Ncurses::KEY_END
|
207
|
-
self.KEY_END
|
214
|
+
when Ncurses::KEY_UP then self.scroll_up
|
215
|
+
when Ncurses::KEY_DOWN then self.scroll_down
|
216
|
+
when Ncurses::KEY_RIGHT then self.scroll_right
|
217
|
+
when Ncurses::KEY_LEFT then self.scroll_left
|
218
|
+
when Ncurses::KEY_HOME then self.scroll_begin
|
219
|
+
when Ncurses::KEY_END then self.scroll_end
|
220
|
+
when Ncurses::KEY_PPAGE, RNDK::BACKCHAR
|
221
|
+
self.scroll_page_up
|
222
|
+
when Ncurses::KEY_NPAGE, RNDK::FORCHAR
|
223
|
+
self.scroll_page_down
|
208
224
|
when '$'.ord
|
209
225
|
@left_char = @max_left_char
|
210
226
|
when '|'.ord
|
@@ -213,7 +229,7 @@ module RNDK
|
|
213
229
|
@selected_item = @current_item
|
214
230
|
when RNDK::KEY_ESC
|
215
231
|
self.set_exit_type(input)
|
216
|
-
ret =
|
232
|
+
ret = false
|
217
233
|
complete = true
|
218
234
|
when Ncurses::ERR
|
219
235
|
self.set_exit_type(input)
|
@@ -229,13 +245,11 @@ module RNDK
|
|
229
245
|
end
|
230
246
|
|
231
247
|
# Should we call a post-process?
|
232
|
-
if
|
233
|
-
@post_process_func.call(:RADIO, self, @post_process_data, input)
|
234
|
-
end
|
248
|
+
self.run_signal_binding(:after_input) if not complete
|
235
249
|
end
|
236
250
|
|
237
|
-
if
|
238
|
-
self.
|
251
|
+
if not complete
|
252
|
+
self.draw_items(@box)
|
239
253
|
self.set_exit_type(0)
|
240
254
|
end
|
241
255
|
|
@@ -245,34 +259,32 @@ module RNDK
|
|
245
259
|
end
|
246
260
|
|
247
261
|
# This moves the radio field to the given location.
|
248
|
-
def move(
|
262
|
+
def move(x, y, relative, refresh_flag)
|
249
263
|
windows = [@win, @scrollbar_win, @shadow_win]
|
250
|
-
self.move_specific(
|
264
|
+
self.move_specific(x, y, relative, refresh_flag,
|
251
265
|
windows, subwidgets)
|
252
266
|
end
|
253
267
|
|
254
268
|
# This function draws the radio widget.
|
255
|
-
def draw
|
269
|
+
def draw
|
256
270
|
# Do we need to draw in the shadow?
|
257
|
-
|
258
|
-
Draw.drawShadow(@shadow_win)
|
259
|
-
end
|
271
|
+
Draw.drawShadow(@shadow_win) unless @shadow_win.nil?
|
260
272
|
|
261
|
-
self.
|
273
|
+
self.draw_title @win
|
262
274
|
|
263
|
-
# Draw in the radio
|
264
|
-
self.
|
275
|
+
# Draw in the radio items.
|
276
|
+
self.draw_items @box
|
265
277
|
end
|
266
278
|
|
267
|
-
# This redraws the radio
|
268
|
-
def
|
279
|
+
# This redraws the radio items.
|
280
|
+
def draw_items(box)
|
269
281
|
scrollbar_adj = if @scrollbar_placement == RNDK::LEFT then 1 else 0 end
|
270
282
|
screen_pos = 0
|
271
283
|
|
272
|
-
# Draw the
|
284
|
+
# Draw the items
|
273
285
|
(0...@view_size).each do |j|
|
274
286
|
k = j + @current_top
|
275
|
-
if k < @
|
287
|
+
if k < @items_size
|
276
288
|
xpos = self.Screen_XPOS(0)
|
277
289
|
ypos = self.Screen_YPOS(j)
|
278
290
|
|
@@ -301,7 +313,7 @@ module RNDK
|
|
301
313
|
# Highlight the current item
|
302
314
|
if @has_focus
|
303
315
|
k = @current_item
|
304
|
-
if k < @
|
316
|
+
if k < @items_size
|
305
317
|
screen_pos = self.ScreenPOS(k, scrollbar_adj)
|
306
318
|
ypos = self.Screen_YPOS(@current_high)
|
307
319
|
|
@@ -326,7 +338,7 @@ module RNDK
|
|
326
338
|
Ncurses.mvwvline(@scrollbar_win,
|
327
339
|
@toggle_pos,
|
328
340
|
0,
|
329
|
-
' '.ord |
|
341
|
+
' '.ord | RNDK::Color[:reverse],
|
330
342
|
@toggle_size)
|
331
343
|
end
|
332
344
|
|
@@ -339,7 +351,7 @@ module RNDK
|
|
339
351
|
end
|
340
352
|
|
341
353
|
# This sets the background attribute of the widget.
|
342
|
-
def
|
354
|
+
def set_bg_color(attrib)
|
343
355
|
Ncurses.wbkgd(@win, attrib)
|
344
356
|
Ncurses.wbkgd(@scrollbar_win, attrib) unless @scrollbar_win.nil?
|
345
357
|
end
|
@@ -350,7 +362,7 @@ module RNDK
|
|
350
362
|
|
351
363
|
# This function destroys the radio widget.
|
352
364
|
def destroy
|
353
|
-
self.
|
365
|
+
self.clean_title
|
354
366
|
self.destroyInfo
|
355
367
|
|
356
368
|
# Clean up the windows.
|
@@ -359,33 +371,31 @@ module RNDK
|
|
359
371
|
RNDK.window_delete(@win)
|
360
372
|
|
361
373
|
# Clean up the key bindings.
|
362
|
-
self.clean_bindings
|
374
|
+
self.clean_bindings
|
363
375
|
|
364
|
-
# Unregister this
|
365
|
-
|
376
|
+
# Unregister this widget.
|
377
|
+
@screen.unregister self
|
366
378
|
end
|
367
379
|
|
368
380
|
# This function erases the radio widget
|
369
381
|
def erase
|
370
|
-
if self.
|
382
|
+
if self.valid?
|
371
383
|
RNDK.window_erase(@win)
|
372
384
|
RNDK.window_erase(@shadow_win)
|
373
385
|
end
|
374
386
|
end
|
375
387
|
|
376
|
-
# This sets various attributes of the radio
|
388
|
+
# This sets various attributes of the radio items.
|
377
389
|
def set(highlight, choice_char, box)
|
378
390
|
self.set_highlight(highlight)
|
379
391
|
self.setChoiceCHaracter(choice_char)
|
380
392
|
self.set_box(box)
|
381
393
|
end
|
382
394
|
|
383
|
-
# This sets the radio
|
384
|
-
def
|
385
|
-
widest_item = self.
|
386
|
-
if widest_item <= 0
|
387
|
-
return
|
388
|
-
end
|
395
|
+
# This sets the radio items items.
|
396
|
+
def set_items(items)
|
397
|
+
widest_item = self.create_items(items, @box_width)
|
398
|
+
return if widest_item <= 0
|
389
399
|
|
390
400
|
# Clean up the display.
|
391
401
|
(0...@view_size).each do |j|
|
@@ -393,23 +403,23 @@ module RNDK
|
|
393
403
|
RNDK::HORIZONTAL, 0, @box_width - @border_size)
|
394
404
|
end
|
395
405
|
|
396
|
-
self.
|
406
|
+
self.set_view_size(items_size)
|
397
407
|
|
398
|
-
self.
|
408
|
+
self.set_current_item(0)
|
399
409
|
@left_char = 0
|
400
410
|
@selected_item = 0
|
401
411
|
|
402
412
|
self.updateViewWidth(widest_item)
|
403
413
|
end
|
404
414
|
|
405
|
-
def getItems(
|
406
|
-
(0...@
|
407
|
-
|
415
|
+
def getItems(items)
|
416
|
+
(0...@items_size).each do |j|
|
417
|
+
items << RNDK.chtype2Char(@item[j])
|
408
418
|
end
|
409
|
-
return @
|
419
|
+
return @items_size
|
410
420
|
end
|
411
421
|
|
412
|
-
# This sets the highlight bar of the radio
|
422
|
+
# This sets the highlight bar of the radio items.
|
413
423
|
def set_highlight(highlight)
|
414
424
|
@highlight = highlight
|
415
425
|
end
|
@@ -418,7 +428,7 @@ module RNDK
|
|
418
428
|
return @highlight
|
419
429
|
end
|
420
430
|
|
421
|
-
# This sets the character to use when selecting na item in the
|
431
|
+
# This sets the character to use when selecting na item in the items.
|
422
432
|
def setChoiceCharacter(character)
|
423
433
|
@choice_char = character
|
424
434
|
end
|
@@ -428,7 +438,7 @@ module RNDK
|
|
428
438
|
end
|
429
439
|
|
430
440
|
# This sets the character to use to drw the left side of the choice box
|
431
|
-
# on the
|
441
|
+
# on the items
|
432
442
|
def setLeftBrace(character)
|
433
443
|
@left_box_char = character
|
434
444
|
end
|
@@ -438,7 +448,7 @@ module RNDK
|
|
438
448
|
end
|
439
449
|
|
440
450
|
# This sets the character to use to draw the right side of the choice box
|
441
|
-
# on the
|
451
|
+
# on the items
|
442
452
|
def setRightBrace(character)
|
443
453
|
@right_box_char = character
|
444
454
|
end
|
@@ -448,8 +458,8 @@ module RNDK
|
|
448
458
|
end
|
449
459
|
|
450
460
|
# This sets the current highlighted item of the widget
|
451
|
-
def
|
452
|
-
self.
|
461
|
+
def set_current_item(item)
|
462
|
+
self.set_position(item)
|
453
463
|
@selected_item = item
|
454
464
|
end
|
455
465
|
|
@@ -467,32 +477,32 @@ module RNDK
|
|
467
477
|
end
|
468
478
|
|
469
479
|
def focus
|
470
|
-
self.
|
480
|
+
self.draw_items(@box)
|
471
481
|
end
|
472
482
|
|
473
483
|
def unfocus
|
474
|
-
self.
|
484
|
+
self.draw_items(@box)
|
475
485
|
end
|
476
486
|
|
477
|
-
def
|
487
|
+
def create_items(items, box_width)
|
478
488
|
status = false
|
479
489
|
widest_item = 0
|
480
490
|
|
481
|
-
if
|
482
|
-
|
491
|
+
if items.size >= 0
|
492
|
+
new_items = []
|
483
493
|
new_len = []
|
484
494
|
new_pos = []
|
485
495
|
|
486
496
|
# Each item in the needs to be converted to chtype array
|
487
497
|
status = true
|
488
498
|
box_width -= 2 + @border_size
|
489
|
-
(0...
|
499
|
+
(0...items.size).each do |j|
|
490
500
|
lentmp = []
|
491
501
|
postmp = []
|
492
|
-
|
502
|
+
new_items << RNDK.char2Chtype(items[j], lentmp, postmp)
|
493
503
|
new_len << lentmp[0]
|
494
504
|
new_pos << postmp[0]
|
495
|
-
if
|
505
|
+
if new_items[j].nil? || new_items[j].size == 0
|
496
506
|
status = false
|
497
507
|
break
|
498
508
|
end
|
@@ -501,11 +511,12 @@ module RNDK
|
|
501
511
|
end
|
502
512
|
if status
|
503
513
|
self.destroyInfo
|
504
|
-
@item =
|
514
|
+
@item = new_items
|
505
515
|
@item_len = new_len
|
506
516
|
@item_pos = new_pos
|
507
517
|
end
|
508
518
|
end
|
519
|
+
@items_size = items.size
|
509
520
|
|
510
521
|
return (if status then widest_item else 0 end)
|
511
522
|
end
|
@@ -531,8 +542,7 @@ module RNDK
|
|
531
542
|
@item_pos[n] - @left_char + scrollbar_adj + @border_size
|
532
543
|
end
|
533
544
|
|
534
|
-
|
535
|
-
|
536
|
-
end
|
545
|
+
|
546
|
+
|
537
547
|
end
|
538
548
|
end
|