rdialog-ng 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.rdoc +11 -0
- data/VERSION +1 -0
- data/lib/rdialog-ng/rdialog-ng.rb +624 -0
- data/lib/rdialog-ng/version.rb +10 -0
- data/lib/rdialog-ng.rb +4 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec8b8d6b054f9ca4e548a65a2cc88ee15ee41315
|
4
|
+
data.tar.gz: 040ad212aa56544651cfd86df8fcaad71ab50740
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94cd922d9bcdb07544529b51c0667e6f27c54695d6283810a062fb269938b770e62b6cedb91b0f3b7b9d338c7e9958fce4816cfd5b68ecc547e92478a8b6fea3
|
7
|
+
data.tar.gz: 9b8d988e621aef5263d19114167808024e4eb71687060645aab45059d95acb5fc65a6ad5a3fbe8d3fc41d7868548ed167344101773c003d363a64e8813d696c1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2016 Jan-Frederik Rieckers
|
2
|
+
Copyright (c) 2009 Matt Scilipoti
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
= rdialog-ng
|
2
|
+
|
3
|
+
A gem providing a ruby interface to the n-curses dialog generator: dialog.
|
4
|
+
|
5
|
+
== Credits
|
6
|
+
|
7
|
+
This gem was developed by Matt Scilipoti, Lucas Vieira and Aleks Clark. This fork just adds some bugfixes and extra functionality I needed for a special scenario.
|
8
|
+
|
9
|
+
== Copyright
|
10
|
+
|
11
|
+
Copyright (c) 2016 Jan-Frederik Rieckers. See LICENSE for details.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,624 @@
|
|
1
|
+
|
2
|
+
# vim:ts=4:sw=4:
|
3
|
+
# = rdialog-ng - A dialog gem for Ruby
|
4
|
+
#
|
5
|
+
# Homepage:: https://github.com/Janfred/rdialog-ng
|
6
|
+
# Author:: Jan-Frederik Rieckers
|
7
|
+
# Copyright:: (cc) 2016 Jan-Frederik Rieckers
|
8
|
+
# License:: MIT
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'tempfile'
|
12
|
+
require 'date'
|
13
|
+
class RDialogNG
|
14
|
+
# All accessors are boolean unless otherwise noted.
|
15
|
+
#
|
16
|
+
|
17
|
+
#
|
18
|
+
# This gives you some control over the box dimensions when
|
19
|
+
# using auto sizing (specifying 0 for height and width).
|
20
|
+
# It represents width / height. The default is 9,
|
21
|
+
# which means 9 characters wide to every 1 line high.
|
22
|
+
#
|
23
|
+
attr_accessor :aspect
|
24
|
+
|
25
|
+
#
|
26
|
+
# Specifies a backtitle string to be displayed on the backdrop,
|
27
|
+
# at the top of the screen.
|
28
|
+
#
|
29
|
+
attr_accessor :backtitle
|
30
|
+
|
31
|
+
#
|
32
|
+
# Sound the audible alarm each time the screen is refreshed.
|
33
|
+
#
|
34
|
+
attr_accessor :beep
|
35
|
+
|
36
|
+
#
|
37
|
+
# Specify the position of the upper left corner of a dialog box
|
38
|
+
# on the screen, as an array containing two integers.
|
39
|
+
#
|
40
|
+
attr_accessor :begin
|
41
|
+
|
42
|
+
#
|
43
|
+
#Override the label used for "Cancel" buttons.
|
44
|
+
#
|
45
|
+
attr_accessor :cancellabel
|
46
|
+
|
47
|
+
#
|
48
|
+
# Interpret embedded newlines in the dialog text as a newline
|
49
|
+
# on the screen. Otherwise, dialog will only wrap lines where
|
50
|
+
# needed to fit inside the text box. Even though you can control
|
51
|
+
# line breaks with this, dialog will still wrap any lines that are
|
52
|
+
# too long for the width of the box. Without cr-wrap, the layout
|
53
|
+
# of your text may be formatted to look nice in the source code of
|
54
|
+
# your script without affecting the way it will look in the dialog.
|
55
|
+
#
|
56
|
+
attr_accessor :crwrap
|
57
|
+
|
58
|
+
#
|
59
|
+
# Interpret the tags data for checklist, radiolist and menuboxes
|
60
|
+
# adding a column which is displayed in the bottom line of the
|
61
|
+
# screen, for the currently selected item.
|
62
|
+
#
|
63
|
+
attr_accessor :itemhelp
|
64
|
+
|
65
|
+
#
|
66
|
+
# Suppress the "Cancel" button in checklist, inputbox and menubox
|
67
|
+
# modes. A script can still test if the user pressed the ESC key to
|
68
|
+
# cancel to quit.
|
69
|
+
#
|
70
|
+
attr_accessor :nocancel
|
71
|
+
|
72
|
+
#
|
73
|
+
#Override the label used for "Ok" buttons.
|
74
|
+
#
|
75
|
+
attr_accessor :oklabel
|
76
|
+
|
77
|
+
#
|
78
|
+
# Draw a shadow to the right and bottom of each dialog box.
|
79
|
+
#
|
80
|
+
attr_accessor :shadow
|
81
|
+
|
82
|
+
#
|
83
|
+
# Sleep (delay) for the given integer of seconds after processing
|
84
|
+
# a dialog box.
|
85
|
+
#
|
86
|
+
attr_accessor :sleep
|
87
|
+
|
88
|
+
#
|
89
|
+
# Convert each tab character to one or more spaces.
|
90
|
+
# Otherwise, tabs are rendered according to the curses library's
|
91
|
+
# interpretation.
|
92
|
+
#
|
93
|
+
attr_accessor :tabcorrect
|
94
|
+
|
95
|
+
#
|
96
|
+
# Specify the number(int) of spaces that a tab character occupies
|
97
|
+
# if the tabcorrect option is set true. The default is 8.
|
98
|
+
#
|
99
|
+
attr_accessor :tablen
|
100
|
+
|
101
|
+
#
|
102
|
+
# Specify the timeout in secs
|
103
|
+
# Timeout (exit with error code) if no user response within the given number of seconds.
|
104
|
+
# This is overridden if the background "--tailboxbg is used.
|
105
|
+
# A timeout of zero seconds is ignored.
|
106
|
+
#
|
107
|
+
attr_accessor :timeout
|
108
|
+
|
109
|
+
#
|
110
|
+
# Title string to be displayed at the top of the dialog box.
|
111
|
+
#
|
112
|
+
attr_accessor :title
|
113
|
+
|
114
|
+
#
|
115
|
+
# Alternate path to dialog. If this is not set, environment path
|
116
|
+
# is used.
|
117
|
+
attr_accessor :path_to_dialog
|
118
|
+
|
119
|
+
# Returns a new RDialog Object
|
120
|
+
|
121
|
+
def initialize()
|
122
|
+
end
|
123
|
+
# A calendar box displays month, day and year in separately
|
124
|
+
# adjustable windows. If the values for day, month or year are
|
125
|
+
# missing or negative, the current date's corresponding values
|
126
|
+
# are used. You can increment or decrement any of those using
|
127
|
+
# the left-, up-, right- and down-arrows. Use vi-style h, j, k
|
128
|
+
# and l for moving around the array of days in a month. Use tab
|
129
|
+
# or backtab to move between windows. If the year is given as
|
130
|
+
# zero, the current date is used as an initial value.
|
131
|
+
#
|
132
|
+
# Returns a Date object with the selected date
|
133
|
+
|
134
|
+
def calendar(text="Select a Date", height=0, width=0, day=Date.today.mday(), month=Date.today.mon(), year=Date.today.year())
|
135
|
+
|
136
|
+
tmp = Tempfile.new('tmp')
|
137
|
+
|
138
|
+
command = option_string() + "--calendar \"" + text.to_s +
|
139
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " " +
|
140
|
+
day.to_i.to_s + " " + month.to_i.to_s + " " + year.to_i.to_s +
|
141
|
+
" 2> " + tmp.path
|
142
|
+
success = system(command)
|
143
|
+
if success
|
144
|
+
date = Date::civil(*tmp.readline.split('/').collect {|i| i.to_i}.reverse)
|
145
|
+
tmp.close!
|
146
|
+
return date
|
147
|
+
else
|
148
|
+
tmp.close!
|
149
|
+
return success
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
# A checklist box is similar to a menu box; there are multiple
|
155
|
+
# entries presented in the form of a menu. Instead of choosing
|
156
|
+
# one entry among the entries, each entry can be turned on or off
|
157
|
+
# by the user. The initial on/off state of each entry is speci-
|
158
|
+
# fied by status.
|
159
|
+
|
160
|
+
def checklist(text, items, height=0, width=0, listheight=0)
|
161
|
+
|
162
|
+
tmp = Tempfile.new('tmp')
|
163
|
+
|
164
|
+
itemlist = String.new
|
165
|
+
|
166
|
+
for item in items
|
167
|
+
if item[2]
|
168
|
+
item[2] = "on"
|
169
|
+
else
|
170
|
+
item[2] = "off"
|
171
|
+
end
|
172
|
+
itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s +
|
173
|
+
"\" " + item[2] + " "
|
174
|
+
|
175
|
+
if @itemhelp
|
176
|
+
itemlist += "\"" + item[3].to_s + "\" "
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
command = option_string() + "--checklist \"" + text.to_s +
|
181
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s +
|
182
|
+
" " + listheight.to_i.to_s + " " + itemlist + "2> " +
|
183
|
+
tmp.path
|
184
|
+
puts command
|
185
|
+
success = system(command)
|
186
|
+
puts success
|
187
|
+
if success
|
188
|
+
selected_string = tmp.readline
|
189
|
+
tmp.close!
|
190
|
+
selected_string.slice!(0)
|
191
|
+
selected_string.chomp!("\"")
|
192
|
+
selected_array = selected_string.split('" "')
|
193
|
+
for item in selected_array
|
194
|
+
item.delete!("\\")
|
195
|
+
end
|
196
|
+
|
197
|
+
return selected_array
|
198
|
+
else
|
199
|
+
tmp.close!
|
200
|
+
return success
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
# The file-selection dialog displays a text-entry window in which
|
206
|
+
# you can type a filename (or directory), and above that two win-
|
207
|
+
# dows with directory names and filenames.
|
208
|
+
|
209
|
+
# Here filepath can be a filepath in which case the file and
|
210
|
+
# directory windows will display the contents of the path and the
|
211
|
+
# text-entry window will contain the preselected filename.
|
212
|
+
#
|
213
|
+
# Use tab or arrow keys to move between the windows. Within the
|
214
|
+
# directory or filename windows, use the up/down arrow keys to
|
215
|
+
# scroll the current selection. Use the space-bar to copy the
|
216
|
+
# current selection into the text-entry window.
|
217
|
+
#
|
218
|
+
# Typing any printable characters switches focus to the text-
|
219
|
+
# entry window, entering that character as well as scrolling the
|
220
|
+
# directory and filename windows to the closest match.
|
221
|
+
#
|
222
|
+
# Use a carriage return or the "OK" button to accept the current
|
223
|
+
# value in the text-entry window and exit.
|
224
|
+
|
225
|
+
def fselect(path, height=0, width=0)
|
226
|
+
tmp = Tempfile.new('tmp')
|
227
|
+
|
228
|
+
command = option_string() + "--fselect \"" + path.to_s +
|
229
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
230
|
+
|
231
|
+
command += "2> " + tmp.path
|
232
|
+
|
233
|
+
success = system(command)
|
234
|
+
|
235
|
+
if success
|
236
|
+
begin
|
237
|
+
selected_string = tmp.readline
|
238
|
+
rescue EOFError
|
239
|
+
selected_string = ""
|
240
|
+
end
|
241
|
+
tmp.close!
|
242
|
+
return selected_string
|
243
|
+
else
|
244
|
+
tmp.close!
|
245
|
+
return success
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# A gauge is basically an info box with showing of a percentage value,
|
250
|
+
# given as the second parameter in the range from 0 to 100
|
251
|
+
|
252
|
+
def gauge(text, value, height=0, width=0)
|
253
|
+
begin
|
254
|
+
intval = value.to_i
|
255
|
+
rescue
|
256
|
+
return false
|
257
|
+
end
|
258
|
+
|
259
|
+
command = option_string() + "--gauge \""+text.to_s+"\" " + height.to_i.to_s + " " + width.to_i.to_s + " 0"
|
260
|
+
|
261
|
+
success = system("echo #{intval} | "+command)
|
262
|
+
|
263
|
+
return success
|
264
|
+
end
|
265
|
+
|
266
|
+
# An info box is basically a message box. However, in this case,
|
267
|
+
# dialog will exit immediately after displaying the message to
|
268
|
+
# the user. The screen is not cleared when dialog exits, so that
|
269
|
+
# the message will remain on the screen until the calling shell
|
270
|
+
# script clears it later. This is useful when you want to inform
|
271
|
+
# the user that some operations are carrying on that may require
|
272
|
+
# some time to finish.
|
273
|
+
#
|
274
|
+
# Returns false if esc was pushed
|
275
|
+
|
276
|
+
def infobox(text, height=0, width=0)
|
277
|
+
command = option_string() + "--infobox \"" + text.to_s +
|
278
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
279
|
+
success = system(command)
|
280
|
+
return success
|
281
|
+
end
|
282
|
+
|
283
|
+
# A radiolist box is similar to a menu box. The only difference
|
284
|
+
# is that you can indicate which entry is currently selected, by
|
285
|
+
# setting its status to true.
|
286
|
+
|
287
|
+
def radiolist(text, items, height=0, width=0, listheight=0)
|
288
|
+
|
289
|
+
tmp = Tempfile.new('tmp')
|
290
|
+
|
291
|
+
itemlist = String.new
|
292
|
+
|
293
|
+
for item in items
|
294
|
+
if item[2]
|
295
|
+
item[2] = "on"
|
296
|
+
else
|
297
|
+
item[2] = "off"
|
298
|
+
end
|
299
|
+
itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s +
|
300
|
+
"\" " + item[2] + " "
|
301
|
+
|
302
|
+
if @itemhelp
|
303
|
+
itemlist += "\"" + item[3].to_s + "\" "
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
command = option_string() + "--radiolist \"" + text.to_s +
|
308
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s +
|
309
|
+
" " + listheight.to_i.to_s + " " + itemlist + "2> " +
|
310
|
+
tmp.path
|
311
|
+
success = system(command)
|
312
|
+
|
313
|
+
if success
|
314
|
+
selected_string = tmp.readline
|
315
|
+
tmp.close!
|
316
|
+
return selected_string
|
317
|
+
else
|
318
|
+
close!
|
319
|
+
return success
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
# As its name suggests, a menu box is a dialog box that can be
|
325
|
+
# used to present a list of choices in the form of a menu for the
|
326
|
+
# user to choose. Choices are displayed in the order given.
|
327
|
+
# Each menu entry consists of a tag string and an item string.
|
328
|
+
# The tag gives the entry a name to distinguish it from the other
|
329
|
+
# entries in the menu. The item is a short description of the
|
330
|
+
# option that the entry represents. The user can move between
|
331
|
+
# the menu entries by pressing the cursor keys, the first letter
|
332
|
+
# of the tag as a hot-key, or the number keys 1-9. There are
|
333
|
+
# menu-height entries displayed in the menu at one time, but the
|
334
|
+
# menu will be scrolled if there are more entries than that.
|
335
|
+
#
|
336
|
+
# Returns a string containing the tag of the chosen menu entry.
|
337
|
+
|
338
|
+
def menu(text="Text Goes Here", items=nil, height=0, width=0, listheight=0)
|
339
|
+
tmp = Tempfile.new('tmp')
|
340
|
+
|
341
|
+
itemlist = String.new
|
342
|
+
|
343
|
+
for item in items
|
344
|
+
itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s + "\" "
|
345
|
+
|
346
|
+
if @itemhelp
|
347
|
+
itemlist += "\"" + item[2].to_s + "\" "
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
command = option_string() + "--menu \"" + text.to_s +
|
352
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s +
|
353
|
+
" " + listheight.to_i.to_s + " " + itemlist + "2> " +
|
354
|
+
tmp.path
|
355
|
+
success = system(command)
|
356
|
+
|
357
|
+
if success
|
358
|
+
selected_string = tmp.readline
|
359
|
+
tmp.close!
|
360
|
+
return selected_string
|
361
|
+
else
|
362
|
+
tmp.close!
|
363
|
+
return success
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
# A message box is very similar to a yes/no box. The only dif-
|
369
|
+
# ference between a message box and a yes/no box is that a mes-
|
370
|
+
# sage box has only a single OK button. You can use this dialog
|
371
|
+
# box to display any message you like. After reading the mes-
|
372
|
+
# sage, the user can press the ENTER key so that dialog will exit
|
373
|
+
# and the calling shell script can continue its operation.
|
374
|
+
|
375
|
+
def msgbox(text="Text Goes Here", height=0, width=0)
|
376
|
+
command = option_string() + "--msgbox \"" + text.to_s +
|
377
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
378
|
+
|
379
|
+
success = system(command)
|
380
|
+
return success
|
381
|
+
end
|
382
|
+
|
383
|
+
# A password box is similar to an input box, except that the text
|
384
|
+
# the user enters is not displayed. This is useful when prompt-
|
385
|
+
# ing for passwords or other sensitive information. Be aware
|
386
|
+
# that if anything is passed in "init", it will be visible in the
|
387
|
+
# system's process table to casual snoopers. Also, it is very
|
388
|
+
# confusing to the user to provide them with a default password
|
389
|
+
# they cannot see. For these reasons, using "init" is highly
|
390
|
+
# discouraged.
|
391
|
+
|
392
|
+
def passwordbox(text="Please enter some text", height=0, width=0, init="")
|
393
|
+
tmp = Tempfile.new('tmp')
|
394
|
+
command = option_string() + "--passwordbox \"" + text.to_s +
|
395
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
396
|
+
|
397
|
+
unless init.empty?
|
398
|
+
command += init.to_s + " "
|
399
|
+
end
|
400
|
+
|
401
|
+
command += "2> " + tmp.path
|
402
|
+
|
403
|
+
success = system(command)
|
404
|
+
|
405
|
+
if success
|
406
|
+
begin
|
407
|
+
selected_string = tmp.readline
|
408
|
+
rescue EOFError
|
409
|
+
selected_string = ""
|
410
|
+
end
|
411
|
+
tmp.close!
|
412
|
+
return selected_string
|
413
|
+
else
|
414
|
+
tmp.close!
|
415
|
+
return success
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
# The textbox method handles three similar dialog functions, textbox,
|
420
|
+
# tailbox, and tailboxbg. They are activated by setting type to
|
421
|
+
# "text", "tail", and "bg" respectively
|
422
|
+
#
|
423
|
+
# Textbox mode:
|
424
|
+
# A text box lets you display the contents of a text file in a
|
425
|
+
# dialog box. It is like a simple text file viewer. The user
|
426
|
+
# can move through the file by using the cursor, PGUP/PGDN and
|
427
|
+
# HOME/END keys available on most keyboards. If the lines are
|
428
|
+
# too long to be displayed in the box, the LEFT/RIGHT keys can be
|
429
|
+
# used to scroll the text region horizontally. You may also use
|
430
|
+
# vi-style keys h, j, k, l in place of the cursor keys, and B or
|
431
|
+
# N in place of the pageup/pagedown keys. Scroll up/down using
|
432
|
+
# vi-style 'k' and 'j', or arrow-keys. Scroll left/right using
|
433
|
+
# vi-style 'h' and 'l', or arrow-keys. A '0' resets the
|
434
|
+
# left/right scrolling. For more convenience, vi-style forward
|
435
|
+
# and backward searching functions are also provided.
|
436
|
+
#
|
437
|
+
# Tailbox mode:
|
438
|
+
# Display text from a file in a dialog box, as in a "tail -f"
|
439
|
+
# command. Scroll left/right using vi-style 'h' and 'l', or
|
440
|
+
# arrow-keys. A '0' resets the scrolling.
|
441
|
+
#
|
442
|
+
# Tailboxbg mode:
|
443
|
+
# Display text from a file in a dialog box as a background task,
|
444
|
+
# as in a "tail -f &" command. Scroll left/right using vi-style
|
445
|
+
# 'h' and 'l', or arrow-keys. A '0' resets the scrolling.
|
446
|
+
|
447
|
+
def textbox(file, type="text", height=0, width=0)
|
448
|
+
case type
|
449
|
+
when "text"
|
450
|
+
opt = "--textbox"
|
451
|
+
when "tail"
|
452
|
+
opt = "--tailbox"
|
453
|
+
when "bg"
|
454
|
+
opt = "--textboxbg"
|
455
|
+
when "edit"
|
456
|
+
opt = "--editbox"
|
457
|
+
end
|
458
|
+
|
459
|
+
command = option_string() + opt +" \"" + file.to_s +
|
460
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
461
|
+
|
462
|
+
success = system(command)
|
463
|
+
|
464
|
+
return success
|
465
|
+
end
|
466
|
+
|
467
|
+
# A dialog is displayed which allows you to select hour, minute
|
468
|
+
# and second. If the values for hour, minute or second are miss-
|
469
|
+
# ing or negative, the current date's corresponding values are
|
470
|
+
# used. You can increment or decrement any of those using the
|
471
|
+
# left-, up-, right- and down-arrows. Use tab or backtab to move
|
472
|
+
# between windows.
|
473
|
+
#
|
474
|
+
# On exit, a Time object is returned.
|
475
|
+
|
476
|
+
def timebox(file, type="text", height=0, width=0, time=Time.now)
|
477
|
+
tmp = Tempfile.new('tmp')
|
478
|
+
|
479
|
+
command = option_string() + "--timebox \"" + text.to_s +
|
480
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " " +
|
481
|
+
time.hour.to_s + " " + time.min.to_s + " " +
|
482
|
+
time.sec.to_s + " 2> " + tmp.path
|
483
|
+
success = system(command)
|
484
|
+
if success
|
485
|
+
time = Time.parse(tmp.readline)
|
486
|
+
tmp.close!
|
487
|
+
return time
|
488
|
+
else
|
489
|
+
tmp.close!
|
490
|
+
return success
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|
494
|
+
|
495
|
+
# An input box is useful when you want to ask questions that
|
496
|
+
# require the user to input a string as the answer. If init is
|
497
|
+
# supplied it is used to initialize the input string. When
|
498
|
+
# entering the string, the backspace, delete and cursor keys can
|
499
|
+
# be used to correct typing errors. If the input string is
|
500
|
+
# longer than can fit in the dialog box, the input field will be
|
501
|
+
# scrolled.
|
502
|
+
#
|
503
|
+
# On exit, the input string will be returned.
|
504
|
+
|
505
|
+
|
506
|
+
def inputbox(text="Please enter some text", height=0, width=0, init="")
|
507
|
+
tmp = Tempfile.new('tmp')
|
508
|
+
|
509
|
+
command = option_string() + "--inputbox \"" + text.to_s +
|
510
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
|
511
|
+
|
512
|
+
unless init.empty?
|
513
|
+
command += init.to_s + " "
|
514
|
+
end
|
515
|
+
|
516
|
+
command += "2> " + tmp.path
|
517
|
+
|
518
|
+
success = system(command)
|
519
|
+
|
520
|
+
if success
|
521
|
+
begin
|
522
|
+
selected_string = tmp.readline
|
523
|
+
rescue EOFError
|
524
|
+
selected_string = ""
|
525
|
+
end
|
526
|
+
tmp.close!
|
527
|
+
return selected_string
|
528
|
+
else
|
529
|
+
tmp.close!
|
530
|
+
return success
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
# A yes/no dialog box of size height rows by width columns will
|
535
|
+
# be displayed. The string specified by text is displayed inside
|
536
|
+
# the dialog box. If this string is too long to fit in one line,
|
537
|
+
# it will be automatically divided into multiple lines at appro-
|
538
|
+
# priate places. The text string can also contain the sub-string
|
539
|
+
# "\n" or newline characters '\n' to control line breaking
|
540
|
+
# explicitly. This dialog box is useful for asking questions
|
541
|
+
# that require the user to answer either yes or no. The dialog
|
542
|
+
# box has a Yes button and a No button, in which the user can
|
543
|
+
# switch between by pressing the TAB key.
|
544
|
+
|
545
|
+
def yesno(text="Please enter some text", height=0, width=0)
|
546
|
+
command = option_string() + "--yesno \"" + text.to_s +
|
547
|
+
"\" " + height.to_i.to_s + " " + width.to_i.to_s
|
548
|
+
|
549
|
+
success = system(command)
|
550
|
+
return success
|
551
|
+
end
|
552
|
+
|
553
|
+
private
|
554
|
+
|
555
|
+
def option_string()
|
556
|
+
unless @path_to_dialog
|
557
|
+
ostring = "dialog "
|
558
|
+
else
|
559
|
+
ostring = @path_to_dialog + " "
|
560
|
+
end
|
561
|
+
if @aspect
|
562
|
+
ostring += "--aspect " + aspect + " "
|
563
|
+
end
|
564
|
+
|
565
|
+
if @beep
|
566
|
+
ostring += "--beep "
|
567
|
+
end
|
568
|
+
|
569
|
+
if @boxbegin
|
570
|
+
ostring += "--begin " + @boxbegin[0] + @boxbegin[1] + " "
|
571
|
+
end
|
572
|
+
|
573
|
+
if @backtitle
|
574
|
+
ostring += "--backtitle \"" + @backtitle + "\" "
|
575
|
+
end
|
576
|
+
|
577
|
+
if @cancellabel
|
578
|
+
ostring += "--cancel-label \"" + @cancellabel + "\" "
|
579
|
+
end
|
580
|
+
|
581
|
+
if @oklabel
|
582
|
+
ostring += "--ok-label \"" + @oklabel + "\" "
|
583
|
+
end
|
584
|
+
|
585
|
+
if @itemhelp
|
586
|
+
ostring += "--item-help "
|
587
|
+
end
|
588
|
+
|
589
|
+
unless @shadow == nil
|
590
|
+
if @shadow == true
|
591
|
+
ostring += "--shadow "
|
592
|
+
else
|
593
|
+
ostring += "--no-shadow "
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
if @sleep
|
598
|
+
ostring += "--sleep " + @sleep.to_s + " "
|
599
|
+
end
|
600
|
+
|
601
|
+
if @tabcorrect
|
602
|
+
ostring += "--tab-correct "
|
603
|
+
end
|
604
|
+
|
605
|
+
if @tablen
|
606
|
+
ostring += "--tab-len " + @tablen.to_i + " "
|
607
|
+
end
|
608
|
+
|
609
|
+
if @timeout
|
610
|
+
ostring += "--timeout " + @timeout.to_s + " "
|
611
|
+
end
|
612
|
+
|
613
|
+
if @title
|
614
|
+
ostring += "--title \"" + @title.to_s + "\" "
|
615
|
+
end
|
616
|
+
|
617
|
+
if @nocancel
|
618
|
+
ostring += "--nocancel "
|
619
|
+
end
|
620
|
+
|
621
|
+
return ostring
|
622
|
+
|
623
|
+
end
|
624
|
+
end
|
data/lib/rdialog-ng.rb
ADDED
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdialog-ng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aleks Clark
|
8
|
+
- Matt Scilipoti
|
9
|
+
- Lucas Vieira
|
10
|
+
- Jan-Frederik Rieckers
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
15
|
+
dependencies: []
|
16
|
+
description: A gem providing a ruby interface to the n-curses dialog generator - 'dialog'.
|
17
|
+
email: rubygem@rieckers.it
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files:
|
21
|
+
- LICENSE
|
22
|
+
- README.rdoc
|
23
|
+
files:
|
24
|
+
- LICENSE
|
25
|
+
- README.rdoc
|
26
|
+
- VERSION
|
27
|
+
- lib/rdialog-ng.rb
|
28
|
+
- lib/rdialog-ng/rdialog-ng.rb
|
29
|
+
- lib/rdialog-ng/version.rb
|
30
|
+
homepage: https://github.com/rieckers/rdialog-ng
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.2.2
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: A gem providing a ruby interface to the n-curses dialog generator - 'dialog'.
|
53
|
+
test_files: []
|