cdk 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,54 @@
|
|
1
|
+
module CDK
|
2
|
+
VERSION_MAJOR = 0
|
3
|
+
VERSION_MINOR = 10
|
4
|
+
VERSION_PATCH = 0
|
5
|
+
|
6
|
+
CDK_PATHMAX = 256
|
7
|
+
|
8
|
+
L_MARKER = '<'
|
9
|
+
R_MARKER = '>'
|
10
|
+
|
11
|
+
LEFT = 9000
|
12
|
+
RIGHT = 9001
|
13
|
+
CENTER = 9002
|
14
|
+
TOP = 9003
|
15
|
+
BOTTOM = 9004
|
16
|
+
HORIZONTAL = 9005
|
17
|
+
VERTICAL = 9006
|
18
|
+
FULL = 9007
|
19
|
+
|
20
|
+
NONE = 0
|
21
|
+
ROW = 1
|
22
|
+
COL = 2
|
23
|
+
|
24
|
+
MAX_BINDINGS = 300
|
25
|
+
MAX_ITEMS = 2000
|
26
|
+
MAX_BUTTONS = 200
|
27
|
+
|
28
|
+
def self.CTRL(c)
|
29
|
+
c.ord & 0x1f
|
30
|
+
end
|
31
|
+
|
32
|
+
REFRESH = CTRL('L')
|
33
|
+
PASTE = CTRL('V')
|
34
|
+
COPY = CTRL('Y')
|
35
|
+
ERASE = CTRL('U')
|
36
|
+
CUT = CTRL('X')
|
37
|
+
BEGOFLINE = CTRL('A')
|
38
|
+
ENDOFLINE = CTRL('E')
|
39
|
+
BACKCHAR = CTRL('B')
|
40
|
+
FORCHAR = CTRL('F')
|
41
|
+
TRANSPOSE = CTRL('T')
|
42
|
+
NEXT = CTRL('N')
|
43
|
+
PREV = CTRL('P')
|
44
|
+
DELETE = "\177".ord
|
45
|
+
KEY_ESC = "\033".ord
|
46
|
+
KEY_RETURN = "\012".ord
|
47
|
+
KEY_TAB = "\t".ord
|
48
|
+
|
49
|
+
def self.Version
|
50
|
+
return "%d.%d.%d" % [CDK::VERSION_MAJOR,
|
51
|
+
CDK::VERSION_MINOR,
|
52
|
+
CDK::VERSION_PATCH]
|
53
|
+
end
|
54
|
+
end # module CDK
|
data/lib/cdk/display.rb
CHANGED
@@ -1,40 +1,26 @@
|
|
1
1
|
module CDK
|
2
2
|
module Display
|
3
|
-
# Given a string, returns the equivalent display type
|
4
|
-
def Display.char2DisplayType(string)
|
5
|
-
table = {
|
6
|
-
"CHAR" => :CHAR,
|
7
|
-
"HCHAR" => :HCHAR,
|
8
|
-
"INT" => :INT,
|
9
|
-
"HINT" => :HINT,
|
10
|
-
"UCHAR" => :UCHAR,
|
11
|
-
"LCHAR" => :LCHAR,
|
12
|
-
"UHCHAR" => :UHCHAR,
|
13
|
-
"LHCHAR" => :LHCHAR,
|
14
|
-
"MIXED" => :MIXED,
|
15
|
-
"HMIXED" => :HMIXED,
|
16
|
-
"UMIXED" => :UMIXED,
|
17
|
-
"LMIXED" => :LMIXED,
|
18
|
-
"UHMIXED" => :UHMIXED,
|
19
|
-
"LHMIXED" => :LHMIXED,
|
20
|
-
"VIEWONLY" => :VIEWONLY,
|
21
|
-
0 => :INVALID
|
22
|
-
}
|
23
|
-
|
24
|
-
if table.include?(string)
|
25
|
-
table[string]
|
26
|
-
else
|
27
|
-
:INVALID
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
3
|
# Tell if a display type is "hidden"
|
32
4
|
def Display.isHiddenDisplayType(type)
|
33
5
|
case type
|
34
|
-
when :HCHAR,
|
6
|
+
when :HCHAR,
|
7
|
+
:HINT,
|
8
|
+
:HMIXED,
|
9
|
+
:LHCHAR,
|
10
|
+
:LHMIXED,
|
11
|
+
:UHCHAR,
|
12
|
+
:UHMIXED
|
35
13
|
true
|
36
|
-
|
37
|
-
|
14
|
+
|
15
|
+
when :CHAR,
|
16
|
+
:INT,
|
17
|
+
:INVALID,
|
18
|
+
:LCHAR,
|
19
|
+
:LMIXED,
|
20
|
+
:MIXED,
|
21
|
+
:UCHAR,
|
22
|
+
:UMIXED,
|
23
|
+
:VIEWONLY
|
38
24
|
false
|
39
25
|
end
|
40
26
|
end
|
@@ -45,15 +31,24 @@ module CDK
|
|
45
31
|
result = input
|
46
32
|
if !CDK.isChar(input)
|
47
33
|
result = Ncurses::ERR
|
48
|
-
|
34
|
+
|
35
|
+
elsif [:INT, :HINT].include?(type) &&
|
36
|
+
!CDK.digit?(result.chr)
|
49
37
|
result = Ncurses::ERR
|
50
|
-
|
38
|
+
|
39
|
+
elsif [:CHAR, :UCHAR, :LCHAR, :UHCHAR, :LHCHAR].include?(type) &&
|
40
|
+
CDK.digit?(result.chr)
|
51
41
|
result = Ncurses::ERR
|
42
|
+
|
52
43
|
elsif type == :VIEWONLY
|
53
44
|
result = ERR
|
54
|
-
|
45
|
+
|
46
|
+
elsif [:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include?(type) &&
|
47
|
+
CDK.alpha?(result.chr)
|
55
48
|
result = result.chr.upcase.ord
|
56
|
-
|
49
|
+
|
50
|
+
elsif [:LCHAR, :LHCHAR, :LMIXED, :LHMIXED].include?(type) &&
|
51
|
+
CDK.alpha?(result.chr)
|
57
52
|
result = result.chr.downcase.ord
|
58
53
|
end
|
59
54
|
|
data/lib/cdk/draw.rb
CHANGED
@@ -42,7 +42,7 @@ module CDK
|
|
42
42
|
window.mvwaddch(tly, brx, Ncurses::ACS_URCORNER | attr)
|
43
43
|
window.mvwaddch(bry, tlx, Ncurses::ACS_LLCORNER | attr)
|
44
44
|
window.mvwaddch(bry, brx, Ncurses::ACS_LRCORNER | attr)
|
45
|
-
|
45
|
+
SCREEN.wrefresh(window)
|
46
46
|
end
|
47
47
|
|
48
48
|
# This draws a box with attributes and lets the user define each
|
@@ -86,7 +86,7 @@ module CDK
|
|
86
86
|
count += 1
|
87
87
|
end
|
88
88
|
if count != 0
|
89
|
-
|
89
|
+
SCREEN.wrefresh(win)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -162,7 +162,7 @@ module CDK
|
|
162
162
|
shadow_win.mvwaddch(0, x_hi, Ncurses::ACS_URCORNER | Ncurses::A_DIM)
|
163
163
|
shadow_win.mvwaddch(y_hi, 0, Ncurses::ACS_LLCORNER | Ncurses::A_DIM)
|
164
164
|
shadow_win.mvwaddch(y_hi, x_hi, Ncurses::ACS_LRCORNER | Ncurses::A_DIM)
|
165
|
-
|
165
|
+
SCREEN.wrefresh(shadow_win)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -170,9 +170,7 @@ module CDK
|
|
170
170
|
def Draw.writeBlanks(window, xpos, ypos, align, start, endn)
|
171
171
|
if start < endn
|
172
172
|
want = (endn - start) + 1000
|
173
|
-
blanks = ''
|
174
|
-
|
175
|
-
CDK.cleanChar(blanks, want - 1, ' ')
|
173
|
+
blanks = ' ' * (want - 1)
|
176
174
|
Draw.writeChar(window, xpos, ypos, blanks, align, start, endn)
|
177
175
|
end
|
178
176
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module CDK
|
2
|
+
# This reads a file and sticks it into the list provided.
|
3
|
+
def self.readFile(filename, array)
|
4
|
+
begin
|
5
|
+
fd = File.new(filename, "r")
|
6
|
+
rescue
|
7
|
+
return -1
|
8
|
+
end
|
9
|
+
|
10
|
+
lines = fd.readlines.map do |line|
|
11
|
+
if line.size > 0 && line[-1] == "\n"
|
12
|
+
line[0...-1]
|
13
|
+
else
|
14
|
+
line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
array.concat(lines)
|
18
|
+
fd.close
|
19
|
+
array.size
|
20
|
+
end
|
21
|
+
|
22
|
+
# This opens the current directory and reads the contents.
|
23
|
+
def self.getDirectoryContents(directory, list)
|
24
|
+
counter = 0
|
25
|
+
|
26
|
+
# Open the directory.
|
27
|
+
Dir.foreach(directory) do |filename|
|
28
|
+
next if filename == '.'
|
29
|
+
list << filename
|
30
|
+
end
|
31
|
+
|
32
|
+
list.sort!
|
33
|
+
return list.size
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the directory for the given pathname, i.e. the part before the
|
37
|
+
# last slash
|
38
|
+
# For now this function is just a wrapper for File.dirname kept for ease of
|
39
|
+
# porting and will be completely replaced in the future
|
40
|
+
def self.dirName (pathname)
|
41
|
+
File.dirname(pathname)
|
42
|
+
end
|
43
|
+
end # module CDK
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module CDK
|
2
|
+
# This safely erases a given window
|
3
|
+
def self.eraseCursesWindow (window)
|
4
|
+
return if window.nil?
|
5
|
+
|
6
|
+
window.werase
|
7
|
+
SCREEN.wrefresh(window)
|
8
|
+
end
|
9
|
+
|
10
|
+
# This safely deletes a given window.
|
11
|
+
def self.deleteCursesWindow (window)
|
12
|
+
return if window.nil?
|
13
|
+
|
14
|
+
eraseCursesWindow(window)
|
15
|
+
window.delwin
|
16
|
+
end
|
17
|
+
|
18
|
+
# This moves a given window (if we're able to set the window's beginning).
|
19
|
+
# We do not use mvwin(), because it does not (usually) move subwindows.
|
20
|
+
def self.moveCursesWindow (window, xdiff, ydiff)
|
21
|
+
return if window.nil?
|
22
|
+
|
23
|
+
xpos = []
|
24
|
+
ypos = []
|
25
|
+
window.getbegyx(ypos, xpos)
|
26
|
+
if window.mvwin(ypos[0], xpos[0]) != Ncurses::ERR
|
27
|
+
xpos[0] += xdiff
|
28
|
+
ypos[0] += ydiff
|
29
|
+
window.werase
|
30
|
+
window.mvwin(ypos[0], xpos[0])
|
31
|
+
else
|
32
|
+
CDK.Beep
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# If the dimension is a negative value, the dimension will be the full
|
37
|
+
# height/width of the parent window - the value of the dimension. Otherwise,
|
38
|
+
# the dimension will be the given value.
|
39
|
+
def self.setWidgetDimension (parent_dim, proposed_dim, adjustment)
|
40
|
+
# If the user passed in FULL, return the parents size
|
41
|
+
if proposed_dim == FULL or proposed_dim == 0
|
42
|
+
parent_dim
|
43
|
+
|
44
|
+
elsif proposed_dim >= 0
|
45
|
+
# if they gave a positive value, return it
|
46
|
+
|
47
|
+
if proposed_dim >= parent_dim
|
48
|
+
parent_dim
|
49
|
+
else
|
50
|
+
proposed_dim + adjustment
|
51
|
+
end
|
52
|
+
|
53
|
+
else
|
54
|
+
# if they gave a negative value then return the dimension
|
55
|
+
# of the parent plus the value given
|
56
|
+
#
|
57
|
+
if parent_dim + proposed_dim < 0
|
58
|
+
parent_dim
|
59
|
+
else
|
60
|
+
parent_dim + proposed_dim
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end # module CDK
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module CDK
|
2
|
+
module Alignments
|
3
|
+
# This takes an x and y position and realigns the values iff they sent in
|
4
|
+
# values like CENTER, LEFT, RIGHT
|
5
|
+
#
|
6
|
+
# window is an Ncurses::WINDOW object
|
7
|
+
# xpos, ypos is an array with exactly one value, an integer
|
8
|
+
# box_width, box_height is an integer
|
9
|
+
def alignxy (window, xpos, ypos, box_width, box_height)
|
10
|
+
first = window.getbegx
|
11
|
+
last = window.getmaxx
|
12
|
+
if (gap = (last - box_width)) < 0
|
13
|
+
gap = 0
|
14
|
+
end
|
15
|
+
last = first + gap
|
16
|
+
|
17
|
+
case xpos[0]
|
18
|
+
when LEFT
|
19
|
+
xpos[0] = first
|
20
|
+
when RIGHT
|
21
|
+
xpos[0] = first + gap
|
22
|
+
when CENTER
|
23
|
+
xpos[0] = first + (gap / 2)
|
24
|
+
else
|
25
|
+
if xpos[0] > last
|
26
|
+
xpos[0] = last
|
27
|
+
elsif xpos[0] < first
|
28
|
+
xpos[0] = first
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
first = window.getbegy
|
33
|
+
last = window.getmaxy
|
34
|
+
if (gap = (last - box_height)) < 0
|
35
|
+
gap = 0
|
36
|
+
end
|
37
|
+
last = first + gap
|
38
|
+
|
39
|
+
case ypos[0]
|
40
|
+
when TOP
|
41
|
+
ypos[0] = first
|
42
|
+
when BOTTOM
|
43
|
+
ypos[0] = first + gap
|
44
|
+
when CENTER
|
45
|
+
ypos[0] = first + (gap / 2)
|
46
|
+
else
|
47
|
+
if ypos[0] > last
|
48
|
+
ypos[0] = last
|
49
|
+
elsif ypos[0] < first
|
50
|
+
ypos[0] = first
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end # module Alignments
|
55
|
+
end # module CDK
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module CDK
|
2
|
+
module Bindings
|
3
|
+
attr_reader :binding_list
|
4
|
+
|
5
|
+
def init_bindings
|
6
|
+
# Bound functions
|
7
|
+
@binding_list = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def bindableObject(cdktype)
|
11
|
+
if cdktype != self.object_type
|
12
|
+
return nil
|
13
|
+
elsif [:FSELECT, :ALPHALIST].include?(self.object_type)
|
14
|
+
return @entry_field
|
15
|
+
else
|
16
|
+
return self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def bind(type, key, function, data)
|
21
|
+
obj = self.bindableObject(type)
|
22
|
+
if key.ord < Ncurses::KEY_MAX && !(obj.nil?)
|
23
|
+
if key.ord != 0
|
24
|
+
obj.binding_list[key.ord] = [function, data]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def unbind(type, key)
|
30
|
+
obj = self.bindableObject(type)
|
31
|
+
unless obj.nil?
|
32
|
+
obj.binding_list.delete(key)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def cleanBindings(type)
|
37
|
+
obj = self.bindableObject(type)
|
38
|
+
if !(obj.nil?) && !(obj.binding_list.nil?)
|
39
|
+
obj.binding_list.clear
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# This checks to see if the binding for the key exists:
|
44
|
+
# If it does then it runs the command and returns its value, normally true
|
45
|
+
# If it doesn't it returns a false. This way we can 'overwrite' coded
|
46
|
+
# bindings.
|
47
|
+
def checkBind(type, key)
|
48
|
+
obj = self.bindableObject(type)
|
49
|
+
if !(obj.nil?) && obj.binding_list.include?(key)
|
50
|
+
function = obj.binding_list[key][0]
|
51
|
+
data = obj.binding_list[key][1]
|
52
|
+
|
53
|
+
if function == :getc
|
54
|
+
return data
|
55
|
+
else
|
56
|
+
return function.call(type, obj, data, key)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
|
62
|
+
# This checks to see if the binding for the key exists.
|
63
|
+
def isBind(type, key)
|
64
|
+
result = false
|
65
|
+
obj = self.bindableObject(type)
|
66
|
+
unless obj.nil?
|
67
|
+
result = obj.binding_list.include?(key)
|
68
|
+
end
|
69
|
+
|
70
|
+
return result
|
71
|
+
end
|
72
|
+
end # module Bindings
|
73
|
+
end # module CDK
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module CDK
|
2
|
+
module Borders
|
3
|
+
attr_accessor :box
|
4
|
+
attr_accessor :ULChar, :URChar, :LLChar, :LRChar, :HZChar, :VTChar, :BXAttr
|
5
|
+
attr_reader :border_size
|
6
|
+
|
7
|
+
def init_borders
|
8
|
+
# set default line-drawing characters
|
9
|
+
@ULChar = Ncurses::ACS_ULCORNER
|
10
|
+
@URChar = Ncurses::ACS_URCORNER
|
11
|
+
@LLChar = Ncurses::ACS_LLCORNER
|
12
|
+
@LRChar = Ncurses::ACS_LRCORNER
|
13
|
+
@HZChar = Ncurses::ACS_HLINE
|
14
|
+
@VTChar = Ncurses::ACS_VLINE
|
15
|
+
@BXAttr = Ncurses::A_NORMAL
|
16
|
+
end
|
17
|
+
|
18
|
+
def setBox(box)
|
19
|
+
@box = box
|
20
|
+
@border_size = if @box then 1 else 0 end
|
21
|
+
end
|
22
|
+
|
23
|
+
def getBox
|
24
|
+
return @box
|
25
|
+
end
|
26
|
+
|
27
|
+
# Set the object's upper-left-corner line-drawing character.
|
28
|
+
def setULchar(ch)
|
29
|
+
@ULChar = ch
|
30
|
+
end
|
31
|
+
|
32
|
+
# Set the object's upper-right-corner line-drawing character.
|
33
|
+
def setURchar(ch)
|
34
|
+
@URChar = ch
|
35
|
+
end
|
36
|
+
|
37
|
+
# Set the object's lower-left-corner line-drawing character.
|
38
|
+
def setLLchar(ch)
|
39
|
+
@LLChar = ch
|
40
|
+
end
|
41
|
+
|
42
|
+
# Set the object's upper-right-corner line-drawing character.
|
43
|
+
def setLRchar(ch)
|
44
|
+
@LRChar = ch
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set the object's horizontal line-drawing character
|
48
|
+
def setHZchar(ch)
|
49
|
+
@HZChar = ch
|
50
|
+
end
|
51
|
+
|
52
|
+
# Set the object's vertical line-drawing character
|
53
|
+
def setVTchar(ch)
|
54
|
+
@VTChar = ch
|
55
|
+
end
|
56
|
+
|
57
|
+
# Set the object's box-attributes.
|
58
|
+
def setBXattr(ch)
|
59
|
+
@BXAttr = ch
|
60
|
+
end
|
61
|
+
end # module Borders
|
62
|
+
end # module CDK
|