Class: RDialog
- Inherits:
-
Object
- Object
- RDialog
- Defined in:
- lib/rdialog.rb
Instance Attribute Summary collapse
-
#aspect ⇒ Object
This gives you some control over the box dimensions when using auto sizing (specifying 0 for height and width).
-
#backtitle ⇒ Object
Specifies a backtitle string to be displayed on the backdrop, at the top of the screen.
-
#beep ⇒ Object
Sound the audible alarm each time the screen is refreshed.
-
#begin ⇒ Object
Specify the position of the upper left corner of a dialog box on the screen, as an array containing two integers.
-
#crwrap ⇒ Object
Interpret embedded newlines in the dialog text as a newline on the screen.
-
#itemhelp ⇒ Object
Interpret the tags data for checklist, radiolist and menuboxes adding a column which is displayed in the bottom line of the screen, for the currently selected item.
-
#nocancel ⇒ Object
Suppress the “Cancel” button in checklist, inputbox and menubox modes.
-
#path_to_dialog ⇒ Object
Alternate path to dialog.
-
#shadow ⇒ Object
Draw a shadow to the right and bottom of each dialog box.
-
#sleep ⇒ Object
Sleep (delay) for the given integer of seconds after processing a dialog box.
-
#tabcorrect ⇒ Object
Convert each tab character to one or more spaces.
-
#tablen ⇒ Object
Specify the number(int) of spaces that a tab character occupies if the tabcorrect option is set true.
-
#title ⇒ Object
Title string to be displayed at the top of the dialog box.
Instance Method Summary collapse
-
#calendar(text = "Select a Date", height = 0, width = 0, day = Date.today.mday(), month = Date.today.mon(), year = Date.today.year()) ⇒ Object
Returns a Date object with the selected date.
-
#checklist(text, items, height = 0, width = 0, listheight = 0) ⇒ Object
entries presented in the form of a menu.
-
#fselect(path, height = 0, width = 0) ⇒ Object
Use a carriage return or the “OK” button to accept the current value in the text-entry window and exit.
-
#gauge(text, height = 0, width = 0) ⇒ Object
Does not work.
-
#infobox(text, height = 0, width = 0) ⇒ Object
Returns false if esc was pushed.
-
#initialize ⇒ RDialog
constructor
Returns a new RDialog Object.
- #inputbox(text = "Please enter some text", height = 0, width = 0, init = "") ⇒ Object
-
#menu(text = "Text Goes Here", items = nil, height = 0, width = 0, listheight = 0) ⇒ Object
Returns a string containing the tag of the chosen menu entry.
-
#msgbox(text = "Text Goes Here", height = 0, width = 0) ⇒ Object
A message box is very similar to a yes/no box.
-
#passwordbox(text = "Please enter some text", height = 0, width = 0, init = "") ⇒ Object
A password box is similar to an input box, except that the text the user enters is not displayed.
-
#radiolist(text, items, height = 0, width = 0, listheight = 0) ⇒ Object
A radiolist box is similar to a menu box.
-
#textbox(file, type = "text", height = 0, width = 0) ⇒ Object
The textbox method handles three similar dialog functions, textbox, tailbox, and tailboxbg.
-
#timebox(file, type = "text", height = 0, width = 0, time = Time.now) ⇒ Object
On exit, a Time object is returned.
-
#yesno(text = "Please enter some text", height = 0, width = 0) ⇒ Object
A yes/no dialog box of size height rows by width columns will be displayed.
Constructor Details
#initialize ⇒ RDialog
Returns a new RDialog Object
105 106 |
# File 'lib/rdialog.rb', line 105 def initialize() end |
Instance Attribute Details
#aspect ⇒ Object
This gives you some control over the box dimensions when using auto sizing (specifying 0 for height and width). It represents width / height. The default is 9, which means 9 characters wide to every 1 line high.
25 26 27 |
# File 'lib/rdialog.rb', line 25 def aspect @aspect end |
#backtitle ⇒ Object
Specifies a backtitle string to be displayed on the backdrop, at the top of the screen.
31 32 33 |
# File 'lib/rdialog.rb', line 31 def backtitle @backtitle end |
#beep ⇒ Object
Sound the audible alarm each time the screen is refreshed.
36 37 38 |
# File 'lib/rdialog.rb', line 36 def beep @beep end |
#begin ⇒ Object
Specify the position of the upper left corner of a dialog box on the screen, as an array containing two integers.
42 43 44 |
# File 'lib/rdialog.rb', line 42 def begin @begin end |
#crwrap ⇒ Object
Interpret embedded newlines in the dialog text as a newline on the screen. Otherwise, dialog will only wrap lines where needed to fit inside the text box. Even though you can control line breaks with this, dialog will still wrap any lines that are too long for the width of the box. Without cr-wrap, the layout of your text may be formatted to look nice in the source code of your script without affecting the way it will look in the dialog.
53 54 55 |
# File 'lib/rdialog.rb', line 53 def crwrap @crwrap end |
#itemhelp ⇒ Object
Interpret the tags data for checklist, radiolist and menuboxes adding a column which is displayed in the bottom line of the screen, for the currently selected item.
60 61 62 |
# File 'lib/rdialog.rb', line 60 def itemhelp @itemhelp end |
#nocancel ⇒ Object
Suppress the “Cancel” button in checklist, inputbox and menubox modes. A script can still test if the user pressed the ESC key to cancel to quit.
67 68 69 |
# File 'lib/rdialog.rb', line 67 def nocancel @nocancel end |
#path_to_dialog ⇒ Object
Alternate path to dialog. If this is not set, environment path is used.
101 102 103 |
# File 'lib/rdialog.rb', line 101 def path_to_dialog @path_to_dialog end |
#shadow ⇒ Object
Draw a shadow to the right and bottom of each dialog box.
72 73 74 |
# File 'lib/rdialog.rb', line 72 def shadow @shadow end |
#sleep ⇒ Object
Sleep (delay) for the given integer of seconds after processing a dialog box.
78 79 80 |
# File 'lib/rdialog.rb', line 78 def sleep @sleep end |
#tabcorrect ⇒ Object
Convert each tab character to one or more spaces. Otherwise, tabs are rendered according to the curses library’s interpretation.
85 86 87 |
# File 'lib/rdialog.rb', line 85 def tabcorrect @tabcorrect end |
#tablen ⇒ Object
Specify the number(int) of spaces that a tab character occupies if the tabcorrect option is set true. The default is 8.
91 92 93 |
# File 'lib/rdialog.rb', line 91 def tablen @tablen end |
#title ⇒ Object
Title string to be displayed at the top of the dialog box.
96 97 98 |
# File 'lib/rdialog.rb', line 96 def title @title end |
Instance Method Details
#calendar(text = "Select a Date", height = 0, width = 0, day = Date.today.mday(), month = Date.today.mon(), year = Date.today.year()) ⇒ Object
Returns a Date object with the selected date
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rdialog.rb', line 118 def calendar(text="Select a Date", height=0, width=0, day=Date.today.mday(), month=Date.today.mon(), year=Date.today.year()) tmp = Tempfile.new('tmp') command = option_string() + "--calendar \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " + day.to_i.to_s + " " + month.to_i.to_s + " " + year.to_i.to_s + " 2> " + tmp.path success = system(command) if success date = Date::civil(*tmp.readline.split('/').collect {|i| i.to_i}.reverse) tmp.close! return date else tmp.close! return success end end |
#checklist(text, items, height = 0, width = 0, listheight = 0) ⇒ Object
entries presented in the form of a menu. Instead of choosing
one entry among the entries, each entry can be turned on or off
by the user. The initial on/off state of each entry is speci-
fied by status.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rdialog.rb', line 144 def checklist(text, items, height=0, width=0, listheight=0) tmp = Tempfile.new('tmp') itemlist = String.new for item in items if item[2] item[2] = "on" else item[2] = "off" end itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s + "\" " + item[2] + " " if @itemhelp itemlist += "\"" + item[3].to_s + "\" " end end command = option_string() + "--checklist \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " + listheight.to_i.to_s + " " + itemlist + "2> " + tmp.path puts command success = system(command) puts success if success selected_string = tmp.readline tmp.close! selected_string.slice!(0) selected_string.chomp!("\"") selected_array = selected_string.split('" "') for item in selected_array item.delete!("\\") end return selected_array else tmp.close! return success end end |
#fselect(path, height = 0, width = 0) ⇒ Object
Use a carriage return or the “OK” button to accept the current
value in the text-entry window and exit.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/rdialog.rb', line 209 def fselect(path, height=0, width=0) tmp = Tempfile.new('tmp') command = option_string() + "--fselect \"" + path.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " command += "2> " + tmp.path success = system(command) if success begin selected_string = tmp.readline rescue EOFError selected_string = "" end tmp.close! return selected_string else tmp.close! return success end end |
#gauge(text, height = 0, width = 0) ⇒ Object
Does not work. Someone is welcome to try and make it work.
233 234 235 |
# File 'lib/rdialog.rb', line 233 def gauge(text, height=0, width=0) return false end |
#infobox(text, height = 0, width = 0) ⇒ Object
Returns false if esc was pushed
247 248 249 250 251 252 |
# File 'lib/rdialog.rb', line 247 def infobox(text, height=0, width=0) command = option_string() + "--infobox \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " success = system(command) return success end |
#inputbox(text = "Please enter some text", height = 0, width = 0, init = "") ⇒ Object
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/rdialog.rb', line 475 def inputbox(text="Please enter some text", height=0, width=0, init="") tmp = Tempfile.new('tmp') command = option_string() + "--inputbox \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " unless init.empty? command += init.to_s + " " end command += "2> " + tmp.path success = system(command) if success begin selected_string = tmp.readline rescue EOFError selected_string = "" end tmp.close! return selected_string else tmp.close! return success end end |
#menu(text = "Text Goes Here", items = nil, height = 0, width = 0, listheight = 0) ⇒ Object
Returns a string containing the tag of the chosen menu entry.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/rdialog.rb', line 309 def (text="Text Goes Here", items=nil, height=0, width=0, listheight=0) tmp = Tempfile.new('tmp') itemlist = String.new for item in items itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s + "\" " if @itemhelp itemlist += "\"" + item[2].to_s + "\" " end end command = option_string() + "--menu \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " + listheight.to_i.to_s + " " + itemlist + "2> " + tmp.path success = system(command) if success selected_string = tmp.readline tmp.close! return selected_string else tmp.close! return success end end |
#msgbox(text = "Text Goes Here", height = 0, width = 0) ⇒ Object
A message box is very similar to a yes/no box. The only dif-
ference between a message box and a yes/no box is that a mes-
sage box has only a single OK button. You can use this dialog
box to display any message you like. After reading the mes-
sage, the user can press the ENTER key so that dialog will exit
and the calling shell script can continue its operation.
346 347 348 349 350 351 352 |
# File 'lib/rdialog.rb', line 346 def msgbox(text="Text Goes Here", height=0, width=0) command = option_string() + "--msgbox \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " success = system(command) return success end |
#passwordbox(text = "Please enter some text", height = 0, width = 0, init = "") ⇒ Object
A password box is similar to an input box, except that the text
the user enters is not displayed. This is useful when prompt-
ing for passwords or other sensitive information. Be aware
that if anything is passed in "init", it will be visible in the
system's process table to casual snoopers. Also, it is very
confusing to the user to provide them with a default password
they cannot see. For these reasons, using "init" is highly
discouraged.
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/rdialog.rb', line 363 def passwordbox(text="Please enter some text", height=0, width=0, init="") tmp = Tempfile.new('tmp') command = option_string() + "--passwordbox \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " unless init.empty? command += init.to_s + " " end command += "2> " + tmp.path success = system(command) if success begin selected_string = tmp.readline rescue EOFError selected_string = "" end tmp.close! return selected_string else tmp.close! return success end end |
#radiolist(text, items, height = 0, width = 0, listheight = 0) ⇒ Object
A radiolist box is similar to a menu box. The only difference
is that you can indicate which entry is currently selected, by
setting its status to true.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rdialog.rb', line 258 def radiolist(text, items, height=0, width=0, listheight=0) tmp = Tempfile.new('tmp') itemlist = String.new for item in items if item[2] item[2] = "on" else item[2] = "off" end itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s + "\" " + item[2] + " " if @itemhelp itemlist += "\"" + item[3].to_s + "\" " end end command = option_string() + "--radiolist \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " + listheight.to_i.to_s + " " + itemlist + "2> " + tmp.path success = system(command) if success selected_string = tmp.readline tmp.close! return selected_string else tmp.close! return success end end |
#textbox(file, type = "text", height = 0, width = 0) ⇒ Object
The textbox method handles three similar dialog functions, textbox,
tailbox, and tailboxbg. They are activated by setting type to
"text", "tail", and "bg" respectively
Textbox mode:
A text box lets you display the contents of a text file in a dialog box. It is like a simple text file viewer. The user can move through the file by using the cursor, PGUP/PGDN and HOME/END keys available on most keyboards. If the lines are too long to be displayed in the box, the LEFT/RIGHT keys can be used to scroll the text region horizontally. You may also use vi-style keys h, j, k, l in place of the cursor keys, and B or N in place of the pageup/pagedown keys. Scroll up/down using vi-style ‘k’ and ‘j’, or arrow-keys. Scroll left/right using vi-style ‘h’ and ‘l’, or arrow-keys. A ‘0’ resets the left/right scrolling. For more convenience, vi-style forward and backward searching functions are also provided.
Tailbox mode:
Display text from a file in a dialog box, as in a “tail -f” command. Scroll left/right using vi-style ‘h’ and ‘l’, or arrow-keys. A ‘0’ resets the scrolling.
Tailboxbg mode:
Display text from a file in a dialog box as a background task, as in a “tail -f &” command. Scroll left/right using vi-style ‘h’ and ‘l’, or arrow-keys. A ‘0’ resets the scrolling.
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/rdialog.rb', line 418 def textbox(file, type="text", height=0, width=0) case type when "text" opt = "--textbox" when "tail" opt = "--tailbox" when "bg" opt = "--textboxbg" end command = option_string() + opt +" \"" + file.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " success = system(command) return success end |
#timebox(file, type = "text", height = 0, width = 0, time = Time.now) ⇒ Object
On exit, a Time object is returned.
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/rdialog.rb', line 445 def timebox(file, type="text", height=0, width=0, time=Time.now) tmp = Tempfile.new('tmp') command = option_string() + "--timebox \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " + time.hour.to_s + " " + time.min.to_s + " " + time.sec.to_s + " 2> " + tmp.path success = system(command) if success time = Time.parse(tmp.readline) tmp.close! return time else tmp.close! return success end end |
#yesno(text = "Please enter some text", height = 0, width = 0) ⇒ Object
A yes/no dialog box of size height rows by width columns will
be displayed. The string specified by text is displayed inside
the dialog box. If this string is too long to fit in one line,
it will be automatically divided into multiple lines at appro-
priate places. The text string can also contain the sub-string
"\n" or newline characters '\n' to control line breaking
explicitly. This dialog box is useful for asking questions
that require the user to answer either yes or no. The dialog
box has a Yes button and a No button, in which the user can
switch between by pressing the TAB key.
514 515 516 517 518 519 520 |
# File 'lib/rdialog.rb', line 514 def yesno(text="Please enter some text", height=0, width=0) command = option_string() + "--inputbox \"" + text.to_s + "\" " + height.to_i.to_s + " " + width.to_i.to_s success = system(command) return success end |