rndk 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/demos/appointment.rb +40 -25
- data/demos/clock.rb +22 -11
- data/demos/fileview.rb +141 -0
- data/examples/01-hello-world.rb +1 -2
- data/examples/02-colors.rb +58 -0
- data/examples/03-markup.rb +70 -0
- data/examples/04-quick-widgets.rb +72 -0
- data/examples/05-position-widget.rb +3 -6
- data/examples/calendar.rb +104 -0
- data/examples/scroll.rb +106 -0
- data/lib/rndk/alphalist.rb +14 -14
- data/lib/rndk/button.rb +21 -21
- data/lib/rndk/buttonbox.rb +18 -18
- data/lib/rndk/calendar.rb +333 -240
- data/lib/rndk/core/color.rb +136 -0
- data/lib/rndk/core/display.rb +23 -12
- data/lib/rndk/core/draw.rb +32 -26
- data/lib/rndk/core/markup.rb +561 -0
- data/lib/rndk/core/quick_widgets.rb +232 -12
- data/lib/rndk/core/screen.rb +16 -17
- data/lib/rndk/core/utils.rb +143 -0
- data/lib/rndk/core/widget.rb +133 -92
- data/lib/rndk/dialog.rb +17 -17
- data/lib/rndk/entry.rb +21 -21
- data/lib/rndk/fselect.rb +16 -16
- data/lib/rndk/graph.rb +10 -10
- data/lib/rndk/histogram.rb +10 -10
- data/lib/rndk/itemlist.rb +20 -20
- data/lib/rndk/label.rb +66 -45
- data/lib/rndk/marquee.rb +10 -10
- data/lib/rndk/matrix.rb +27 -27
- data/lib/rndk/mentry.rb +22 -22
- data/lib/rndk/menu.rb +14 -14
- data/lib/rndk/radio.rb +19 -19
- data/lib/rndk/scale.rb +21 -21
- data/lib/rndk/scroll.rb +19 -19
- data/lib/rndk/scroller.rb +2 -0
- data/lib/rndk/selection.rb +20 -20
- data/lib/rndk/slider.rb +21 -21
- data/lib/rndk/swindow.rb +20 -20
- data/lib/rndk/template.rb +21 -21
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +18 -18
- data/lib/rndk.rb +99 -777
- data/rndk.gemspec +1 -1
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8f9ad279e8103fa755fa296a6ce77f841d44447
|
4
|
+
data.tar.gz: 645cac649bc64fc804541c71868800aa28b172e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e6a0f5bdda584d982e13ecb89643c09f0acc07061c9de05912ecdaff70abf22163d87eba05fd4405d5fbff2672e75188cf07d37a7a22d121a65386612f5a12
|
7
|
+
data.tar.gz: 6ab7a46f6aa062a58d3b79a7620665eae38e1b0f6bfbeff64eaa4fd31a78d5dd700b5c9845789b12fda15c7ca77a27e8e8a2976338e1ebf1ee6f3d319b46f457
|
data/demos/appointment.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
+
# Note: This is not for beginners! Check out the examples/
|
4
|
+
# before adventuring into the demos/ realm!
|
5
|
+
#
|
3
6
|
# Shows a book where you can create appointments of different
|
4
7
|
# kinds, save and restore them on a file.
|
5
8
|
#
|
@@ -40,8 +43,8 @@ class Appointment
|
|
40
43
|
lines = []
|
41
44
|
|
42
45
|
# Read the appointment file.
|
43
|
-
lines_read = RNDK.
|
44
|
-
if lines_read ==
|
46
|
+
lines_read = RNDK.read_file(filename, lines)
|
47
|
+
if lines_read == nil
|
45
48
|
app_info.count = 0
|
46
49
|
return
|
47
50
|
end
|
@@ -114,14 +117,13 @@ class Appointment
|
|
114
117
|
readAppointmentFile(filename, appointment_info)
|
115
118
|
|
116
119
|
# Set up RNDK
|
117
|
-
|
118
|
-
rndkscreen = RNDK::Screen.new(curses_win)
|
120
|
+
rndkscreen = RNDK::Screen.new
|
119
121
|
|
120
122
|
# Set up RNDK colors
|
121
|
-
RNDK::
|
123
|
+
RNDK::Color.init
|
122
124
|
|
123
125
|
# Create the calendar widget.
|
124
|
-
calendar = RNDK::
|
126
|
+
calendar = RNDK::Calendar.new(rndkscreen,
|
125
127
|
RNDK::CENTER,
|
126
128
|
RNDK::CENTER,
|
127
129
|
title, day, month, year,
|
@@ -130,7 +132,6 @@ class Appointment
|
|
130
132
|
|
131
133
|
# Is the widget nil?
|
132
134
|
if calendar.nil?
|
133
|
-
rndkscreen.destroy
|
134
135
|
RNDK::Screen.end_rndk
|
135
136
|
|
136
137
|
puts "Cannot create the calendar. Is the window too small?"
|
@@ -148,8 +149,15 @@ class Appointment
|
|
148
149
|
|
149
150
|
# Create the itemlist widget.
|
150
151
|
itemlist = RNDK::ITEMLIST.new(calendar.screen,
|
151
|
-
|
152
|
-
|
152
|
+
RNDK::CENTER,
|
153
|
+
RNDK::CENTER,
|
154
|
+
'',
|
155
|
+
'Select Appointment Type: ',
|
156
|
+
items,
|
157
|
+
items.size,
|
158
|
+
0,
|
159
|
+
true,
|
160
|
+
false)
|
153
161
|
|
154
162
|
# Get the appointment type from the user.
|
155
163
|
selection = itemlist.activate([])
|
@@ -167,10 +175,19 @@ class Appointment
|
|
167
175
|
marker = Appointment::GPAppointmentAttributes[selection]
|
168
176
|
|
169
177
|
# Create the entry field for the description.
|
170
|
-
entry = RNDK::ENTRY.new(calendar.screen,
|
171
|
-
|
172
|
-
|
173
|
-
|
178
|
+
entry = RNDK::ENTRY.new(calendar.screen,
|
179
|
+
RNDK::CENTER,
|
180
|
+
RNDK::CENTER,
|
181
|
+
'<C>Enter a description of the appointment.',
|
182
|
+
'Description: ',
|
183
|
+
Ncurses::A_NORMAL,
|
184
|
+
'.'.ord,
|
185
|
+
:MIXED,
|
186
|
+
40,
|
187
|
+
1,
|
188
|
+
512,
|
189
|
+
true,
|
190
|
+
false)
|
174
191
|
|
175
192
|
# Get the description.
|
176
193
|
description = entry.activate([])
|
@@ -275,7 +292,7 @@ class Appointment
|
|
275
292
|
end
|
276
293
|
|
277
294
|
# Create the label widget
|
278
|
-
label = RNDK::LABEL.new(calendar.screen, RNDK::CENTER, RNDK::CENTER, mesg,
|
295
|
+
label = RNDK::LABEL.new(calendar.screen, RNDK::CENTER, RNDK::CENTER, mesg, true, false)
|
279
296
|
label.draw(label.box)
|
280
297
|
label.wait(' ')
|
281
298
|
label.destroy
|
@@ -293,17 +310,17 @@ class Appointment
|
|
293
310
|
" '?' displays appointment for selected day",
|
294
311
|
" 'enter' or 'tab' quits"]
|
295
312
|
|
296
|
-
rndkscreen.
|
313
|
+
rndkscreen.popup_label msg
|
297
314
|
end
|
298
315
|
|
299
316
|
# Now we bind actions to the calendar.
|
300
317
|
# Create a key binding to mark days on the calendar.
|
301
|
-
calendar.bind(:
|
302
|
-
calendar.bind(:
|
303
|
-
calendar.bind(:
|
304
|
-
calendar.bind(:
|
305
|
-
calendar.bind(:
|
306
|
-
calendar.bind(:
|
318
|
+
calendar.bind(:calendar, 'm', create_calendar_mark_cb, appointment_info)
|
319
|
+
calendar.bind(:calendar, 'M', create_calendar_mark_cb, appointment_info)
|
320
|
+
calendar.bind(:calendar, 'r', remove_calendar_mark_cb, appointment_info)
|
321
|
+
calendar.bind(:calendar, 'R', remove_calendar_mark_cb, appointment_info)
|
322
|
+
calendar.bind(:calendar, '?', display_calendar_mark_cb, appointment_info)
|
323
|
+
calendar.bind(:calendar, 'h', show_help, nil)
|
307
324
|
|
308
325
|
# Set all the appointments read from the file.
|
309
326
|
appointment_info.appointment.each do |appointment|
|
@@ -316,17 +333,15 @@ class Appointment
|
|
316
333
|
end
|
317
334
|
|
318
335
|
# Draw the calendar widget.
|
319
|
-
calendar.draw
|
336
|
+
calendar.draw calendar.box
|
320
337
|
|
321
338
|
# Let the user play with the widget.
|
322
|
-
calendar.activate
|
339
|
+
calendar.activate
|
323
340
|
|
324
341
|
# Save the appointment information.
|
325
342
|
Appointment.saveAppointmentFile(filename, appointment_info)
|
326
343
|
|
327
344
|
# Clean up.
|
328
|
-
calendar.destroy
|
329
|
-
rndkscreen.destroy
|
330
345
|
RNDK::Screen.end_rndk
|
331
346
|
end
|
332
347
|
end
|
data/demos/clock.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
+
# Note: This is not for beginners! Check out the examples/
|
4
|
+
# before adventuring into the demos/ realm!
|
5
|
+
#
|
3
6
|
# Shows a colored clock on the screen according to
|
4
7
|
# current system time.
|
5
8
|
# Press any key to exit.
|
@@ -8,20 +11,19 @@ require 'rndk/label'
|
|
8
11
|
|
9
12
|
begin
|
10
13
|
# Set up RNDK
|
11
|
-
|
12
|
-
|
13
|
-
RNDK::Draw.initRNDKColor
|
14
|
+
rndkscreen = RNDK::Screen.new
|
15
|
+
RNDK::Color.init
|
14
16
|
|
15
17
|
# Initial time string
|
16
18
|
mesg = ['</1/B>HH:MM:SS']
|
17
19
|
|
18
20
|
# Declare the labels.
|
19
|
-
label = RNDK::LABEL.new(rndkscreen, RNDK::CENTER, RNDK::CENTER, mesg,
|
21
|
+
label = RNDK::LABEL.new(rndkscreen, RNDK::CENTER, RNDK::CENTER, mesg, true, true)
|
20
22
|
|
21
23
|
# Woops, something bad happened
|
22
24
|
if label.nil?
|
23
25
|
rndkscreen.destroy
|
24
|
-
RNDK.end_rndk
|
26
|
+
RNDK::Screen.end_rndk
|
25
27
|
|
26
28
|
puts "Cannot create the label. Is the window too small?"
|
27
29
|
exit 1
|
@@ -33,7 +35,11 @@ begin
|
|
33
35
|
# Will wait 50ms before getting input
|
34
36
|
Ncurses.wtimeout(label.screen.window, 50)
|
35
37
|
|
36
|
-
|
38
|
+
loop do
|
39
|
+
# Will go on until the user presses something
|
40
|
+
char = Ncurses.wgetch label.screen.window
|
41
|
+
break unless (char == Ncurses::ERR)
|
42
|
+
|
37
43
|
current_time = Time.now.getlocal
|
38
44
|
|
39
45
|
# Formatting time string.
|
@@ -41,16 +47,21 @@ begin
|
|
41
47
|
mesg = [str]
|
42
48
|
|
43
49
|
# Set the label contents
|
44
|
-
label.set(mesg,
|
50
|
+
label.set(mesg, label.box)
|
45
51
|
|
46
52
|
# Draw the label and sleep
|
47
53
|
label.draw(label.box)
|
48
54
|
Ncurses.napms(500)
|
49
|
-
end
|
55
|
+
end
|
50
56
|
|
51
|
-
# Clean up
|
52
|
-
label.destroy
|
53
|
-
rndkscreen.destroy
|
54
57
|
RNDK::Screen.end_rndk
|
58
|
+
|
59
|
+
# In case something goes wrong
|
60
|
+
rescue Exception => e
|
61
|
+
RNDK::Screen.end_rndk
|
62
|
+
|
63
|
+
puts e
|
64
|
+
puts e.inspect
|
65
|
+
puts e.backtrace
|
55
66
|
end
|
56
67
|
|
data/demos/fileview.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Note: This is not for beginners! Check out the examples/
|
4
|
+
# before adventuring into the demos/ realm!
|
5
|
+
#
|
6
|
+
# Shows a FSelect Widget, asking you to pick a file.
|
7
|
+
# Then, a Viewer Widget, showing that file's contents.
|
8
|
+
#
|
9
|
+
require 'optparse'
|
10
|
+
require 'rndk/fselect'
|
11
|
+
|
12
|
+
begin
|
13
|
+
filename = ''
|
14
|
+
directory = '.'
|
15
|
+
|
16
|
+
# Create the viewer buttons.
|
17
|
+
button = [
|
18
|
+
'</5><OK><!5>',
|
19
|
+
'</5><Cancel><!5>',
|
20
|
+
]
|
21
|
+
|
22
|
+
# Set up RNDK and Colors
|
23
|
+
rndkscreen = RNDK::Screen.new
|
24
|
+
RNDK::Color.init
|
25
|
+
|
26
|
+
# Get the filename
|
27
|
+
if filename == ''
|
28
|
+
title = '<C>Pick a file.'
|
29
|
+
label = 'File: '
|
30
|
+
fselect = RNDK::FSELECT.new(rndkscreen,
|
31
|
+
RNDK::CENTER,
|
32
|
+
RNDK::CENTER,
|
33
|
+
20,
|
34
|
+
65,
|
35
|
+
title,
|
36
|
+
label,
|
37
|
+
Ncurses::A_NORMAL,
|
38
|
+
'_',
|
39
|
+
Ncurses::A_REVERSE,
|
40
|
+
'</5>', '</48>', '</N>', '</N>',
|
41
|
+
true,
|
42
|
+
false)
|
43
|
+
|
44
|
+
# Set the starting directory. This is not necessary because when
|
45
|
+
# the file selector starts it uses the present directory as a default.
|
46
|
+
fselect.set(directory,
|
47
|
+
Ncurses::A_NORMAL,
|
48
|
+
'.',
|
49
|
+
Ncurses::A_REVERSE,
|
50
|
+
'</5>', '</48>',
|
51
|
+
'</N>', '</N>',
|
52
|
+
fselect.box)
|
53
|
+
|
54
|
+
# Activate the file selector.
|
55
|
+
filename = fselect.activate([])
|
56
|
+
|
57
|
+
# Check how the person exited from the widget.
|
58
|
+
if fselect.exit_type == :ESCAPE_HIT
|
59
|
+
# pop up a message for the user.
|
60
|
+
mesg = [
|
61
|
+
'<C>Escape hit. No file selected.',
|
62
|
+
'',
|
63
|
+
'<C>Press any key to continue.',
|
64
|
+
]
|
65
|
+
rndkscreen.popup_label(mesg, 3)
|
66
|
+
|
67
|
+
fselect.destroy
|
68
|
+
|
69
|
+
RNDK::Screen.end_rndk
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
fselect.destroy
|
73
|
+
end
|
74
|
+
|
75
|
+
# Create the file viewer to view the file selected.
|
76
|
+
example = RNDK::VIEWER.new(rndkscreen,
|
77
|
+
RNDK::CENTER,
|
78
|
+
RNDK::CENTER,
|
79
|
+
20,
|
80
|
+
-2,
|
81
|
+
button,
|
82
|
+
2,
|
83
|
+
Ncurses::A_REVERSE,
|
84
|
+
true,
|
85
|
+
false)
|
86
|
+
|
87
|
+
# Could we create the viewer widget?
|
88
|
+
if example.nil?
|
89
|
+
RNDK::Screen.end_rndk
|
90
|
+
|
91
|
+
puts "Cannot create viewer. Is the window too small?"
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
# Open the file and read the contents.
|
96
|
+
|
97
|
+
info = []
|
98
|
+
lines = RNDK.read_file(filename, info)
|
99
|
+
if lines == -1
|
100
|
+
puts "Could not open %s" % [filename]
|
101
|
+
exit 1
|
102
|
+
end
|
103
|
+
|
104
|
+
# Set up the viewer title and the contents to the widget.
|
105
|
+
title = '<C></B/22>%20s<!22!B> (If screen is messed up, press Ctrl+L)' % filename
|
106
|
+
example.set(title, info, lines, Ncurses::A_REVERSE, true, true, true)
|
107
|
+
|
108
|
+
# Activate the viewer widget.
|
109
|
+
selected = example.activate([])
|
110
|
+
|
111
|
+
# Check how the person exited from the widget.
|
112
|
+
if example.exit_type == :ESCAPE_HIT
|
113
|
+
mesg = [
|
114
|
+
'<C>Escape hit. No Button selected.',
|
115
|
+
'',
|
116
|
+
'<C>Press any key to continue.',
|
117
|
+
]
|
118
|
+
rndkscreen.popup_label mesg
|
119
|
+
|
120
|
+
elsif example.exit_type == :NORMAL
|
121
|
+
mesg = [
|
122
|
+
'<C>You selected button %d' % [selected],
|
123
|
+
'',
|
124
|
+
'<C>Press any key to continue.',
|
125
|
+
]
|
126
|
+
rndkscreen.popup_label mesg
|
127
|
+
end
|
128
|
+
|
129
|
+
# Clean up
|
130
|
+
RNDK::Screen.end_rndk
|
131
|
+
|
132
|
+
# In case something goes wrong
|
133
|
+
rescue Exception => e
|
134
|
+
RNDK::Screen.end_rndk
|
135
|
+
|
136
|
+
puts e
|
137
|
+
puts e.inspect
|
138
|
+
puts e.backtrace
|
139
|
+
end
|
140
|
+
|
141
|
+
|
data/examples/01-hello-world.rb
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
rndkscreen = RNDK::Screen.new
|
11
11
|
|
12
12
|
# Set up RNDK colors
|
13
|
-
RNDK::
|
13
|
+
RNDK::Color.init
|
14
14
|
|
15
15
|
# Set the labels' content.
|
16
16
|
# (RNDK supports a "markup" string, with colors
|
@@ -28,7 +28,6 @@ begin
|
|
28
28
|
RNDK::CENTER, # x
|
29
29
|
RNDK::CENTER, # y
|
30
30
|
mesg, # message
|
31
|
-
4, # lines count
|
32
31
|
true, # box?
|
33
32
|
true) # shadow?
|
34
33
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Shows how to use colors on your daily life,
|
4
|
+
# plus this beautiful Calendar Widget!
|
5
|
+
#
|
6
|
+
require 'rndk/calendar'
|
7
|
+
|
8
|
+
begin
|
9
|
+
# Always initialize and save the scren
|
10
|
+
screen = RNDK::Screen.new
|
11
|
+
RNDK::Color.init
|
12
|
+
|
13
|
+
# Disabling the blinking cursor
|
14
|
+
Ncurses.curs_set 0
|
15
|
+
|
16
|
+
# Welcome to our Calendar Widget!
|
17
|
+
#
|
18
|
+
# We call Colors attributes - or attrib.
|
19
|
+
# We use them as:
|
20
|
+
#
|
21
|
+
# RNDK::Color[:foreground_background]
|
22
|
+
#
|
23
|
+
# If you want to use your terminal's default
|
24
|
+
# background, simply do:
|
25
|
+
#
|
26
|
+
# RNDK::Color[:foreground]
|
27
|
+
#
|
28
|
+
# On the calendar, if we supply 0 as the
|
29
|
+
# day/month/year it'll use the current day/month/year.
|
30
|
+
cal = RNDK::Calendar.new(screen,
|
31
|
+
RNDK::CENTER, # x
|
32
|
+
RNDK::CENTER, # y
|
33
|
+
"Colored calendar", # title
|
34
|
+
0, # day
|
35
|
+
0, # month
|
36
|
+
0, # year
|
37
|
+
RNDK::Color[:red_yellow], # day attrib
|
38
|
+
RNDK::Color[:cyan_white], # month attrib
|
39
|
+
RNDK::Color[:black_cyan], # year attrib
|
40
|
+
RNDK::Color[:red], # highlight
|
41
|
+
true, # has box?
|
42
|
+
false) # has shadow?
|
43
|
+
cal.activate []
|
44
|
+
|
45
|
+
RNDK::Screen.end_rndk
|
46
|
+
|
47
|
+
# Assuring we end RNDK in case something
|
48
|
+
# bad happens.
|
49
|
+
# You'll see this a lot on the examples.
|
50
|
+
rescue Exception => e
|
51
|
+
RNDK::Screen.end_rndk
|
52
|
+
|
53
|
+
puts e
|
54
|
+
puts e.inspect
|
55
|
+
puts e.backtrace
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Shows all the color pairs available on RNDK.
|
4
|
+
# Also, how to use RNDK's color markup on strings.
|
5
|
+
#
|
6
|
+
# Colors on text are achieved by foreground/background
|
7
|
+
# color pairs. Run the example now.
|
8
|
+
#
|
9
|
+
# As you just say, they go from 1 to 80, going on the
|
10
|
+
# following order in sets of 8 and from background to
|
11
|
+
# foreground:
|
12
|
+
#
|
13
|
+
# 1. white
|
14
|
+
# 2. red
|
15
|
+
# 3. green
|
16
|
+
# 4. yellow
|
17
|
+
# 5. blue
|
18
|
+
# 6. magenta
|
19
|
+
# 7. cyan
|
20
|
+
# 8. black
|
21
|
+
#
|
22
|
+
# Which means that 4 is white on yellow, 11 is red on green
|
23
|
+
# and 44 is magenta on yellow.
|
24
|
+
#
|
25
|
+
# 65 to 72 are the default terminal's foreground over
|
26
|
+
# color backgrounds and 73 to 80 are the colors over
|
27
|
+
# the terminal's default background.
|
28
|
+
|
29
|
+
require 'rndk/label'
|
30
|
+
|
31
|
+
begin
|
32
|
+
# Starting RNDK and Color support
|
33
|
+
screen = RNDK::Screen.new
|
34
|
+
RNDK::Color.init
|
35
|
+
|
36
|
+
# Don't get scared, we're simply showing off all 80 color
|
37
|
+
# pairs available.
|
38
|
+
#
|
39
|
+
# * To start a color, do `</XX>`, where XX is a color pair
|
40
|
+
# from 1 to 80.
|
41
|
+
# * To stop it, do `<!XX>`, where XX is the same as above.
|
42
|
+
|
43
|
+
msg = []
|
44
|
+
msg << "</1>Pair01<!1> </2>Pair02<!2> </3>Pair03<!3> </4>Pair04<!4> </5>Pair05<!5> </6>Pair06<!6> </7>Pair07<!7> </8>Pair08<!8>"
|
45
|
+
msg << "</9>Pair09<!9> </10>Pair10<!10> </11>Pair11<!11> </12>Pair12<!12> </13>Pair13<!13> </14>Pair14<!14> </15>Pair15<!15> </16>Pair16<!16>"
|
46
|
+
msg << "</17>Pair17<!17> </18>Pair18<!18> </19>Pair19<!19> </20>Pair20<!20> </21>Pair21<!21> </22>Pair22<!22> </23>Pair23<!23> </24>Pair24<!24>"
|
47
|
+
msg << "</25>Pair25<!25> </26>Pair26<!26> </27>Pair27<!27> </28>Pair28<!28> </29>Pair29<!29> </30>Pair30<!30> </31>Pair31<!31> </32>Pair32<!32>"
|
48
|
+
msg << "</33>Pair33<!33> </34>Pair34<!34> </35>Pair35<!35> </36>Pair36<!36> </37>Pair37<!37> </38>Pair38<!38> </39>Pair39<!39> </40>Pair40<!40>"
|
49
|
+
msg << "</41>Pair41<!41> </42>Pair42<!42> </43>Pair43<!43> </44>Pair44<!44> </45>Pair45<!45> </46>Pair46<!46> </47>Pair47<!47> </48>Pair48<!48>"
|
50
|
+
msg << "</49>Pair49<!49> </50>Pair50<!50> </51>Pair51<!51> </52>Pair52<!52> </53>Pair53<!53> </54>Pair54<!54> </55>Pair55<!55> </56>Pair56<!56>"
|
51
|
+
msg << "</57>Pair57<!57> </58>Pair58<!58> </59>Pair59<!59> </60>Pair60<!60> </61>Pair61<!61> </62>Pair62<!62> </63>Pair63<!63> </64>Pair64<!64>"
|
52
|
+
msg << "</65>Pair65<!65> </66>Pair66<!66> </67>Pair67<!67> </68>Pair68<!68> </69>Pair69<!69> </70>Pair70<!70> </71>Pair71<!71> </72>Pair72<!72>"
|
53
|
+
msg << "</73>Pair73<!73> </74>Pair74<!74> </75>Pair75<!75> </76>Pair76<!76> </77>Pair77<!77> </78>Pair78<!78> </79>Pair79<!79> </80>Pair80<!80>"
|
54
|
+
msg << ""
|
55
|
+
msg << "<C>All RNDK color pairs (press 'q' to quit)"
|
56
|
+
|
57
|
+
# Show label with that huge message.
|
58
|
+
label = RNDK::LABEL.new(screen,
|
59
|
+
RNDK::CENTER, # x
|
60
|
+
1, # y
|
61
|
+
msg,
|
62
|
+
true, # has box?
|
63
|
+
true) # has shadow?
|
64
|
+
|
65
|
+
screen.refresh
|
66
|
+
label.wait('q') # wait for key to be pressed
|
67
|
+
|
68
|
+
RNDK::Screen.end_rndk
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This shows you how easy it is to use the Quick Widgets --
|
4
|
+
# temporary pre-made Widgets with a single action.
|
5
|
+
#
|
6
|
+
# They're automatically included within `require 'rndk'`.
|
7
|
+
require 'rndk'
|
8
|
+
|
9
|
+
begin
|
10
|
+
screen = RNDK::Screen.new
|
11
|
+
|
12
|
+
# Popup label
|
13
|
+
msg = ["Hello, there!",
|
14
|
+
"Lemme show you some pre-made widgets",
|
15
|
+
"This is the popup_label",
|
16
|
+
"(press any key to continue)"
|
17
|
+
]
|
18
|
+
screen.popup_label msg
|
19
|
+
|
20
|
+
# Popup dialog
|
21
|
+
msg = ["Now this is the popup_dialog",
|
22
|
+
"It returns the index of which button",
|
23
|
+
"you select"
|
24
|
+
]
|
25
|
+
buttons = ["Press me",
|
26
|
+
"No, press me",
|
27
|
+
"No, me"
|
28
|
+
]
|
29
|
+
choice = screen.popup_dialog(msg, buttons)
|
30
|
+
|
31
|
+
screen.popup_label ["You selected button no #{choice}"]
|
32
|
+
|
33
|
+
# View file
|
34
|
+
title = "view_file (If something bad happens, press Ctrl+L)"
|
35
|
+
buttons = ["I'm impressed",
|
36
|
+
"Maybe impressed",
|
37
|
+
"Not impressed"
|
38
|
+
]
|
39
|
+
screen.view_file(title, __FILE__, buttons)
|
40
|
+
|
41
|
+
# Get list index
|
42
|
+
title = "get_list_index example"
|
43
|
+
msg = ["Apples",
|
44
|
+
"Oranges",
|
45
|
+
"Avocados",
|
46
|
+
"Watermelons"]
|
47
|
+
|
48
|
+
screen.get_list_index(title, msg, true)
|
49
|
+
|
50
|
+
# Get string
|
51
|
+
title = "get_string example"
|
52
|
+
msg = "Finally, the last example! What did you thing of it? "
|
53
|
+
|
54
|
+
value = screen.get_string(title, msg, "great")
|
55
|
+
|
56
|
+
screen.popup_label ["You just said '#{value}'"]
|
57
|
+
|
58
|
+
# Finally, the end!
|
59
|
+
RNDK::Screen.end_rndk
|
60
|
+
|
61
|
+
puts "...and as always, thanks for watching!"
|
62
|
+
|
63
|
+
# Just in case something bad happens.
|
64
|
+
rescue Exception => e
|
65
|
+
RNDK::Screen.end_rndk
|
66
|
+
|
67
|
+
puts e
|
68
|
+
puts e.inspect
|
69
|
+
puts e.backtrace
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
|
@@ -40,7 +40,7 @@ begin
|
|
40
40
|
rndkscreen = RNDK::Screen.new(curses_win)
|
41
41
|
|
42
42
|
# Set up RNDK colors
|
43
|
-
RNDK::
|
43
|
+
RNDK::Color.init
|
44
44
|
|
45
45
|
# Create the entry field widget.
|
46
46
|
entry = RNDK::ENTRY.new(rndkscreen,
|
@@ -79,7 +79,7 @@ begin
|
|
79
79
|
"",
|
80
80
|
"<C>Press any key to continue."
|
81
81
|
]
|
82
|
-
rndkscreen.
|
82
|
+
rndkscreen.popup_label mesg
|
83
83
|
|
84
84
|
elsif entry.exit_type == :NORMAL
|
85
85
|
mesg = [
|
@@ -88,12 +88,9 @@ begin
|
|
88
88
|
"",
|
89
89
|
"<C>Press any key to continue."
|
90
90
|
]
|
91
|
-
rndkscreen.
|
91
|
+
rndkscreen.popup_label mesg
|
92
92
|
end
|
93
93
|
|
94
|
-
# Clean up
|
95
|
-
entry.destroy
|
96
|
-
rndkscreen.destroy
|
97
94
|
RNDK::Screen.end_rndk
|
98
95
|
|
99
96
|
# Just in case something bad happens.
|