slithernix-cdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +131 -0
- data/README.md +45 -0
- data/lib/cdk/alphalist.rb +561 -0
- data/lib/cdk/buttonbox.rb +355 -0
- data/lib/cdk/calendar.rb +770 -0
- data/lib/cdk/cdk_objs.rb +463 -0
- data/lib/cdk/dialog.rb +727 -0
- data/lib/cdk/display.rb +63 -0
- data/lib/cdk/draw.rb +233 -0
- data/lib/cdk/dscale.rb +13 -0
- data/lib/cdk/entry.rb +556 -0
- data/lib/cdk/fscale.rb +44 -0
- data/lib/cdk/fselect.rb +940 -0
- data/lib/cdk/fslider.rb +61 -0
- data/lib/cdk/histogram.rb +410 -0
- data/lib/cdk/itemlist.rb +475 -0
- data/lib/cdk/label.rb +207 -0
- data/lib/cdk/marquee.rb +241 -0
- data/lib/cdk/matrix.rb +1176 -0
- data/lib/cdk/mentry.rb +616 -0
- data/lib/cdk/menu.rb +448 -0
- data/lib/cdk/radio.rb +533 -0
- data/lib/cdk/scale.rb +529 -0
- data/lib/cdk/screen.rb +281 -0
- data/lib/cdk/scroll.rb +996 -0
- data/lib/cdk/scroller.rb +183 -0
- data/lib/cdk/selection.rb +619 -0
- data/lib/cdk/slider.rb +542 -0
- data/lib/cdk/swindow.rb +762 -0
- data/lib/cdk/template.rb +562 -0
- data/lib/cdk/traverse.rb +289 -0
- data/lib/cdk/uscale.rb +14 -0
- data/lib/cdk/uslider.rb +14 -0
- data/lib/cdk/viewer.rb +812 -0
- data/lib/cdk.rb +1015 -0
- metadata +149 -0
data/lib/cdk/display.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module CDK
|
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
|
+
# Tell if a display type is "hidden"
|
32
|
+
def Display.isHiddenDisplayType(type)
|
33
|
+
case type
|
34
|
+
when :HCHAR, :HINT, :HMIXED, :LHCHAR, :LHMIXED, :UHCHAR, :UHMIXED
|
35
|
+
true
|
36
|
+
when :CHAR, :INT, :INVALID, :LCHAR, :LMIXED, :MIXED, :UCHAR,
|
37
|
+
:UMIXED, :VIEWONLY
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Given a character input, check if it is allowed by the display type
|
43
|
+
# and return the character to apply to the display, or ERR if not
|
44
|
+
def Display.filterByDisplayType(type, input)
|
45
|
+
result = input
|
46
|
+
if !CDK.isChar(input)
|
47
|
+
result = Curses::Error
|
48
|
+
elsif [:INT, :HINT].include?(type) && !CDK.digit?(result.chr)
|
49
|
+
result = Curses::Error
|
50
|
+
elsif [:CHAR, :UCHAR, :LCHAR, :UHCHAR, :LHCHAR].include?(type) && CDK.digit?(result.chr)
|
51
|
+
result = Curses::Error
|
52
|
+
elsif type == :VIEWONLY
|
53
|
+
result = ERR
|
54
|
+
elsif [:UCHAR, :UHCHAR, :UMIXED, :UHMIXED].include?(type) && CDK.alpha?(result.chr)
|
55
|
+
result = result.chr.upcase.ord
|
56
|
+
elsif [:LCHAR, :LHCHAR, :LMIXED, :LHMIXED].include?(type) && CDK.alpha?(result.chr)
|
57
|
+
result = result.chr.downcase.ord
|
58
|
+
end
|
59
|
+
|
60
|
+
return result
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/cdk/draw.rb
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
module CDK
|
2
|
+
module Draw
|
3
|
+
# This sets up a basic set of color pairs. These can be redefined if wanted
|
4
|
+
def Draw.initCDKColor
|
5
|
+
color = [Curses::COLOR_WHITE, Curses::COLOR_RED, Curses::COLOR_GREEN,
|
6
|
+
Curses::COLOR_YELLOW, Curses::COLOR_BLUE, Curses::COLOR_MAGENTA,
|
7
|
+
Curses::COLOR_CYAN, Curses::COLOR_BLACK]
|
8
|
+
pair = 1
|
9
|
+
|
10
|
+
if Curses.has_colors?
|
11
|
+
# XXX: Only checks if terminal has colours not if colours are started
|
12
|
+
Curses.start_color
|
13
|
+
limit = Curses.colors < 8 ? Curses.colors : 8
|
14
|
+
|
15
|
+
# Create the color pairs
|
16
|
+
(0...limit).each do |fg|
|
17
|
+
(0...limit).each do |bg|
|
18
|
+
Curses.init_pair(pair, color[fg], color[bg])
|
19
|
+
pair += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# This prints out a box around a window with attributes
|
26
|
+
def Draw.boxWindow(window, attr)
|
27
|
+
tlx = 0
|
28
|
+
tly = 0
|
29
|
+
brx = window.maxx - 1
|
30
|
+
bry = window.maxy - 1
|
31
|
+
|
32
|
+
# Draw horizontal lines.
|
33
|
+
window.mvwhline(tly, 0, CDK::ACS_HLINE | attr, window.maxx)
|
34
|
+
window.mvwhline(bry, 0, CDK::ACS_HLINE | attr, window.maxx)
|
35
|
+
|
36
|
+
# Draw horizontal lines.
|
37
|
+
window.mvwvline(0, tlx, CDK::ACS_VLINE | attr, window.maxy)
|
38
|
+
window.mvwvline(0, brx, CDK::ACS_VLINE | attr, window.maxy)
|
39
|
+
|
40
|
+
# Draw in the corners.
|
41
|
+
window.mvwaddch(tly, tlx, CDK::ACS_ULCORNER | attr)
|
42
|
+
window.mvwaddch(tly, brx, CDK::ACS_URCORNER | attr)
|
43
|
+
window.mvwaddch(bry, tlx, CDK::ACS_LLCORNER | attr)
|
44
|
+
window.mvwaddch(bry, brx, CDK::ACS_LRCORNER | attr)
|
45
|
+
window.refresh
|
46
|
+
end
|
47
|
+
|
48
|
+
# This draws a box with attributes and lets the user define each
|
49
|
+
# element of the box
|
50
|
+
def Draw.attrbox(win, tlc, trc, blc, brc, horz, vert, attr)
|
51
|
+
x1 = 0
|
52
|
+
y1 = 0
|
53
|
+
y2 = win.maxy - 1
|
54
|
+
x2 = win.maxx - 1
|
55
|
+
count = 0
|
56
|
+
|
57
|
+
# Draw horizontal lines
|
58
|
+
if horz != 0
|
59
|
+
win.mvwhline(y1, 0, horz | attr, win.maxx)
|
60
|
+
win.mvwhline(y2, 0, horz | attr, win.maxx)
|
61
|
+
count += 1
|
62
|
+
end
|
63
|
+
|
64
|
+
# Draw vertical lines
|
65
|
+
if vert != 0
|
66
|
+
win.mvwvline(0, x1, vert | attr, win.maxy)
|
67
|
+
win.mvwvline(0, x2, vert | attr, win.maxy)
|
68
|
+
count += 1
|
69
|
+
end
|
70
|
+
|
71
|
+
# Draw in the corners.
|
72
|
+
if tlc != 0
|
73
|
+
win.mvwaddch(y1, x1, tlc | attr)
|
74
|
+
count += 1
|
75
|
+
end
|
76
|
+
if trc != 0
|
77
|
+
win.mvwaddch(y1, x2, trc | attr)
|
78
|
+
count += 1
|
79
|
+
end
|
80
|
+
if blc != 0
|
81
|
+
win.mvwaddch(y2, x1, blc | attr)
|
82
|
+
count += 1
|
83
|
+
end
|
84
|
+
if brc != 0
|
85
|
+
win.mvwaddch(y2, x2, brc | attr)
|
86
|
+
count += 1
|
87
|
+
end
|
88
|
+
if count != 0
|
89
|
+
win.refresh
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Draw a box around the given window using the object's defined
|
94
|
+
# line-drawing characters
|
95
|
+
def Draw.drawObjBox(win, object)
|
96
|
+
Draw.attrbox(win,
|
97
|
+
object.ULChar, object.URChar, object.LLChar, object.LRChar,
|
98
|
+
object.HZChar, object.VTChar, object.BXAttr)
|
99
|
+
end
|
100
|
+
|
101
|
+
# This draws a line on the given window. (odd angle lines not working yet)
|
102
|
+
def Draw.drawLine(window, startx, starty, endx, endy, line)
|
103
|
+
xdiff = endx - startx
|
104
|
+
ydiff = endy - starty
|
105
|
+
x = 0
|
106
|
+
y = 0
|
107
|
+
|
108
|
+
# Determine if we're drawing a horizontal or vertical line.
|
109
|
+
if ydiff == 0
|
110
|
+
if xdiff > 0
|
111
|
+
window.mvwhline(starty, startx, line, xdiff)
|
112
|
+
end
|
113
|
+
elsif xdiff == 0
|
114
|
+
if ydiff > 0
|
115
|
+
window.mvwvline(starty, startx, line, ydiff)
|
116
|
+
end
|
117
|
+
else
|
118
|
+
# We need to determine the angle of the line.
|
119
|
+
height = xdiff
|
120
|
+
width = ydiff
|
121
|
+
xratio = if height > width then 1 else width / height end
|
122
|
+
yration = if width > height then width / height else 1 end
|
123
|
+
xadj = 0
|
124
|
+
yadj = 0
|
125
|
+
|
126
|
+
# Set the vars
|
127
|
+
x = startx
|
128
|
+
y = starty
|
129
|
+
while x!= endx && y != endy
|
130
|
+
# Add the char to the window
|
131
|
+
window.mvwaddch(y, x, line)
|
132
|
+
|
133
|
+
# Make the x and y adjustments.
|
134
|
+
if xadj != xratio
|
135
|
+
x = if xdiff < 0 then x - 1 else x + 1 end
|
136
|
+
xadj += 1
|
137
|
+
else
|
138
|
+
xadj = 0
|
139
|
+
end
|
140
|
+
if yadj != yratio
|
141
|
+
y = if ydiff < 0 then y - 1 else y + 1 end
|
142
|
+
yadj += 1
|
143
|
+
else
|
144
|
+
yadj = 0
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# This draws a shadow around a window.
|
151
|
+
def Draw.drawShadow(shadow_win)
|
152
|
+
unless shadow_win.nil?
|
153
|
+
x_hi = shadow_win.maxx - 1
|
154
|
+
y_hi = shadow_win.maxy - 1
|
155
|
+
|
156
|
+
# Draw the line on the bottom.
|
157
|
+
shadow_win.mvwhline(y_hi, 1, CDK::ACS_HLINE | Curses::A_DIM, x_hi)
|
158
|
+
|
159
|
+
# Draw the line on the right.
|
160
|
+
shadow_win.mvwvline(0, x_hi, CDK::ACS_VLINE | Curses::A_DIM, y_hi)
|
161
|
+
|
162
|
+
shadow_win.mvwaddch(0, x_hi, CDK::ACS_URCORNER | Curses::A_DIM)
|
163
|
+
shadow_win.mvwaddch(y_hi, 0, CDK::ACS_LLCORNER | Curses::A_DIM)
|
164
|
+
shadow_win.mvwaddch(y_hi, x_hi, CDK::ACS_LRCORNER | Curses::A_DIM)
|
165
|
+
shadow_win.refresh
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Write a string of blanks using writeChar()
|
170
|
+
def Draw.writeBlanks(window, xpos, ypos, align, start, endn)
|
171
|
+
if start < endn
|
172
|
+
want = (endn - start) + 1000
|
173
|
+
blanks = ''
|
174
|
+
|
175
|
+
CDK.cleanChar(blanks, want - 1, ' ')
|
176
|
+
Draw.writeChar(window, xpos, ypos, blanks, align, start, endn)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# This writes out a char string with no attributes
|
181
|
+
def Draw.writeChar(window, xpos, ypos, string, align, start, endn)
|
182
|
+
Draw.writeCharAttrib(window, xpos, ypos, string, Curses::A_NORMAL,
|
183
|
+
align, start, endn)
|
184
|
+
end
|
185
|
+
|
186
|
+
# This writes out a char string with attributes
|
187
|
+
def Draw.writeCharAttrib(window, xpos, ypos, string, attr, align,
|
188
|
+
start, endn)
|
189
|
+
display = endn - start
|
190
|
+
|
191
|
+
if align == CDK::HORIZONTAL
|
192
|
+
# Draw the message on a horizontal axis
|
193
|
+
display = [display, window.maxx - 1].min
|
194
|
+
(0...display).each do |x|
|
195
|
+
window.mvwaddch(ypos, xpos + x, string[x + start].ord | attr)
|
196
|
+
end
|
197
|
+
else
|
198
|
+
# Draw the message on a vertical axis
|
199
|
+
display = [display, window.maxy - 1].min
|
200
|
+
(0...display).each do |x|
|
201
|
+
window.mvwaddch(ypos + x, xpos, string[x + start].ord | attr)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# This writes out a chtype string
|
207
|
+
def Draw.writeChtype (window, xpos, ypos, string, align, start, endn)
|
208
|
+
Draw.writeChtypeAttrib(window, xpos, ypos, string, Curses::A_NORMAL,
|
209
|
+
align, start, endn)
|
210
|
+
end
|
211
|
+
|
212
|
+
# This writes out a chtype string with the given attributes added.
|
213
|
+
def Draw.writeChtypeAttrib(window, xpos, ypos, string, attr,
|
214
|
+
align, start, endn)
|
215
|
+
diff = endn - start
|
216
|
+
display = 0
|
217
|
+
x = 0
|
218
|
+
if align == CDK::HORIZONTAL
|
219
|
+
# Draw the message on a horizontal axis.
|
220
|
+
display = [diff, window.maxx - xpos].min
|
221
|
+
(0...display).each do |x|
|
222
|
+
window.mvwaddch(ypos, xpos + x, string[x + start].ord | attr)
|
223
|
+
end
|
224
|
+
else
|
225
|
+
# Draw the message on a vertical axis.
|
226
|
+
display = [diff, window.maxy - ypos].min
|
227
|
+
(0...display).each do |x|
|
228
|
+
window.mvwaddch(ypos + x, xpos, string[x + start].ord | attr)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
data/lib/cdk/dscale.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'fscale'
|
2
|
+
|
3
|
+
module CDK
|
4
|
+
class DSCALE < CDK::FSCALE
|
5
|
+
# The original DScale handled unsigned values.
|
6
|
+
# Since Ruby's typing is different this is really just FSCALE
|
7
|
+
# but is nice it's nice to have this for compatibility/completeness
|
8
|
+
# sake.
|
9
|
+
def object_type
|
10
|
+
:DSCALE
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|