cdk 0.9.0 → 0.10.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/lib/cdk.rb +7 -866
- data/lib/cdk/cdk_objs.rb +46 -423
- data/lib/cdk/components.rb +28 -0
- data/lib/cdk/{alphalist.rb → components/alphalist.rb} +9 -6
- data/lib/cdk/components/button.rb +405 -0
- data/lib/cdk/{buttonbox.rb → components/buttonbox.rb} +11 -11
- data/lib/cdk/{calendar.rb → components/calendar.rb} +13 -13
- data/lib/cdk/components/dialog.rb +343 -0
- data/lib/cdk/{dscale.rb → components/dscale.rb} +0 -0
- data/lib/cdk/{entry.rb → components/entry.rb} +18 -18
- data/lib/cdk/{fscale.rb → components/fscale.rb} +1 -1
- data/lib/cdk/{fselect.rb → components/fselect.rb} +16 -13
- data/lib/cdk/{fslider.rb → components/fslider.rb} +1 -1
- data/lib/cdk/components/graph.rb +386 -0
- data/lib/cdk/{histogram.rb → components/histogram.rb} +3 -3
- data/lib/cdk/{itemlist.rb → components/itemlist.rb} +14 -14
- data/lib/cdk/{label.rb → components/label.rb} +7 -7
- data/lib/cdk/{marquee.rb → components/marquee.rb} +7 -7
- data/lib/cdk/{matrix.rb → components/matrix.rb} +27 -27
- data/lib/cdk/{mentry.rb → components/mentry.rb} +18 -18
- data/lib/cdk/{menu.rb → components/menu.rb} +18 -18
- data/lib/cdk/{radio.rb → components/radio.rb} +12 -12
- data/lib/cdk/{scale.rb → components/scale.rb} +13 -13
- data/lib/cdk/{scroll.rb → components/scroll.rb} +23 -386
- data/lib/cdk/{scroller.rb → components/scroller.rb} +1 -1
- data/lib/cdk/{selection.rb → components/selection.rb} +14 -14
- data/lib/cdk/{slider.rb → components/slider.rb} +15 -15
- data/lib/cdk/{swindow.rb → components/swindow.rb} +14 -14
- data/lib/cdk/{template.rb → components/template.rb} +18 -18
- data/lib/cdk/{uscale.rb → components/uscale.rb} +0 -0
- data/lib/cdk/{uslider.rb → components/uslider.rb} +0 -0
- data/lib/cdk/{viewer.rb → components/viewer.rb} +88 -18
- data/lib/cdk/constants.rb +54 -0
- data/lib/cdk/display.rb +30 -35
- data/lib/cdk/draw.rb +4 -6
- data/lib/cdk/helpers/file.rb +43 -0
- data/lib/cdk/helpers/types.rb +13 -0
- data/lib/cdk/helpers/window.rb +64 -0
- data/lib/cdk/mixins/alignments.rb +55 -0
- data/lib/cdk/mixins/bindings.rb +73 -0
- data/lib/cdk/mixins/borders.rb +62 -0
- data/lib/cdk/mixins/common_controls.rb +14 -0
- data/lib/cdk/mixins/converters.rb +358 -0
- data/lib/cdk/mixins/exit_conditions.rb +31 -0
- data/lib/cdk/mixins/focusable.rb +17 -0
- data/lib/cdk/mixins/formattable.rb +15 -0
- data/lib/cdk/mixins/has_screen.rb +23 -0
- data/lib/cdk/mixins/has_title.rb +64 -0
- data/lib/cdk/mixins/justifications.rb +26 -0
- data/lib/cdk/mixins/list_support.rb +31 -0
- data/lib/cdk/mixins/movement.rb +140 -0
- data/lib/cdk/mixins/window_hooks.rb +18 -0
- data/lib/cdk/mixins/window_input.rb +61 -0
- data/lib/cdk/screen.rb +27 -3
- metadata +51 -29
- data/lib/cdk/dialog.rb +0 -727
@@ -0,0 +1,14 @@
|
|
1
|
+
module CDK
|
2
|
+
module CommonControls
|
3
|
+
attr_reader :quit_on_enter
|
4
|
+
|
5
|
+
def quit_on_enter=(v)
|
6
|
+
@quit_on_enter_set = true
|
7
|
+
@quit_on_enter = v
|
8
|
+
end
|
9
|
+
|
10
|
+
def quit_on_enter?
|
11
|
+
@quit_on_enter_set ? @quit_on_enter : true
|
12
|
+
end
|
13
|
+
end # module CommonControls
|
14
|
+
end # module CDK
|
@@ -0,0 +1,358 @@
|
|
1
|
+
module CDK
|
2
|
+
module Converters
|
3
|
+
def encode_attribute (string, from, mask)
|
4
|
+
mask << 0
|
5
|
+
case string[from + 1]
|
6
|
+
when 'B'
|
7
|
+
mask[0] = Ncurses::A_BOLD
|
8
|
+
when 'D'
|
9
|
+
mask[0] = Ncurses::A_DIM
|
10
|
+
when 'K'
|
11
|
+
mask[0] = Ncurses::A_BLINK
|
12
|
+
when 'R'
|
13
|
+
mask[0] = Ncurses::A_REVERSE
|
14
|
+
when 'S'
|
15
|
+
mask[0] = Ncurses::A_STANDOUT
|
16
|
+
when 'U'
|
17
|
+
mask[0] = Ncurses::A_UNDERLINE
|
18
|
+
end
|
19
|
+
|
20
|
+
if mask[0] != 0
|
21
|
+
from += 1
|
22
|
+
elsif CDK.digit?(string[from+1]) and CDK.digit?(string[from + 2])
|
23
|
+
if Ncurses.has_colors?
|
24
|
+
# XXX: Only checks if terminal has colours not if colours are started
|
25
|
+
pair = string[from + 1..from + 2].to_i
|
26
|
+
mask[0] = Ncurses.COLOR_PAIR(pair)
|
27
|
+
else
|
28
|
+
mask[0] = Ncurses.A_BOLD
|
29
|
+
end
|
30
|
+
|
31
|
+
from += 2
|
32
|
+
elsif CDK.digit?(string[from + 1])
|
33
|
+
if Ncurses.has_colors?
|
34
|
+
# XXX: Only checks if terminal has colours not if colours are started
|
35
|
+
pair = string[from + 1].to_i
|
36
|
+
mask[0] = Ncurses.COLOR_PAIR(pair)
|
37
|
+
else
|
38
|
+
mask[0] = Ncurses.A_BOLD
|
39
|
+
end
|
40
|
+
|
41
|
+
from += 1
|
42
|
+
end
|
43
|
+
|
44
|
+
return from
|
45
|
+
end
|
46
|
+
|
47
|
+
# The reverse of encode_attribute
|
48
|
+
# Well, almost. If attributes such as bold and underline are combined in the
|
49
|
+
# same string, we do not necessarily reconstruct them in the same order.
|
50
|
+
# Also, alignment markers and tabs are lost.
|
51
|
+
|
52
|
+
def decode_attribute (string, from, oldattr, newattr)
|
53
|
+
table = {
|
54
|
+
'B' => Ncurses::A_BOLD,
|
55
|
+
'D' => Ncurses::A_DIM,
|
56
|
+
'K' => Ncurses::A_BLINK,
|
57
|
+
'R' => Ncurses::A_REVERSE,
|
58
|
+
'S' => Ncurses::A_STANDOUT,
|
59
|
+
'U' => Ncurses::A_UNDERLINE
|
60
|
+
}
|
61
|
+
|
62
|
+
result = if string.nil? then '' else string end
|
63
|
+
base_len = result.size
|
64
|
+
tmpattr = oldattr & Ncurses::A_ATTRIBUTES
|
65
|
+
|
66
|
+
newattr &= Ncurses::A_ATTRIBUTES
|
67
|
+
if tmpattr != newattr
|
68
|
+
while tmpattr != newattr
|
69
|
+
found = false
|
70
|
+
table.keys.each do |key|
|
71
|
+
if (table[key] & tmpattr) != (table[key] & newattr)
|
72
|
+
found = true
|
73
|
+
result << CDK::L_MARKER
|
74
|
+
if (table[key] & tmpattr).nonzero?
|
75
|
+
result << '!'
|
76
|
+
tmpattr &= ~(table[key])
|
77
|
+
else
|
78
|
+
result << '/'
|
79
|
+
tmpattr |= table[key]
|
80
|
+
end
|
81
|
+
result << key
|
82
|
+
break
|
83
|
+
end
|
84
|
+
end
|
85
|
+
# XXX: Only checks if terminal has colours not if colours are started
|
86
|
+
if Ncurses.has_colors?
|
87
|
+
if (tmpattr & Ncurses::A_COLOR) != (newattr & Ncurses::A_COLOR)
|
88
|
+
oldpair = Ncurses.PAIR_NUMBER(tmpattr)
|
89
|
+
newpair = Ncurses.PAIR_NUMBER(newattr)
|
90
|
+
if !found
|
91
|
+
found = true
|
92
|
+
result << CDK::L_MARKER
|
93
|
+
end
|
94
|
+
if newpair.zero?
|
95
|
+
result << '!'
|
96
|
+
result << oldpair.to_s
|
97
|
+
else
|
98
|
+
result << '/'
|
99
|
+
result << newpair.to_s
|
100
|
+
end
|
101
|
+
tmpattr &= ~(Ncurses::A_COLOR)
|
102
|
+
newattr &= ~(Ncurses::A_COLOR)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if found
|
107
|
+
result << CDK::R_MARKER
|
108
|
+
else
|
109
|
+
break
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
return from + result.size - base_len
|
115
|
+
end
|
116
|
+
|
117
|
+
# This function takes a string, full of format markers and translates
|
118
|
+
# them into a chtype array. This is better suited to curses because
|
119
|
+
# curses uses chtype almost exclusively
|
120
|
+
def char2Chtype (string, to, align)
|
121
|
+
to << 0
|
122
|
+
align << LEFT
|
123
|
+
result = []
|
124
|
+
|
125
|
+
if string.size > 0
|
126
|
+
used = 0
|
127
|
+
|
128
|
+
# The original code makes two passes since it has to pre-allocate space but
|
129
|
+
# we should be able to make do with one since we can dynamically size it
|
130
|
+
adjust = 0
|
131
|
+
attrib = Ncurses::A_NORMAL
|
132
|
+
last_char = 0
|
133
|
+
start = 0
|
134
|
+
used = 0
|
135
|
+
x = 3
|
136
|
+
|
137
|
+
# Look for an alignment marker.
|
138
|
+
if string[0] == L_MARKER
|
139
|
+
if string[1] == 'C' && string[2] == R_MARKER
|
140
|
+
align[0] = CENTER
|
141
|
+
start = 3
|
142
|
+
elsif string[1] == 'R' && string[2] == R_MARKER
|
143
|
+
align[0] = RIGHT
|
144
|
+
start = 3
|
145
|
+
elsif string[1] == 'L' && string[2] == R_MARKER
|
146
|
+
start = 3
|
147
|
+
elsif string[1] == 'B' && string[2] == '='
|
148
|
+
# Set the item index value in the string.
|
149
|
+
result = [' '.ord, ' '.ord, ' '.ord]
|
150
|
+
|
151
|
+
# Pull out the bullet marker.
|
152
|
+
while x < string.size and string[x] != R_MARKER
|
153
|
+
result << (string[x].ord | Ncurses::A_BOLD)
|
154
|
+
x += 1
|
155
|
+
end
|
156
|
+
adjust = 1
|
157
|
+
|
158
|
+
# Set the alignment variables
|
159
|
+
start = x
|
160
|
+
used = x
|
161
|
+
elsif string[1] == 'I' && string[2] == '='
|
162
|
+
from = 3
|
163
|
+
x = 0
|
164
|
+
|
165
|
+
while from < string.size && string[from] != Ncurses.R_MARKER
|
166
|
+
if CDK.digit?(string[from])
|
167
|
+
adjust = adjust * 10 + string[from].to_i
|
168
|
+
x += 1
|
169
|
+
end
|
170
|
+
from += 1
|
171
|
+
end
|
172
|
+
|
173
|
+
start = x + 4
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
while adjust > 0
|
178
|
+
adjust -= 1
|
179
|
+
result << ' '
|
180
|
+
used += 1
|
181
|
+
end
|
182
|
+
|
183
|
+
# Set the format marker boolean to false
|
184
|
+
inside_marker = false
|
185
|
+
|
186
|
+
# Start parsing the character string.
|
187
|
+
from = start
|
188
|
+
while from < string.size
|
189
|
+
# Are we inside a format marker?
|
190
|
+
if !inside_marker
|
191
|
+
if string[from] == L_MARKER &&
|
192
|
+
['/', '!', '#'].include?(string[from + 1])
|
193
|
+
inside_marker = true
|
194
|
+
elsif string[from] == "\\" && string[from + 1] == L_MARKER
|
195
|
+
from += 1
|
196
|
+
result << (string[from].ord | attrib)
|
197
|
+
used += 1
|
198
|
+
from += 1
|
199
|
+
elsif string[from] == "\t"
|
200
|
+
begin
|
201
|
+
result << ' '
|
202
|
+
used += 1
|
203
|
+
end while (used & 7).nonzero?
|
204
|
+
else
|
205
|
+
result << (string[from].ord | attrib)
|
206
|
+
used += 1
|
207
|
+
end
|
208
|
+
else
|
209
|
+
case string[from]
|
210
|
+
when R_MARKER
|
211
|
+
inside_marker = false
|
212
|
+
when '#'
|
213
|
+
last_char = 0
|
214
|
+
case string[from + 2]
|
215
|
+
when 'L'
|
216
|
+
case string[from + 1]
|
217
|
+
when 'L'
|
218
|
+
last_char = Ncurses::ACS_LLCORNER
|
219
|
+
when 'U'
|
220
|
+
last_char = Ncurses::ACS_ULCORNER
|
221
|
+
when 'H'
|
222
|
+
last_char = Ncurses::ACS_HLINE
|
223
|
+
when 'V'
|
224
|
+
last_char = Ncurses::ACS_VLINE
|
225
|
+
when 'P'
|
226
|
+
last_char = Ncurses::ACS_PLUS
|
227
|
+
end
|
228
|
+
when 'R'
|
229
|
+
case string[from + 1]
|
230
|
+
when 'L'
|
231
|
+
last_char = Ncurses::ACS_LRCORNER
|
232
|
+
when 'U'
|
233
|
+
last_char = Ncurses::ACS_URCORNER
|
234
|
+
end
|
235
|
+
when 'T'
|
236
|
+
case string[from + 1]
|
237
|
+
when 'T'
|
238
|
+
last_char = Ncurses::ACS_TTEE
|
239
|
+
when 'R'
|
240
|
+
last_char = Ncurses::ACS_RTEE
|
241
|
+
when 'L'
|
242
|
+
last_char = Ncurses::ACS_LTEE
|
243
|
+
when 'B'
|
244
|
+
last_char = Ncurses::ACS_BTEE
|
245
|
+
end
|
246
|
+
when 'A'
|
247
|
+
case string[from + 1]
|
248
|
+
when 'L'
|
249
|
+
last_char = Ncurses::ACS_LARROW
|
250
|
+
when 'R'
|
251
|
+
last_char = Ncurses::ACS_RARROW
|
252
|
+
when 'U'
|
253
|
+
last_char = Ncurses::ACS_UARROW
|
254
|
+
when 'D'
|
255
|
+
last_char = Ncurses::ACS_DARROW
|
256
|
+
end
|
257
|
+
else
|
258
|
+
case [string[from + 1], string[from + 2]]
|
259
|
+
when ['D', 'I']
|
260
|
+
last_char = Ncurses::ACS_DIAMOND
|
261
|
+
when ['C', 'B']
|
262
|
+
last_char = Ncurses::ACS_CKBOARD
|
263
|
+
when ['D', 'G']
|
264
|
+
last_char = Ncurses::ACS_DEGREE
|
265
|
+
when ['P', 'M']
|
266
|
+
last_char = Ncurses::ACS_PLMINUS
|
267
|
+
when ['B', 'U']
|
268
|
+
last_char = Ncurses::ACS_BULLET
|
269
|
+
when ['S', '1']
|
270
|
+
last_char = Ncurses::ACS_S1
|
271
|
+
when ['S', '9']
|
272
|
+
last_char = Ncurses::ACS_S9
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
if last_char.nonzero?
|
277
|
+
adjust = 1
|
278
|
+
from += 2
|
279
|
+
|
280
|
+
if string[from + 1] == '('
|
281
|
+
# check for a possible numeric modifier
|
282
|
+
from += 2
|
283
|
+
adjust = 0
|
284
|
+
|
285
|
+
while from < string.size && string[from] != ')'
|
286
|
+
if CDK.digit?(string[from])
|
287
|
+
adjust = (adjust * 10) + string[from].to_i
|
288
|
+
end
|
289
|
+
from += 1
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
(0...adjust).each do |x|
|
294
|
+
result << (last_char | attrib)
|
295
|
+
used += 1
|
296
|
+
end
|
297
|
+
when '/'
|
298
|
+
mask = []
|
299
|
+
from = encode_attribute(string, from, mask)
|
300
|
+
attrib |= mask[0]
|
301
|
+
when '!'
|
302
|
+
mask = []
|
303
|
+
from = encode_attribute(string, from, mask)
|
304
|
+
attrib &= ~(mask[0])
|
305
|
+
end
|
306
|
+
end
|
307
|
+
from += 1
|
308
|
+
end
|
309
|
+
|
310
|
+
if result.size == 0
|
311
|
+
result << attrib
|
312
|
+
end
|
313
|
+
to[0] = used
|
314
|
+
else
|
315
|
+
result = []
|
316
|
+
end
|
317
|
+
return result
|
318
|
+
end
|
319
|
+
|
320
|
+
# ...
|
321
|
+
#def self.char2Chtype (string, to, align)
|
322
|
+
#end
|
323
|
+
|
324
|
+
def charOf(chtype)
|
325
|
+
(chtype.ord & 255).chr
|
326
|
+
end
|
327
|
+
|
328
|
+
# This returns a string from a chtype array
|
329
|
+
# Formatting codes are omitted.
|
330
|
+
def chtype2Char(string)
|
331
|
+
newstring = ''
|
332
|
+
|
333
|
+
unless string.nil?
|
334
|
+
string.each do |char|
|
335
|
+
newstring << charOf(char)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
return newstring
|
340
|
+
end
|
341
|
+
|
342
|
+
# This returns a string from a chtype array
|
343
|
+
# Formatting codes are embedded
|
344
|
+
def chtype2String(string)
|
345
|
+
newstring = ''
|
346
|
+
unless string.nil?
|
347
|
+
need = 0
|
348
|
+
(0...string.size).each do |x|
|
349
|
+
need = decode_attribute(newstring, need,
|
350
|
+
x > 0 ? string[x - 1] : 0, string[x])
|
351
|
+
newstring << string[x]
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
return newstring
|
356
|
+
end
|
357
|
+
end # module Converters
|
358
|
+
end # module CDK
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module CDK
|
2
|
+
module ExitConditions
|
3
|
+
attr_reader :exit_type
|
4
|
+
|
5
|
+
def init_exit_conditions
|
6
|
+
# set default exit-types
|
7
|
+
@exit_type = :NEVER_ACTIVATED
|
8
|
+
end
|
9
|
+
|
10
|
+
# Set the object's exit-type based on the input.
|
11
|
+
# The .exitType field should have been part of the CDKOBJS struct, but it
|
12
|
+
# is used too pervasively in older applications to move (yet).
|
13
|
+
def setExitType(ch)
|
14
|
+
case ch
|
15
|
+
when CDK::KEY_ESC
|
16
|
+
@exit_type = :ESCAPE_HIT
|
17
|
+
when CDK::KEY_TAB, Ncurses::KEY_ENTER, CDK::KEY_RETURN
|
18
|
+
@exit_type = :NORMAL
|
19
|
+
when Ncurses::ERR
|
20
|
+
@exit_type = :TIMEOUT
|
21
|
+
when 0
|
22
|
+
@exit_type = :EARLY_EXIT
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def resetExitType
|
27
|
+
@exit_type = :NEVER_ACTIVATED
|
28
|
+
end
|
29
|
+
|
30
|
+
end # module ExitConditions
|
31
|
+
end # module CDK
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CDK
|
2
|
+
module Focusable
|
3
|
+
attr_accessor :has_focus
|
4
|
+
attr_accessor :accepts_focus
|
5
|
+
|
6
|
+
def init_focus
|
7
|
+
@has_focus = true
|
8
|
+
@accepts_focus = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def focus
|
12
|
+
end
|
13
|
+
|
14
|
+
def unfocus
|
15
|
+
end
|
16
|
+
end # module Focusable
|
17
|
+
end # module CDK
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CDK
|
2
|
+
module Formattable
|
3
|
+
attr_reader :skip_formatting
|
4
|
+
|
5
|
+
# XXX Make sure to override this to undo any formatting operations
|
6
|
+
def skip_formatting=(b)
|
7
|
+
@skip_formatting_set = true
|
8
|
+
@skip_formatting = b
|
9
|
+
end
|
10
|
+
|
11
|
+
def skip_formatting?
|
12
|
+
@skip_formatting_set ? @skip_formatting : false
|
13
|
+
end
|
14
|
+
end # module CommonControls
|
15
|
+
end # module CDK
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CDK
|
2
|
+
module HasScreen
|
3
|
+
attr_accessor :screen_index,
|
4
|
+
:screen,
|
5
|
+
:is_visible
|
6
|
+
|
7
|
+
def init_screen
|
8
|
+
@is_visible = true
|
9
|
+
end
|
10
|
+
|
11
|
+
def SCREEN_XPOS(n)
|
12
|
+
n + @border_size
|
13
|
+
end
|
14
|
+
|
15
|
+
def SCREEN_YPOS(n)
|
16
|
+
n + @border_size + @title_lines
|
17
|
+
end
|
18
|
+
|
19
|
+
def wrefresh(win=@win)
|
20
|
+
SCREEN.wrefresh(win)
|
21
|
+
end
|
22
|
+
end # module HasScreen
|
23
|
+
end # module CDK
|