rdialog 0.1.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rdialog.rb +290 -6
- data/lib/rdialog/version.rb +2 -2
- data/website/index.html +2 -2
- metadata +2 -2
data/lib/rdialog.rb
CHANGED
@@ -100,16 +100,22 @@ class RDialog
|
|
100
100
|
# is used.
|
101
101
|
attr_accessor :path_to_dialog
|
102
102
|
|
103
|
-
#
|
104
|
-
#print maxsize method
|
105
|
-
#print size method
|
106
|
-
#print version method
|
107
|
-
|
103
|
+
# Returns a new RDialog Object
|
108
104
|
|
109
105
|
def initialize()
|
110
106
|
end
|
107
|
+
# A calendar box displays month, day and year in separately
|
108
|
+
# adjustable windows. If the values for day, month or year are
|
109
|
+
# missing or negative, the current date's corresponding values
|
110
|
+
# are used. You can increment or decrement any of those using
|
111
|
+
# the left-, up-, right- and down-arrows. Use vi-style h, j, k
|
112
|
+
# and l for moving around the array of days in a month. Use tab
|
113
|
+
# or backtab to move between windows. If the year is given as
|
114
|
+
# zero, the current date is used as an initial value.
|
115
|
+
#
|
116
|
+
# Returns a Date object with the selected date
|
111
117
|
|
112
|
-
def calendar(text="Select a Date", height=
|
118
|
+
def calendar(text="Select a Date", height=0, width=0, day=Date.today.mday(), month=Date.today.mon(), year=Date.today.year())
|
113
119
|
|
114
120
|
tmp = Tempfile.new('tmp')
|
115
121
|
|
@@ -129,6 +135,12 @@ class RDialog
|
|
129
135
|
|
130
136
|
end
|
131
137
|
|
138
|
+
# A checklist box is similar to a menu box; there are multiple
|
139
|
+
# entries presented in the form of a menu. Instead of choosing
|
140
|
+
# one entry among the entries, each entry can be turned on or off
|
141
|
+
# by the user. The initial on/off state of each entry is speci-
|
142
|
+
# fied by status.
|
143
|
+
|
132
144
|
def checklist(text, items, height=0, width=0, listheight=0)
|
133
145
|
|
134
146
|
tmp = Tempfile.new('tmp')
|
@@ -174,6 +186,75 @@ class RDialog
|
|
174
186
|
|
175
187
|
end
|
176
188
|
|
189
|
+
# The file-selection dialog displays a text-entry window in which
|
190
|
+
# you can type a filename (or directory), and above that two win-
|
191
|
+
# dows with directory names and filenames.
|
192
|
+
|
193
|
+
# Here filepath can be a filepath in which case the file and
|
194
|
+
# directory windows will display the contents of the path and the
|
195
|
+
# text-entry window will contain the preselected filename.
|
196
|
+
#
|
197
|
+
# Use tab or arrow keys to move between the windows. Within the
|
198
|
+
# directory or filename windows, use the up/down arrow keys to
|
199
|
+
# scroll the current selection. Use the space-bar to copy the
|
200
|
+
# current selection into the text-entry window.
|
201
|
+
#
|
202
|
+
# Typing any printable characters switches focus to the text-
|
203
|
+
# entry window, entering that character as well as scrolling the
|
204
|
+
# directory and filename windows to the closest match.
|
205
|
+
#
|
206
|
+
# Use a carriage return or the "OK" button to accept the current
|
207
|
+
# value in the text-entry window and exit.
|
208
|
+
|
209
|
+
def fselect(path, height=0, width=0)
|
210
|
+
tmp = Tempfile.new('tmp')
|
211
|
+
|
212
|
+
command = option_string() + "--fselect \"" + path.to_s +
|
213
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
214
|
+
|
215
|
+
command += "2> " + tmp.path
|
216
|
+
|
217
|
+
success = system(command)
|
218
|
+
|
219
|
+
if success
|
220
|
+
begin
|
221
|
+
selected_string = tmp.readline
|
222
|
+
rescue EOFError
|
223
|
+
selected_string = ""
|
224
|
+
end
|
225
|
+
tmp.close!
|
226
|
+
return selected_string
|
227
|
+
else
|
228
|
+
tmp.close!
|
229
|
+
return success
|
230
|
+
end
|
231
|
+
end
|
232
|
+
# Does not work. Someone is welcome to try and make it work.
|
233
|
+
def gauge(text, height=0, width=0)
|
234
|
+
return false
|
235
|
+
end
|
236
|
+
|
237
|
+
# An info box is basically a message box. However, in this case,
|
238
|
+
# dialog will exit immediately after displaying the message to
|
239
|
+
# the user. The screen is not cleared when dialog exits, so that
|
240
|
+
# the message will remain on the screen until the calling shell
|
241
|
+
# script clears it later. This is useful when you want to inform
|
242
|
+
# the user that some operations are carrying on that may require
|
243
|
+
# some time to finish.
|
244
|
+
#
|
245
|
+
# Returns false if esc was pushed
|
246
|
+
|
247
|
+
def infobox(text, height=0, width=0)
|
248
|
+
command = option_string() + "--infobox \"" + text.to_s +
|
249
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
250
|
+
success = system(command)
|
251
|
+
return success
|
252
|
+
end
|
253
|
+
|
254
|
+
# A radiolist box is similar to a menu box. The only difference
|
255
|
+
# is that you can indicate which entry is currently selected, by
|
256
|
+
# setting its status to true.
|
257
|
+
|
177
258
|
def radiolist(text, items, height=0, width=0, listheight=0)
|
178
259
|
|
179
260
|
tmp = Tempfile.new('tmp')
|
@@ -211,6 +292,186 @@ class RDialog
|
|
211
292
|
|
212
293
|
end
|
213
294
|
|
295
|
+
# As its name suggests, a menu box is a dialog box that can be
|
296
|
+
# used to present a list of choices in the form of a menu for the
|
297
|
+
# user to choose. Choices are displayed in the order given.
|
298
|
+
# Each menu entry consists of a tag string and an item string.
|
299
|
+
# The tag gives the entry a name to distinguish it from the other
|
300
|
+
# entries in the menu. The item is a short description of the
|
301
|
+
# option that the entry represents. The user can move between
|
302
|
+
# the menu entries by pressing the cursor keys, the first letter
|
303
|
+
# of the tag as a hot-key, or the number keys 1-9. There are
|
304
|
+
# menu-height entries displayed in the menu at one time, but the
|
305
|
+
# menu will be scrolled if there are more entries than that.
|
306
|
+
#
|
307
|
+
# Returns a string containing the tag of the chosen menu entry.
|
308
|
+
|
309
|
+
def menu(text="Text Goes Here", items=nil, height=0, width=0, listheight=0)
|
310
|
+
tmp = Tempfile.new('tmp')
|
311
|
+
|
312
|
+
itemlist = String.new
|
313
|
+
|
314
|
+
for item in items
|
315
|
+
itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s + "\" "
|
316
|
+
|
317
|
+
if @itemhelp
|
318
|
+
itemlist += "\"" + item[2].to_s + "\" "
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
command = option_string() + "--menu \"" + text.to_s +
|
323
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s +
|
324
|
+
" " + listheight.to_i.to_s + " " + itemlist + "2> " +
|
325
|
+
tmp.path
|
326
|
+
success = system(command)
|
327
|
+
|
328
|
+
if success
|
329
|
+
selected_string = tmp.readline
|
330
|
+
tmp.close!
|
331
|
+
return selected_string
|
332
|
+
else
|
333
|
+
tmp.close!
|
334
|
+
return success
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
# A message box is very similar to a yes/no box. The only dif-
|
340
|
+
# ference between a message box and a yes/no box is that a mes-
|
341
|
+
# sage box has only a single OK button. You can use this dialog
|
342
|
+
# box to display any message you like. After reading the mes-
|
343
|
+
# sage, the user can press the ENTER key so that dialog will exit
|
344
|
+
# and the calling shell script can continue its operation.
|
345
|
+
|
346
|
+
def msgbox(text="Text Goes Here", height=0, width=0)
|
347
|
+
command = option_string() + "--msgbox \"" + text.to_s +
|
348
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
349
|
+
|
350
|
+
success = system(command)
|
351
|
+
return success
|
352
|
+
end
|
353
|
+
|
354
|
+
# A password box is similar to an input box, except that the text
|
355
|
+
# the user enters is not displayed. This is useful when prompt-
|
356
|
+
# ing for passwords or other sensitive information. Be aware
|
357
|
+
# that if anything is passed in "init", it will be visible in the
|
358
|
+
# system's process table to casual snoopers. Also, it is very
|
359
|
+
# confusing to the user to provide them with a default password
|
360
|
+
# they cannot see. For these reasons, using "init" is highly
|
361
|
+
# discouraged.
|
362
|
+
|
363
|
+
def passwordbox(text="Please enter some text", height=0, width=0, init="")
|
364
|
+
tmp = Tempfile.new('tmp')
|
365
|
+
command = option_string() + "--passwordbox \"" + text.to_s +
|
366
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
367
|
+
|
368
|
+
unless init.empty?
|
369
|
+
command += init.to_s + " "
|
370
|
+
end
|
371
|
+
|
372
|
+
command += "2> " + tmp.path
|
373
|
+
|
374
|
+
success = system(command)
|
375
|
+
|
376
|
+
if success
|
377
|
+
begin
|
378
|
+
selected_string = tmp.readline
|
379
|
+
rescue EOFError
|
380
|
+
selected_string = ""
|
381
|
+
end
|
382
|
+
tmp.close!
|
383
|
+
return selected_string
|
384
|
+
else
|
385
|
+
tmp.close!
|
386
|
+
return success
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
# The textbox method handles three similar dialog functions, textbox,
|
391
|
+
# tailbox, and tailboxbg. They are activated by setting type to
|
392
|
+
# "text", "tail", and "bg" respectively
|
393
|
+
#
|
394
|
+
# Textbox mode:
|
395
|
+
# A text box lets you display the contents of a text file in a
|
396
|
+
# dialog box. It is like a simple text file viewer. The user
|
397
|
+
# can move through the file by using the cursor, PGUP/PGDN and
|
398
|
+
# HOME/END keys available on most keyboards. If the lines are
|
399
|
+
# too long to be displayed in the box, the LEFT/RIGHT keys can be
|
400
|
+
# used to scroll the text region horizontally. You may also use
|
401
|
+
# vi-style keys h, j, k, l in place of the cursor keys, and B or
|
402
|
+
# N in place of the pageup/pagedown keys. Scroll up/down using
|
403
|
+
# vi-style 'k' and 'j', or arrow-keys. Scroll left/right using
|
404
|
+
# vi-style 'h' and 'l', or arrow-keys. A '0' resets the
|
405
|
+
# left/right scrolling. For more convenience, vi-style forward
|
406
|
+
# and backward searching functions are also provided.
|
407
|
+
#
|
408
|
+
# Tailbox mode:
|
409
|
+
# Display text from a file in a dialog box, as in a "tail -f"
|
410
|
+
# command. Scroll left/right using vi-style 'h' and 'l', or
|
411
|
+
# arrow-keys. A '0' resets the scrolling.
|
412
|
+
#
|
413
|
+
# Tailboxbg mode:
|
414
|
+
# Display text from a file in a dialog box as a background task,
|
415
|
+
# as in a "tail -f &" command. Scroll left/right using vi-style
|
416
|
+
# 'h' and 'l', or arrow-keys. A '0' resets the scrolling.
|
417
|
+
|
418
|
+
def textbox(file, type="text", height=0, width=0)
|
419
|
+
case type
|
420
|
+
when "text"
|
421
|
+
opt = "--textbox"
|
422
|
+
when "tail"
|
423
|
+
opt = "--tailbox"
|
424
|
+
when "bg"
|
425
|
+
opt = "--textboxbg"
|
426
|
+
end
|
427
|
+
|
428
|
+
command = option_string() + opt +" \"" + file.to_s +
|
429
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
430
|
+
|
431
|
+
success = system(command)
|
432
|
+
|
433
|
+
return success
|
434
|
+
end
|
435
|
+
|
436
|
+
# A dialog is displayed which allows you to select hour, minute
|
437
|
+
# and second. If the values for hour, minute or second are miss-
|
438
|
+
# ing or negative, the current date's corresponding values are
|
439
|
+
# used. You can increment or decrement any of those using the
|
440
|
+
# left-, up-, right- and down-arrows. Use tab or backtab to move
|
441
|
+
# between windows.
|
442
|
+
#
|
443
|
+
# On exit, a Time object is returned.
|
444
|
+
|
445
|
+
def timebox(file, type="text", height=0, width=0, time=Time.now)
|
446
|
+
tmp = Tempfile.new('tmp')
|
447
|
+
|
448
|
+
command = option_string() + "--timebox \"" + text.to_s +
|
449
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " " +
|
450
|
+
time.hour.to_s + " " + time.min.to_s + " " +
|
451
|
+
time.sec.to_s + " 2> " + tmp.path
|
452
|
+
success = system(command)
|
453
|
+
if success
|
454
|
+
time = Time.parse(tmp.readline)
|
455
|
+
tmp.close!
|
456
|
+
return time
|
457
|
+
else
|
458
|
+
tmp.close!
|
459
|
+
return success
|
460
|
+
end
|
461
|
+
|
462
|
+
end
|
463
|
+
|
464
|
+
# An input box is useful when you want to ask questions that
|
465
|
+
# require the user to input a string as the answer. If init is
|
466
|
+
# supplied it is used to initialize the input string. When
|
467
|
+
# entering the string, the backspace, delete and cursor keys can
|
468
|
+
# be used to correct typing errors. If the input string is
|
469
|
+
# longer than can fit in the dialog box, the input field will be
|
470
|
+
# scrolled.
|
471
|
+
#
|
472
|
+
# On exit, the input string will be returned.
|
473
|
+
|
474
|
+
|
214
475
|
def inputbox(text="Please enter some text", height=0, width=0, init="")
|
215
476
|
tmp = Tempfile.new('tmp')
|
216
477
|
|
@@ -239,6 +500,25 @@ class RDialog
|
|
239
500
|
end
|
240
501
|
end
|
241
502
|
|
503
|
+
# A yes/no dialog box of size height rows by width columns will
|
504
|
+
# be displayed. The string specified by text is displayed inside
|
505
|
+
# the dialog box. If this string is too long to fit in one line,
|
506
|
+
# it will be automatically divided into multiple lines at appro-
|
507
|
+
# priate places. The text string can also contain the sub-string
|
508
|
+
# "\n" or newline characters '\n' to control line breaking
|
509
|
+
# explicitly. This dialog box is useful for asking questions
|
510
|
+
# that require the user to answer either yes or no. The dialog
|
511
|
+
# box has a Yes button and a No button, in which the user can
|
512
|
+
# switch between by pressing the TAB key.
|
513
|
+
|
514
|
+
def yesno(text="Please enter some text", height=0, width=0)
|
515
|
+
command = option_string() + "--inputbox \"" + text.to_s +
|
516
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s
|
517
|
+
|
518
|
+
success = system(command)
|
519
|
+
return success
|
520
|
+
end
|
521
|
+
|
242
522
|
private
|
243
523
|
|
244
524
|
def option_string()
|
@@ -291,6 +571,10 @@ class RDialog
|
|
291
571
|
ostring += "--title " + @title.to_s + " "
|
292
572
|
end
|
293
573
|
|
574
|
+
if @nocancel
|
575
|
+
ostring += "--nocancel "
|
576
|
+
end
|
577
|
+
|
294
578
|
return ostring
|
295
579
|
|
296
580
|
end
|
data/lib/rdialog/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Ruby Dialog Interface</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rdialog"; return false'>
|
35
35
|
Get Version
|
36
|
-
<a href="http://rubyforge.org/projects/rdialog" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/rdialog" class="numbers">0.5.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘rdialog’</h1>
|
39
39
|
|
@@ -112,7 +112,7 @@ exec("ssh sweeper@" + selected_item)
|
|
112
112
|
|
113
113
|
<p>Comments are welcome. Send an email to <a href="mailto:aleks.clark@gmail.com">Aleks Clark</a>.</p>
|
114
114
|
<p class="coda">
|
115
|
-
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>,
|
115
|
+
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 21st May 2007<br>
|
116
116
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
117
117
|
</p>
|
118
118
|
</div>
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rdialog
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2007-05-21 00:00:00.000000 -04:00
|
8
8
|
summary: A gem providing a ruby interface to the n-curses dialog generator dialog
|
9
9
|
require_paths:
|
10
10
|
- lib
|