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
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
module RNDK
|
3
|
+
class Widget
|
4
|
+
|
5
|
+
# Returns the internal Widget that accepts key bindings.
|
6
|
+
#
|
7
|
+
# Some widgets are made of others.
|
8
|
+
# So when we bind keys to those complex widgets,
|
9
|
+
# we can specify which internal Widget accepts keybindings.
|
10
|
+
#
|
11
|
+
# For example, on an Alphalist (which is composed of Scroll
|
12
|
+
# and Entry), we bind keys to the Entry, not Scroll.
|
13
|
+
#
|
14
|
+
def bindable_widget rndktype
|
15
|
+
return nil if rndktype != @widget_type
|
16
|
+
|
17
|
+
|
18
|
+
if [:Fselect, :alphalist].include? @widget_type
|
19
|
+
return @entry_field
|
20
|
+
|
21
|
+
else
|
22
|
+
return self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Binds a `function` to a `key`.
|
27
|
+
#
|
28
|
+
def bind_key(key, data=nil, &action)
|
29
|
+
obj = self.bindable_widget @widget_type
|
30
|
+
|
31
|
+
if (key.ord >= Ncurses::KEY_MAX) or (key.ord.zero?) or (obj.nil?)
|
32
|
+
return
|
33
|
+
end
|
34
|
+
|
35
|
+
obj.binding_list[key.ord] = [action, data]
|
36
|
+
end
|
37
|
+
|
38
|
+
def unbind_key key
|
39
|
+
obj = self.bindable_widget @widget_type
|
40
|
+
|
41
|
+
obj.binding_list.delete(key) unless obj.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def clean_bindings
|
45
|
+
obj = self.bindable_widget @widget_type
|
46
|
+
|
47
|
+
if (not obj.nil?) and (not obj.binding_list.nil?)
|
48
|
+
obj.binding_list.clear
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Runs any binding that's set for `key`.
|
53
|
+
#
|
54
|
+
# @return The binding's return value or `false`, if no
|
55
|
+
# keybinding for `key` exists.
|
56
|
+
|
57
|
+
def run_key_binding key
|
58
|
+
obj = self.bindable_widget @widget_type
|
59
|
+
|
60
|
+
return false if obj.nil? or (not obj.binding_list.include? key)
|
61
|
+
|
62
|
+
function = obj.binding_list[key][0]
|
63
|
+
data = obj.binding_list[key][1]
|
64
|
+
|
65
|
+
# What the heck is this?
|
66
|
+
return data if function == :getc
|
67
|
+
|
68
|
+
function.call data
|
69
|
+
end
|
70
|
+
|
71
|
+
# Tells if the key binding for the key exists.
|
72
|
+
def is_bound? key
|
73
|
+
obj = self.bindable_widget @widget_type
|
74
|
+
return false if obj.nil?
|
75
|
+
|
76
|
+
obj.binding_list.include? key
|
77
|
+
end
|
78
|
+
|
79
|
+
# Binds an `action` to be executed when
|
80
|
+
# `signal` is activated.
|
81
|
+
def bind_signal(signal, &action)
|
82
|
+
return unless @supported_signals.include? signal
|
83
|
+
|
84
|
+
@actions[signal] = [] if @actions[signal].nil?
|
85
|
+
|
86
|
+
@actions[signal] << action
|
87
|
+
end
|
88
|
+
|
89
|
+
# Runs all actions based on `signal`, passing `data` as an
|
90
|
+
# argument.
|
91
|
+
#
|
92
|
+
# @note It interrupts executing when any action returns
|
93
|
+
# `false`.
|
94
|
+
# @return `true` if all actions were executed or no actions
|
95
|
+
# exist, `false` if they were interrupted.
|
96
|
+
def run_signal_binding(signal, data=nil)
|
97
|
+
return true if @actions[signal].nil?
|
98
|
+
|
99
|
+
@actions[signal].each do |action|
|
100
|
+
return false if action.call(data) == false
|
101
|
+
end
|
102
|
+
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
data/lib/rndk/dialog.rb
CHANGED
@@ -1,33 +1,72 @@
|
|
1
1
|
require 'rndk'
|
2
2
|
|
3
3
|
module RNDK
|
4
|
-
|
4
|
+
|
5
|
+
class Dialog < Widget
|
6
|
+
|
5
7
|
attr_reader :current_button
|
8
|
+
|
6
9
|
MIN_DIALOG_WIDTH = 10
|
7
10
|
|
8
|
-
def initialize(
|
9
|
-
button_count, highlight, separator, box, shadow)
|
11
|
+
def initialize(screen, config={})
|
10
12
|
super()
|
11
|
-
|
13
|
+
@widget_type = :dialog
|
14
|
+
@supported_signals += [:before_input, :after_input,
|
15
|
+
:before_pressing, :after_pressing]
|
16
|
+
|
17
|
+
x = 0
|
18
|
+
y = 0
|
19
|
+
text = "dialog"
|
20
|
+
buttons = ["button"]
|
21
|
+
highlight = RNDK::Color[:reverse]
|
22
|
+
separator = true
|
23
|
+
box = true
|
24
|
+
shadow = false
|
25
|
+
|
26
|
+
config.each do |key, val|
|
27
|
+
x = val if key == :x
|
28
|
+
y = val if key == :y
|
29
|
+
text = val if key == :text
|
30
|
+
buttons = val if key == :buttons
|
31
|
+
highlight = val if key == :highlight
|
32
|
+
separator = val if key == :separator
|
33
|
+
box = val if key == :box
|
34
|
+
shadow = val if key == :shadow
|
35
|
+
end
|
36
|
+
|
37
|
+
# Adjusting if the user sent us a String as text
|
38
|
+
text = [text] if text.class == String
|
39
|
+
return nil if text.class != Array or text.empty?
|
40
|
+
rows = text.size
|
41
|
+
|
42
|
+
# Adjusting if the user sent us a String as buttons
|
43
|
+
buttons = [buttons] if buttons.class == String
|
44
|
+
return nil if buttons.class != Array or buttons.empty?
|
45
|
+
button_count = buttons.size
|
46
|
+
|
47
|
+
box_width = Dialog::MIN_DIALOG_WIDTH
|
12
48
|
max_message_width = -1
|
13
49
|
button_width = 0
|
14
|
-
xpos =
|
15
|
-
ypos =
|
50
|
+
xpos = x
|
51
|
+
ypos = y
|
16
52
|
temp = 0
|
17
53
|
buttonadj = 0
|
18
54
|
@info = []
|
19
55
|
@info_len = []
|
20
56
|
@info_pos = []
|
21
|
-
@
|
57
|
+
@buttons = []
|
22
58
|
@button_len = []
|
23
59
|
@button_pos = []
|
24
60
|
|
61
|
+
@screen = screen
|
62
|
+
@parent = screen.window
|
63
|
+
|
25
64
|
if rows <= 0 || button_count <= 0
|
26
65
|
self.destroy
|
27
66
|
return nil
|
28
67
|
end
|
29
68
|
|
30
|
-
self.set_box
|
69
|
+
self.set_box box
|
31
70
|
box_height = if separator then 1 else 0 end
|
32
71
|
box_height += rows + 2 * @border_size + 1
|
33
72
|
|
@@ -35,7 +74,7 @@ module RNDK
|
|
35
74
|
(0...rows).each do |x|
|
36
75
|
info_len = []
|
37
76
|
info_pos = []
|
38
|
-
@info << RNDK.char2Chtype(
|
77
|
+
@info << RNDK.char2Chtype(text[x], info_len, info_pos)
|
39
78
|
@info_len << info_len[0]
|
40
79
|
@info_pos << info_pos[0]
|
41
80
|
max_message_width = [max_message_width, info_len[0]].max
|
@@ -44,7 +83,7 @@ module RNDK
|
|
44
83
|
# Translate the button label string to a chtype array
|
45
84
|
(0...button_count).each do |x|
|
46
85
|
button_len = []
|
47
|
-
@
|
86
|
+
@buttons << RNDK.char2Chtype(buttons[x], button_len, [])
|
48
87
|
@button_len << button_len[0]
|
49
88
|
button_width += button_len[0] + 1
|
50
89
|
end
|
@@ -58,13 +97,11 @@ module RNDK
|
|
58
97
|
# Now we have to readjust the x and y positions.
|
59
98
|
xtmp = [xpos]
|
60
99
|
ytmp = [ypos]
|
61
|
-
RNDK.alignxy(
|
100
|
+
RNDK.alignxy(screen.window, xtmp, ytmp, box_width, box_height)
|
62
101
|
xpos = xtmp[0]
|
63
102
|
ypos = ytmp[0]
|
64
103
|
|
65
104
|
# Set up the dialog box attributes.
|
66
|
-
@screen = rndkscreen
|
67
|
-
@parent = rndkscreen.window
|
68
105
|
@win = Ncurses.newwin(box_height, box_width, ypos, xpos)
|
69
106
|
@shadow_win = nil
|
70
107
|
@button_count = button_count
|
@@ -105,20 +142,20 @@ module RNDK
|
|
105
142
|
end
|
106
143
|
|
107
144
|
# Register this baby.
|
108
|
-
|
145
|
+
screen.register(@widget_type, self)
|
109
146
|
end
|
110
147
|
|
111
148
|
# This lets the user select the button.
|
112
|
-
def activate(actions)
|
149
|
+
def activate(actions=[])
|
113
150
|
input = 0
|
114
151
|
|
115
152
|
# Draw the dialog box.
|
116
|
-
self.draw
|
153
|
+
self.draw
|
117
154
|
|
118
155
|
# Lets move to the first button.
|
119
156
|
Draw.writeChtypeAttrib(@win,
|
120
157
|
@button_pos[@current_button],
|
121
|
-
@box_height - 1 - @border_size, @
|
158
|
+
@box_height - 1 - @border_size, @buttons[@current_button],
|
122
159
|
@highlight,
|
123
160
|
RNDK::HORIZONTAL,
|
124
161
|
0,
|
@@ -127,7 +164,7 @@ module RNDK
|
|
127
164
|
|
128
165
|
if actions.nil? || actions.size == 0
|
129
166
|
while true
|
130
|
-
input = self.getch
|
167
|
+
input = self.getch
|
131
168
|
|
132
169
|
# Inject the character into the widget.
|
133
170
|
ret = self.inject(input)
|
@@ -151,27 +188,26 @@ module RNDK
|
|
151
188
|
end
|
152
189
|
|
153
190
|
# This injects a single character into the dialog widget
|
154
|
-
def inject
|
191
|
+
def inject input
|
155
192
|
first_button = 0
|
156
193
|
last_button = @button_count - 1
|
157
|
-
pp_return =
|
158
|
-
ret =
|
194
|
+
pp_return = true
|
195
|
+
ret = false
|
159
196
|
complete = false
|
160
197
|
|
161
198
|
# Set the exit type.
|
162
199
|
self.set_exit_type(0)
|
163
200
|
|
164
201
|
# Check if there is a pre-process function to be called.
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
202
|
+
keep_going = self.run_signal_binding(:before_input, input)
|
203
|
+
|
204
|
+
if keep_going
|
169
205
|
|
170
|
-
# Should we continue?
|
171
|
-
if pp_return != 0
|
172
206
|
# Check for a key binding.
|
173
|
-
if self.
|
174
|
-
|
207
|
+
if self.is_bound? input
|
208
|
+
self.run_key_binding input
|
209
|
+
#complete = true
|
210
|
+
|
175
211
|
else
|
176
212
|
case input
|
177
213
|
when Ncurses::KEY_LEFT, Ncurses::KEY_BTAB, Ncurses::KEY_BACKSPACE
|
@@ -196,22 +232,24 @@ module RNDK
|
|
196
232
|
complete = true
|
197
233
|
when Ncurses::ERR
|
198
234
|
self.set_exit_type(input)
|
235
|
+
|
199
236
|
when Ncurses::KEY_ENTER, RNDK::KEY_RETURN
|
200
|
-
self.
|
201
|
-
|
202
|
-
|
237
|
+
keep_going = self.run_signal_binding(:before_pressing, @current_button)
|
238
|
+
if keep_going
|
239
|
+
self.set_exit_type(input)
|
240
|
+
ret = @current_button
|
241
|
+
complete = true
|
242
|
+
self.run_signal_binding(:after_pressing, ret)
|
243
|
+
end
|
203
244
|
end
|
204
245
|
end
|
205
246
|
|
206
247
|
# Should we call a post_process?
|
207
|
-
if
|
208
|
-
@post_process_func.call(:DIALOG, self,
|
209
|
-
@post_process_data, input)
|
210
|
-
end
|
248
|
+
self.run_signal_binding(:after_input) if not complete
|
211
249
|
end
|
212
250
|
|
213
251
|
unless complete
|
214
|
-
self.
|
252
|
+
self.draw_buttons
|
215
253
|
Ncurses.wrefresh @win
|
216
254
|
self.set_exit_type(0)
|
217
255
|
end
|
@@ -221,16 +259,14 @@ module RNDK
|
|
221
259
|
end
|
222
260
|
|
223
261
|
# This function draws the dialog widget.
|
224
|
-
def draw
|
262
|
+
def draw
|
225
263
|
# Is there a shadow?
|
226
264
|
unless @shadow_win.nil?
|
227
265
|
Draw.drawShadow(@shadow_win)
|
228
266
|
end
|
229
267
|
|
230
268
|
# Box the widget if they asked.
|
231
|
-
if box
|
232
|
-
Draw.drawObjBox(@win, self)
|
233
|
-
end
|
269
|
+
Draw.drawObjBox(@win, self) if @box
|
234
270
|
|
235
271
|
# Draw in the message.
|
236
272
|
(0...@message_rows).each do |x|
|
@@ -244,7 +280,7 @@ module RNDK
|
|
244
280
|
end
|
245
281
|
|
246
282
|
# Draw in the buttons.
|
247
|
-
self.
|
283
|
+
self.draw_buttons
|
248
284
|
|
249
285
|
Ncurses.wrefresh @win
|
250
286
|
end
|
@@ -256,15 +292,15 @@ module RNDK
|
|
256
292
|
RNDK.window_delete(@shadow_win)
|
257
293
|
|
258
294
|
# Clean the key bindings
|
259
|
-
self.clean_bindings
|
295
|
+
self.clean_bindings
|
260
296
|
|
261
|
-
# Unregister this
|
262
|
-
|
297
|
+
# Unregister this widget
|
298
|
+
@screen.unregister self
|
263
299
|
end
|
264
300
|
|
265
301
|
# This function erases the dialog widget from the screen.
|
266
302
|
def erase
|
267
|
-
if self.
|
303
|
+
if self.valid?
|
268
304
|
RNDK.window_erase(@win)
|
269
305
|
RNDK.window_erase(@shadow_win)
|
270
306
|
end
|
@@ -296,17 +332,17 @@ module RNDK
|
|
296
332
|
end
|
297
333
|
|
298
334
|
# This sets the background attribute of the widget.
|
299
|
-
def
|
335
|
+
def set_bg_color(attrib)
|
300
336
|
Ncurses.wbkgd(@win, attrib)
|
301
337
|
end
|
302
338
|
|
303
339
|
# This draws the dialog buttons and the separation line.
|
304
|
-
def
|
340
|
+
def draw_buttons
|
305
341
|
(0...@button_count).each do |x|
|
306
342
|
Draw.writeChtype(@win,
|
307
343
|
@button_pos[x],
|
308
344
|
@box_height -1 - @border_size,
|
309
|
-
@
|
345
|
+
@buttons[x],
|
310
346
|
RNDK::HORIZONTAL,
|
311
347
|
0,
|
312
348
|
@button_len[x])
|
@@ -335,7 +371,7 @@ module RNDK
|
|
335
371
|
Draw.writeChtypeAttrib(@win,
|
336
372
|
@button_pos[@current_button],
|
337
373
|
@box_height - 1 - @border_size,
|
338
|
-
@
|
374
|
+
@buttons[@current_button],
|
339
375
|
@highlight,
|
340
376
|
RNDK::HORIZONTAL,
|
341
377
|
0,
|
@@ -343,15 +379,11 @@ module RNDK
|
|
343
379
|
end
|
344
380
|
|
345
381
|
def focus
|
346
|
-
self.draw
|
382
|
+
self.draw
|
347
383
|
end
|
348
384
|
|
349
385
|
def unfocus
|
350
|
-
self.draw
|
351
|
-
end
|
352
|
-
|
353
|
-
def object_type
|
354
|
-
:DIALOG
|
386
|
+
self.draw
|
355
387
|
end
|
356
388
|
|
357
389
|
def position
|
data/lib/rndk/entry.rb
CHANGED
@@ -84,26 +84,25 @@ module RNDK
|
|
84
84
|
attr_reader :win, :box_height, :box_width, :max, :field_width
|
85
85
|
attr_reader :min, :max
|
86
86
|
|
87
|
-
|
88
87
|
# Creates an Entry Widget.
|
89
88
|
#
|
90
89
|
# ## Arguments
|
91
90
|
#
|
92
|
-
# * `
|
91
|
+
# * `x` is the x position - can be an integer or
|
93
92
|
# `RNDK::LEFT`, `RNDK::RIGHT`, `RNDK::CENTER`.
|
94
|
-
# * `
|
93
|
+
# * `y` is the y position - can be an integer or
|
95
94
|
# `RNDK::TOP`, `RNDK::BOTTOM`, `RNDK::CENTER`.
|
96
95
|
# * `title` can be more than one line - just split them
|
97
96
|
# with `\n`s.
|
98
97
|
# * `label` is the String that will appear on the label
|
99
98
|
# of the Entry field.
|
100
|
-
# * `
|
99
|
+
# * `field_color` is the attribute/color of the characters
|
101
100
|
# that are typed in.
|
102
101
|
# * `filler_char` is the character to display on the
|
103
102
|
# empty spaces in the entry field.
|
104
103
|
# * `disp_type` tells how the entry field will behave.
|
105
104
|
# _See main Entry documentation_.
|
106
|
-
# * `
|
105
|
+
# * `field_width` is the width of the field. It it's 0,
|
107
106
|
# will be created with full width of the screen.
|
108
107
|
# If it's a negative value, will create with full width
|
109
108
|
# minus that value.
|
@@ -114,36 +113,57 @@ module RNDK
|
|
114
113
|
# * `box` if the Widget is drawn with a box outside it.
|
115
114
|
# * `shadow` turns on/off the shadow around the Widget.
|
116
115
|
#
|
117
|
-
def initialize(
|
118
|
-
xplace,
|
119
|
-
yplace,
|
120
|
-
title,
|
121
|
-
label,
|
122
|
-
field_attr,
|
123
|
-
filler,
|
124
|
-
disp_type,
|
125
|
-
f_width,
|
126
|
-
min,
|
127
|
-
max,
|
128
|
-
box,
|
129
|
-
shadow)
|
116
|
+
def initialize(screen, config={})
|
130
117
|
super()
|
118
|
+
@widget_type = :entry
|
119
|
+
@supported_signals += [:before_input, :after_input]
|
120
|
+
|
121
|
+
x = 0
|
122
|
+
y = 0
|
123
|
+
title = "entry"
|
124
|
+
label = "label"
|
125
|
+
field_color = RNDK::Color[:normal]
|
126
|
+
filler = '.'
|
127
|
+
disp_type = :MIXED
|
128
|
+
field_width = 0
|
129
|
+
initial_text = ""
|
130
|
+
min = 0
|
131
|
+
max = 9001
|
132
|
+
box = true
|
133
|
+
shadow = false
|
134
|
+
|
135
|
+
config.each do |key, val|
|
136
|
+
x = val if key == :x
|
137
|
+
y = val if key == :y
|
138
|
+
title = val if key == :title
|
139
|
+
label = val if key == :label
|
140
|
+
field_color = val if key == :field_color
|
141
|
+
filler = val if key == :filler
|
142
|
+
disp_type = val if key == :disp_type
|
143
|
+
field_width = val if key == :field_width
|
144
|
+
initial_text = val if key == :initial_text
|
145
|
+
min = val if key == :min
|
146
|
+
max = val if key == :max
|
147
|
+
box = val if key == :box
|
148
|
+
shadow = val if key == :shadow
|
149
|
+
end
|
131
150
|
|
132
|
-
parent_width = Ncurses.getmaxx
|
133
|
-
parent_height = Ncurses.getmaxy
|
151
|
+
parent_width = Ncurses.getmaxx screen.window
|
152
|
+
parent_height = Ncurses.getmaxy screen.window
|
134
153
|
|
135
|
-
field_width =
|
154
|
+
field_width = field_width
|
136
155
|
box_width = 0
|
137
156
|
|
138
|
-
xpos =
|
139
|
-
ypos =
|
157
|
+
xpos = x
|
158
|
+
ypos = y
|
140
159
|
|
141
160
|
self.set_box box
|
142
161
|
box_height = @border_size*2 + 1
|
143
162
|
|
144
|
-
# If the field_width is a negative value, the field_width
|
145
|
-
# COLS-field_width, otherwise the field_width will
|
146
|
-
|
163
|
+
# If the field_width is a negative value, the field_width
|
164
|
+
# WILL be COLS-field_width, otherwise the field_width will
|
165
|
+
# be the given width.
|
166
|
+
field_width = RNDK.set_widget_dimension(parent_width, field_width, 0)
|
147
167
|
box_width = field_width + 2*@border_size
|
148
168
|
|
149
169
|
# Set some basic values of the entry field.
|
@@ -174,12 +194,12 @@ module RNDK
|
|
174
194
|
# Rejustify the x and y positions if we need to.
|
175
195
|
xtmp = [xpos]
|
176
196
|
ytmp = [ypos]
|
177
|
-
RNDK.alignxy(
|
197
|
+
RNDK.alignxy(screen.window, xtmp, ytmp, box_width, box_height)
|
178
198
|
xpos = xtmp[0]
|
179
199
|
ypos = ytmp[0]
|
180
200
|
|
181
201
|
# Make the label window.
|
182
|
-
@win = Ncurses.subwin(
|
202
|
+
@win = Ncurses.subwin(screen.window, box_height, box_width, ypos, xpos)
|
183
203
|
if @win.nil?
|
184
204
|
self.destroy
|
185
205
|
return nil
|
@@ -211,10 +231,10 @@ module RNDK
|
|
211
231
|
@info_width = max + 3
|
212
232
|
|
213
233
|
# Set up the rest of the structure.
|
214
|
-
@screen =
|
215
|
-
@parent =
|
234
|
+
@screen = screen
|
235
|
+
@parent = screen.window
|
216
236
|
@shadow_win = nil
|
217
|
-
@
|
237
|
+
@field_color = field_color
|
218
238
|
@field_width = field_width
|
219
239
|
@filler = filler
|
220
240
|
@hidden = filler
|
@@ -255,16 +275,18 @@ module RNDK
|
|
255
275
|
end
|
256
276
|
end
|
257
277
|
|
278
|
+
self.set_text initial_text
|
279
|
+
|
258
280
|
# Do we want a shadow?
|
259
281
|
if shadow
|
260
|
-
@shadow_win = Ncurses.subwin(
|
282
|
+
@shadow_win = Ncurses.subwin(screen.window,
|
261
283
|
box_height,
|
262
284
|
box_width,
|
263
285
|
ypos + 1,
|
264
286
|
xpos + 1)
|
265
287
|
end
|
266
288
|
|
267
|
-
|
289
|
+
screen.register(:entry, self)
|
268
290
|
end
|
269
291
|
|
270
292
|
# Activates the Entry Widget, letting the user interact with it.
|
@@ -280,11 +302,11 @@ module RNDK
|
|
280
302
|
ret = 0
|
281
303
|
|
282
304
|
# Draw the widget.
|
283
|
-
self.draw
|
305
|
+
self.draw
|
284
306
|
|
285
307
|
if actions.nil? or actions.size == 0
|
286
308
|
while true
|
287
|
-
input = self.getch
|
309
|
+
input = self.getch
|
288
310
|
|
289
311
|
# Inject the character into the widget.
|
290
312
|
ret = self.inject(input)
|
@@ -312,7 +334,7 @@ module RNDK
|
|
312
334
|
|
313
335
|
# @see Widget#inject
|
314
336
|
def inject input
|
315
|
-
pp_return =
|
337
|
+
pp_return = true
|
316
338
|
ret = 1
|
317
339
|
complete = false
|
318
340
|
|
@@ -322,17 +344,15 @@ module RNDK
|
|
322
344
|
# Refresh the widget field.
|
323
345
|
self.drawField
|
324
346
|
|
325
|
-
|
326
|
-
|
327
|
-
@pre_process_data, input)
|
328
|
-
end
|
347
|
+
# Check if there is a pre-process function to be called.
|
348
|
+
keep_going = self.run_signal_binding(:before_input, input)
|
329
349
|
|
330
|
-
|
331
|
-
if pp_return != 0
|
350
|
+
if keep_going
|
332
351
|
|
333
352
|
# Check a predefined binding
|
334
|
-
if self.
|
335
|
-
|
353
|
+
if self.is_bound? input
|
354
|
+
self.run_key_binding input
|
355
|
+
#complete = true
|
336
356
|
|
337
357
|
else
|
338
358
|
curr_pos = @screen_col + @left_char
|
@@ -472,9 +492,8 @@ module RNDK
|
|
472
492
|
end
|
473
493
|
end
|
474
494
|
|
475
|
-
|
476
|
-
|
477
|
-
end
|
495
|
+
# Should we do a post-process?
|
496
|
+
self.run_signal_binding(:after_input) if not complete
|
478
497
|
end
|
479
498
|
|
480
499
|
unless complete
|
@@ -486,10 +505,10 @@ module RNDK
|
|
486
505
|
end
|
487
506
|
|
488
507
|
# @see Widget#move
|
489
|
-
def move(
|
508
|
+
def move(x, y, relative, refresh_flag)
|
490
509
|
windows = [@win, @field_win, @label_win, @shadow_win]
|
491
510
|
|
492
|
-
self.move_specific(
|
511
|
+
self.move_specific(x, y, relative, refresh_flag, windows, [])
|
493
512
|
end
|
494
513
|
|
495
514
|
# Clears the text from the entry field.
|
@@ -512,14 +531,14 @@ module RNDK
|
|
512
531
|
# Draws the Widget on the Screen.
|
513
532
|
#
|
514
533
|
# If `box` is true, it is drawn with a box.
|
515
|
-
def draw
|
534
|
+
def draw
|
516
535
|
# Did we ask for a shadow?
|
517
536
|
Draw.drawShadow @shadow_win unless @shadow_win.nil?
|
518
537
|
|
519
538
|
# Box the widget if asked.
|
520
|
-
Draw.drawObjBox(@win, self) if box
|
539
|
+
Draw.drawObjBox(@win, self) if @box
|
521
540
|
|
522
|
-
self.
|
541
|
+
self.draw_title @win
|
523
542
|
Ncurses.wrefresh @win
|
524
543
|
|
525
544
|
# Draw in the label to the widget.
|
@@ -540,7 +559,7 @@ module RNDK
|
|
540
559
|
|
541
560
|
# @see Widget#erase
|
542
561
|
def erase
|
543
|
-
if self.
|
562
|
+
if self.valid?
|
544
563
|
RNDK.window_erase(@field_win)
|
545
564
|
RNDK.window_erase(@label_win)
|
546
565
|
RNDK.window_erase(@win)
|
@@ -550,16 +569,16 @@ module RNDK
|
|
550
569
|
|
551
570
|
# @see Widget#destroy
|
552
571
|
def destroy
|
553
|
-
self.
|
572
|
+
self.clean_title
|
554
573
|
|
555
574
|
RNDK.window_delete(@field_win)
|
556
575
|
RNDK.window_delete(@label_win)
|
557
576
|
RNDK.window_delete(@shadow_win)
|
558
577
|
RNDK.window_delete(@win)
|
559
578
|
|
560
|
-
self.clean_bindings
|
579
|
+
self.clean_bindings
|
561
580
|
|
562
|
-
|
581
|
+
@screen.unregister self
|
563
582
|
end
|
564
583
|
|
565
584
|
# Sets multiple attributes of the Widget.
|
@@ -635,7 +654,7 @@ module RNDK
|
|
635
654
|
end
|
636
655
|
|
637
656
|
# Sets the background attribute/color of the widget.
|
638
|
-
def
|
657
|
+
def set_bg_color attrib
|
639
658
|
Ncurses.wbkgd(@win, attrib)
|
640
659
|
Ncurses.wbkgd(@field_win, attrib)
|
641
660
|
|
@@ -648,7 +667,7 @@ module RNDK
|
|
648
667
|
# See Ncurses#curs_set.
|
649
668
|
def set_highlight(highlight, cursor)
|
650
669
|
Ncurses.wbkgd(@field_win, highlight)
|
651
|
-
@
|
670
|
+
@field_color = highlight
|
652
671
|
Ncurses.curs_set cursor
|
653
672
|
|
654
673
|
# FIXME(original) - if (cursor) { move the cursor to this widget }
|
@@ -660,7 +679,7 @@ module RNDK
|
|
660
679
|
end
|
661
680
|
|
662
681
|
def unfocus
|
663
|
-
self.draw
|
682
|
+
self.draw
|
664
683
|
Ncurses.wrefresh @field_win
|
665
684
|
end
|
666
685
|
|
@@ -669,10 +688,6 @@ module RNDK
|
|
669
688
|
super @win
|
670
689
|
end
|
671
690
|
|
672
|
-
def object_type
|
673
|
-
:entry
|
674
|
-
end
|
675
|
-
|
676
691
|
# Allows the programmer to set a different widget input handler.
|
677
692
|
#
|
678
693
|
# @note Unless you're very low-level and know what you're doing
|
@@ -696,7 +711,7 @@ module RNDK
|
|
696
711
|
end
|
697
712
|
else
|
698
713
|
(@left_char...@info.size).each do |x|
|
699
|
-
Ncurses.mvwaddch(@field_win, 0, x - @left_char, @info[x].ord | @
|
714
|
+
Ncurses.mvwaddch(@field_win, 0, x - @left_char, @info[x].ord | @field_color)
|
700
715
|
end
|
701
716
|
end
|
702
717
|
Ncurses.wmove(@field_win, 0, @screen_col)
|