rbhex-core 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/CHANGELOG +2000 -0
- data/LICENSE +56 -0
- data/README.md +44 -0
- data/examples/abasiclist.rb +179 -0
- data/examples/alpmenu.rb +50 -0
- data/examples/app.sample +19 -0
- data/examples/atree.rb +100 -0
- data/examples/bline.rb +136 -0
- data/examples/common/file.rb +45 -0
- data/examples/data/README.markdown +9 -0
- data/examples/data/brew.txt +38 -0
- data/examples/data/color.2 +37 -0
- data/examples/data/gemlist.txt +60 -0
- data/examples/data/lotr.txt +12 -0
- data/examples/data/ports.txt +136 -0
- data/examples/data/table.txt +37 -0
- data/examples/data/tasks.csv +88 -0
- data/examples/data/tasks.txt +27 -0
- data/examples/data/todo.txt +10 -0
- data/examples/data/todo.txt.bak +10 -0
- data/examples/data/todocsv.csv +28 -0
- data/examples/data/unix1.txt +21 -0
- data/examples/data/unix2.txt +11 -0
- data/examples/dbdemo.rb +502 -0
- data/examples/dirtree.rb +94 -0
- data/examples/newtabbedwindow.rb +100 -0
- data/examples/newtesttabp.rb +92 -0
- data/examples/tabular.rb +146 -0
- data/examples/tasks.rb +178 -0
- data/examples/term2.rb +84 -0
- data/examples/testbuttons.rb +296 -0
- data/examples/testcombo.rb +102 -0
- data/examples/testfields.rb +195 -0
- data/examples/testkeypress.rb +72 -0
- data/examples/testlistbox.rb +170 -0
- data/examples/testmessagebox.rb +140 -0
- data/examples/testprogress.rb +116 -0
- data/examples/testree.rb +106 -0
- data/examples/testwsshortcuts.rb +66 -0
- data/examples/testwsshortcuts2.rb +128 -0
- data/lib/rbhex.rb +6 -0
- data/lib/rbhex/core/docs/index.txt +73 -0
- data/lib/rbhex/core/include/action.rb +80 -0
- data/lib/rbhex/core/include/actionmanager.rb +49 -0
- data/lib/rbhex/core/include/appmethods.rb +214 -0
- data/lib/rbhex/core/include/bordertitle.rb +48 -0
- data/lib/rbhex/core/include/chunk.rb +203 -0
- data/lib/rbhex/core/include/io.rb +553 -0
- data/lib/rbhex/core/include/listbindings.rb +74 -0
- data/lib/rbhex/core/include/listcellrenderer.rb +140 -0
- data/lib/rbhex/core/include/listeditable.rb +317 -0
- data/lib/rbhex/core/include/listscrollable.rb +663 -0
- data/lib/rbhex/core/include/listselectable.rb +271 -0
- data/lib/rbhex/core/include/multibuffer.rb +83 -0
- data/lib/rbhex/core/include/orderedhash.rb +77 -0
- data/lib/rbhex/core/include/ractionevent.rb +73 -0
- data/lib/rbhex/core/include/rchangeevent.rb +27 -0
- data/lib/rbhex/core/include/rhistory.rb +95 -0
- data/lib/rbhex/core/include/rinputdataevent.rb +47 -0
- data/lib/rbhex/core/include/vieditable.rb +172 -0
- data/lib/rbhex/core/include/widgetmenu.rb +66 -0
- data/lib/rbhex/core/system/colormap.rb +165 -0
- data/lib/rbhex/core/system/keyboard.rb +150 -0
- data/lib/rbhex/core/system/keydefs.rb +30 -0
- data/lib/rbhex/core/system/ncurses.rb +236 -0
- data/lib/rbhex/core/system/panel.rb +162 -0
- data/lib/rbhex/core/system/window.rb +913 -0
- data/lib/rbhex/core/util/ansiparser.rb +119 -0
- data/lib/rbhex/core/util/app.rb +1228 -0
- data/lib/rbhex/core/util/basestack.rb +410 -0
- data/lib/rbhex/core/util/bottomline.rb +1859 -0
- data/lib/rbhex/core/util/colorparser.rb +77 -0
- data/lib/rbhex/core/util/focusmanager.rb +31 -0
- data/lib/rbhex/core/util/padreader.rb +192 -0
- data/lib/rbhex/core/util/rcommandwindow.rb +604 -0
- data/lib/rbhex/core/util/rdialogs.rb +574 -0
- data/lib/rbhex/core/util/viewer.rb +149 -0
- data/lib/rbhex/core/util/widgetshortcuts.rb +506 -0
- data/lib/rbhex/core/version.rb +5 -0
- data/lib/rbhex/core/widgets/applicationheader.rb +103 -0
- data/lib/rbhex/core/widgets/box.rb +58 -0
- data/lib/rbhex/core/widgets/divider.rb +310 -0
- data/lib/rbhex/core/widgets/keylabelprinter.rb +194 -0
- data/lib/rbhex/core/widgets/rcombo.rb +253 -0
- data/lib/rbhex/core/widgets/rcontainer.rb +415 -0
- data/lib/rbhex/core/widgets/rlink.rb +30 -0
- data/lib/rbhex/core/widgets/rlist.rb +696 -0
- data/lib/rbhex/core/widgets/rmenu.rb +958 -0
- data/lib/rbhex/core/widgets/rmenulink.rb +22 -0
- data/lib/rbhex/core/widgets/rmessagebox.rb +387 -0
- data/lib/rbhex/core/widgets/rprogress.rb +118 -0
- data/lib/rbhex/core/widgets/rtabbedpane.rb +634 -0
- data/lib/rbhex/core/widgets/rtabbedwindow.rb +70 -0
- data/lib/rbhex/core/widgets/rtextarea.rb +960 -0
- data/lib/rbhex/core/widgets/rtextview.rb +739 -0
- data/lib/rbhex/core/widgets/rtree.rb +768 -0
- data/lib/rbhex/core/widgets/rwidget.rb +3277 -0
- data/lib/rbhex/core/widgets/scrollbar.rb +143 -0
- data/lib/rbhex/core/widgets/statusline.rb +113 -0
- data/lib/rbhex/core/widgets/tabular.rb +264 -0
- data/lib/rbhex/core/widgets/tabularwidget.rb +1142 -0
- data/lib/rbhex/core/widgets/textpad.rb +995 -0
- data/lib/rbhex/core/widgets/tree/treecellrenderer.rb +150 -0
- data/lib/rbhex/core/widgets/tree/treemodel.rb +428 -0
- data/rbhex-core.gemspec +32 -0
- metadata +172 -0
@@ -0,0 +1,574 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: dialogs so user can do basic stuff in one line.
|
3
|
+
* Description:
|
4
|
+
* Author: rkumar
|
5
|
+
|
6
|
+
--------
|
7
|
+
* Date: 2008-12-30 12:22
|
8
|
+
* 2011-10-1 : moving print_error and print_status methods here as alternatives
|
9
|
+
to alert and confirm. Anyone who has included those will get these.
|
10
|
+
And this file is included in the base file.
|
11
|
+
|
12
|
+
Shucks, this file has no module. It's bare !
|
13
|
+
* License:
|
14
|
+
Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
15
|
+
|
16
|
+
# CHANGES:
|
17
|
+
# -- moving to the new Messagebox 2011-11-19 v 1.5.0
|
18
|
+
TODO:
|
19
|
+
Add select_one (message, values, default)
|
20
|
+
=end
|
21
|
+
require 'rbhex/core/widgets/rwidget'
|
22
|
+
#require 'rbhex/deprecated/widgets/rmessagebox'
|
23
|
+
require 'rbhex/core/widgets/rmessagebox'
|
24
|
+
|
25
|
+
# -- moving to the new Messagebox 2011-11-19 v 1.5.0
|
26
|
+
# Alert user with a one line message
|
27
|
+
#
|
28
|
+
def alert text, config={}
|
29
|
+
|
30
|
+
if text.is_a? RubyCurses::Variable
|
31
|
+
text = text.get_value
|
32
|
+
end
|
33
|
+
_title = config[:title] || "Alert"
|
34
|
+
tp = MessageBox.new config do
|
35
|
+
title _title
|
36
|
+
button_type :ok
|
37
|
+
message text
|
38
|
+
#text mess
|
39
|
+
end
|
40
|
+
tp.run
|
41
|
+
end
|
42
|
+
|
43
|
+
# Alert user with a block of text. This will popup a textview in which the user can scroll
|
44
|
+
# Use this if you are not sure of the size of the text, such as printing a stack trace,
|
45
|
+
# exception
|
46
|
+
# 2011-12-25 just pass in an exceptino object and we do the rest
|
47
|
+
def textdialog mess, config={}
|
48
|
+
if mess.is_a? Exception
|
49
|
+
mess = [mess.to_s, *mess.backtrace]
|
50
|
+
config[:title] ||= "Exception"
|
51
|
+
end
|
52
|
+
config[:title] ||= "Alert"
|
53
|
+
tp = MessageBox.new config do
|
54
|
+
button_type :ok
|
55
|
+
text mess
|
56
|
+
end
|
57
|
+
tp.run
|
58
|
+
end
|
59
|
+
#
|
60
|
+
# This uses the new messagebox 2011-11-19 v 1.5.0
|
61
|
+
# NOTE: The earlier get_string had only an OK button, this seems to have a CANCEL
|
62
|
+
# @param [String] a label such as "Enter name:"
|
63
|
+
# @return [String] value entered by user, nil if cancel pressed
|
64
|
+
# @yield [Field] field created by messagebox
|
65
|
+
def get_string label, config={} # yield Field
|
66
|
+
config[:title] ||= "Entry"
|
67
|
+
label_config = config[:label_config] || {}
|
68
|
+
label_config[:row] ||= 2
|
69
|
+
label_config[:col] ||= 2
|
70
|
+
label_config[:text] = label
|
71
|
+
|
72
|
+
field_config = config[:field_config] || {}
|
73
|
+
field_config[:row] ||= 3
|
74
|
+
field_config[:col] ||= 2
|
75
|
+
field_config[:attr] = :reverse
|
76
|
+
field_config[:maxlen] ||= config[:maxlen]
|
77
|
+
field_config[:display_length] ||= config[:display_length]
|
78
|
+
field_config[:default] ||= config[:default]
|
79
|
+
field_config[:default] = field_config[:default].chomp if field_config[:default]
|
80
|
+
field_config[:name] = :name
|
81
|
+
#field_config[:display_length] ||= 50 # i want it to extend since i don't know the actual width
|
82
|
+
#field_config[:width] ||= 50 # i want it to extend since i don't know the actual width
|
83
|
+
field_config[:width] ||= (field_config[:display_length] || 50)
|
84
|
+
|
85
|
+
defwid = config[:default].nil? ? 30 : config[:default].size + 13
|
86
|
+
w = [label.size + 8, defwid, field_config[:width]+13 ].max
|
87
|
+
config[:width] ||= w
|
88
|
+
## added history 2013-03-06 - 14:25 : we could keep history based on prompt
|
89
|
+
$get_string_history ||= []
|
90
|
+
#$log.debug "XXX: FIELD SIZE #{w} "
|
91
|
+
#$log.debug "XXX: FIELD CONFIG #{field_config} "
|
92
|
+
tp = MessageBox.new config do
|
93
|
+
button_type :ok_cancel
|
94
|
+
default_button 0
|
95
|
+
item Label.new nil, label_config
|
96
|
+
fld = Field.new nil, field_config
|
97
|
+
item fld
|
98
|
+
## added field history 2013-03-06 - 14:24
|
99
|
+
require 'rbhex/core/include/rhistory'
|
100
|
+
fld.extend(FieldHistory)
|
101
|
+
# We need to manually set history each time, since the field is recreated
|
102
|
+
# with the messagebox. Otherwise, field can on its own handle history
|
103
|
+
fld.history($get_string_history)
|
104
|
+
end
|
105
|
+
# added yield to override settings
|
106
|
+
yield tp.form.by_name[:name] if block_given?
|
107
|
+
index = tp.run
|
108
|
+
if index == 0 # OK
|
109
|
+
## added field history 2013-03-06 - 14:24
|
110
|
+
t = tp.form.by_name[:name].text
|
111
|
+
$get_string_history << t if t && !$get_string_history.include?(t)
|
112
|
+
return t
|
113
|
+
else # CANCEL
|
114
|
+
# Should i use nil or blank. I am currently opting for nil, as this may imply to caller
|
115
|
+
# that user does not wish to override whatever value is being prompted for.
|
116
|
+
return nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
# new version using new messagebox
|
120
|
+
# @param [String] question
|
121
|
+
# @return [Boolean] true or false
|
122
|
+
# @yield [Label]
|
123
|
+
#
|
124
|
+
def confirm text, config={}, &block
|
125
|
+
title = config['title'] || "Confirm"
|
126
|
+
config[:default_button] ||= 0
|
127
|
+
|
128
|
+
mb = RubyCurses::MessageBox.new config do
|
129
|
+
title title
|
130
|
+
message text, &block
|
131
|
+
button_type :yes_no
|
132
|
+
end
|
133
|
+
index = mb.run
|
134
|
+
return index == 0
|
135
|
+
end
|
136
|
+
##
|
137
|
+
# pops up a modal box with a message and an OK button.
|
138
|
+
# No return value.
|
139
|
+
# Usage:
|
140
|
+
# alert("You did not enter anything!")
|
141
|
+
# alert("You did not enter anything!", "title"=>"Wake Up")
|
142
|
+
# alert("You did not enter anything!", {"title"=>"Wake Up", "bgcolor"=>"blue", "color"=>"white"})
|
143
|
+
# block currently ignored. don't know what to do, can't pass it to MB since alread sending in a block
|
144
|
+
#
|
145
|
+
|
146
|
+
# ------------------------ We've Moved here from window class ---------------- #
|
147
|
+
# #
|
148
|
+
# Moving some methods from window. They no longer require having a window. #
|
149
|
+
# #
|
150
|
+
# ---------------------------------------------------------------------------- #
|
151
|
+
#
|
152
|
+
#
|
153
|
+
|
154
|
+
# new version with a window created on 2011-10-1 12:37 AM
|
155
|
+
# Now can be separate from window class, needing nothing, just a util class
|
156
|
+
# prints a status message and pauses for a char
|
157
|
+
# @param [String] text to print
|
158
|
+
# @param [Hash] config: :color :bgcolor :color_pair
|
159
|
+
# :wait (numbr of seconds to wait for a key press and then close) if not givn
|
160
|
+
# will keep waiting for keypress (the default)
|
161
|
+
def print_status_message text, aconfig={}, &block
|
162
|
+
_print_message :status, text, aconfig, &block
|
163
|
+
end
|
164
|
+
alias :rb_puts print_status_message
|
165
|
+
|
166
|
+
# new version with a window created on 2011-10-1 12:30 AM
|
167
|
+
# Now can be separate from window class, needing nothing, just a util class
|
168
|
+
# @param [String] text to print
|
169
|
+
# @param [Hash] config: :color :bgcolor :color_pair
|
170
|
+
# :wait (numbr of seconds to wait for a key press and then close) if not givn
|
171
|
+
# will keep waiting for keypress (the default)
|
172
|
+
def print_error_message text, aconfig={}, &block
|
173
|
+
_print_message :error, text, aconfig, &block
|
174
|
+
end
|
175
|
+
private
|
176
|
+
def _create_footer_window h = 2 , w = Ncurses.COLS, t = Ncurses.LINES-2, l = 0 #:nodoc:
|
177
|
+
ewin = VER::Window.new(h, w , t, l)
|
178
|
+
end
|
179
|
+
# @param [:symbol] :error or :status kind of message
|
180
|
+
#private
|
181
|
+
def _print_message type, text, aconfig={}, &block #:nodoc:
|
182
|
+
case text
|
183
|
+
when RubyCurses::Variable # added 2011-09-20 incase variable passed
|
184
|
+
text = text.get_value
|
185
|
+
when Exception
|
186
|
+
text = text.to_s
|
187
|
+
end
|
188
|
+
# NOTE we are polluting global namespace
|
189
|
+
# fixed on 2011-12-6 . to test
|
190
|
+
#aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
|
191
|
+
color = aconfig[:color]
|
192
|
+
bgcolor = aconfig[:bgcolor]
|
193
|
+
ewin = _create_footer_window #*@layout
|
194
|
+
r = 0; c = 1;
|
195
|
+
case type
|
196
|
+
when :error
|
197
|
+
color ||= 'red'
|
198
|
+
bgcolor ||= 'black'
|
199
|
+
else
|
200
|
+
color ||= :white
|
201
|
+
bgcolor ||= :black
|
202
|
+
end
|
203
|
+
color_pair = get_color($promptcolor, color, bgcolor)
|
204
|
+
color_pair = aconfig[:color_pair] || color_pair
|
205
|
+
ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
|
206
|
+
ewin.printstring r, c, text, color_pair
|
207
|
+
ewin.printstring(r+1, c, "Press a key ", color_pair) unless aconfig[:wait]
|
208
|
+
ewin.wrefresh
|
209
|
+
if aconfig[:wait]
|
210
|
+
#try this out, if user wants a wait, then it will wait for 5 seconds, or if a key is pressed sooner
|
211
|
+
value = aconfig[:wait]
|
212
|
+
if value.is_a? Fixnum
|
213
|
+
value = value * 10
|
214
|
+
else
|
215
|
+
value = 50
|
216
|
+
end
|
217
|
+
Ncurses::halfdelay(tenths = value)
|
218
|
+
ewin.getch
|
219
|
+
Ncurses::halfdelay(tenths = 10)
|
220
|
+
else
|
221
|
+
ewin.getchar
|
222
|
+
end
|
223
|
+
ewin.destroy
|
224
|
+
end
|
225
|
+
#
|
226
|
+
# Alternative to confirm dialog, if you want this look and feel, at last 2 lines of screen
|
227
|
+
# @param [String] text to prompt
|
228
|
+
# @return [true, false] 'y' is true, all else if false
|
229
|
+
public
|
230
|
+
def rb_confirm text, aconfig={}, &block
|
231
|
+
# backward compatibility with agree()
|
232
|
+
if aconfig == true || aconfig == false
|
233
|
+
default = aconfig
|
234
|
+
aconfig = {}
|
235
|
+
else
|
236
|
+
default = aconfig[:default]
|
237
|
+
end
|
238
|
+
case text
|
239
|
+
when RubyCurses::Variable # added 2011-09-20 incase variable passed
|
240
|
+
text = text.get_value
|
241
|
+
when Exception
|
242
|
+
text = text.to_s
|
243
|
+
end
|
244
|
+
ewin = _create_footer_window
|
245
|
+
r = 0; c = 1;
|
246
|
+
#aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
|
247
|
+
# changed on 2011-12-6
|
248
|
+
color = aconfig[:color]
|
249
|
+
bgcolor = aconfig[:bgcolor]
|
250
|
+
color ||= :white
|
251
|
+
bgcolor ||= :black
|
252
|
+
color_pair = get_color($promptcolor, color, bgcolor)
|
253
|
+
ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
|
254
|
+
ewin.printstring r, c, text, color_pair
|
255
|
+
ewin.printstring r+1, c, "[y/n]", color_pair
|
256
|
+
ewin.wrefresh
|
257
|
+
#retval = :NO # consistent with confirm # CHANGE TO TRUE FALSE NOW
|
258
|
+
retval = false
|
259
|
+
begin
|
260
|
+
ch = ewin.getchar
|
261
|
+
retval = (ch == 'y'.ord || ch == 'Y'.ord )
|
262
|
+
# if caller passed a default value and user pressed ENTER return that
|
263
|
+
# can be true or false so don't change this to "if default". 2011-12-8
|
264
|
+
if !default.nil?
|
265
|
+
if ch == 13 || ch == KEY_ENTER
|
266
|
+
retval = default
|
267
|
+
end
|
268
|
+
end
|
269
|
+
#retval = :YES if ch.chr == 'y'
|
270
|
+
ensure
|
271
|
+
ewin.destroy
|
272
|
+
end
|
273
|
+
retval
|
274
|
+
end
|
275
|
+
alias :confirm_window :rb_confirm
|
276
|
+
# class created to display multiple messages without asking for user to hit a key
|
277
|
+
# returns a window to which one can keep calling printstring with 0 or 1 as row.
|
278
|
+
# destroy when finished.
|
279
|
+
# Also, one can pause if one wants, or linger.
|
280
|
+
# This is meant to be a replacement for the message_immediate and message_raw
|
281
|
+
# I was trying out in App.rb. 2011-10-1 1:27 AM
|
282
|
+
# Testing from test2.rb
|
283
|
+
# TODO: add option of putting progress_bar
|
284
|
+
class StatusWindow
|
285
|
+
attr_reader :h, :w, :top, :left # height, width, top row, left col of window
|
286
|
+
attr_reader :win
|
287
|
+
attr_accessor :color_pair
|
288
|
+
def initialize config={}, &block
|
289
|
+
@color_pair = config[:color_pair]
|
290
|
+
@row_offset = config[:row_offset] || 0
|
291
|
+
@col_offset = config[:col_offset] || 0
|
292
|
+
create_window *config[:layout]
|
293
|
+
end
|
294
|
+
def create_window h = 2 , w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0
|
295
|
+
return @win if @win
|
296
|
+
@win = VER::Window.new(h, w , t, l)
|
297
|
+
@h = h ; @w = w; @top = t ; @left = l
|
298
|
+
@color_pair ||= get_color($promptcolor, 'white','black')
|
299
|
+
@win.bkgd(Ncurses.COLOR_PAIR(@color_pair));
|
300
|
+
@win
|
301
|
+
end
|
302
|
+
# creates a color pair based on given bg and fg colors as strings
|
303
|
+
#def set_colors bgcolor, fgcolor='white'
|
304
|
+
#@color_pair = get_color($datacolor, 'white','black')
|
305
|
+
#end
|
306
|
+
# prints a string on given row (0 or 1)
|
307
|
+
def printstring r, c, text, color_pair=@color_pair
|
308
|
+
create_window unless @win
|
309
|
+
show unless @visible
|
310
|
+
r = @h-1 if r > @h-1
|
311
|
+
#@win.printstring r, c, ' '*@w, @color_pair
|
312
|
+
# FIXME this padding overwrites the border and the offset means next line wiped
|
313
|
+
# However, now it may now totally clear a long line.
|
314
|
+
@win.printstring r+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, text], color_pair
|
315
|
+
@win.wrefresh
|
316
|
+
end
|
317
|
+
# print given strings from first first column onwards
|
318
|
+
def print *textarray
|
319
|
+
create_window unless @win
|
320
|
+
show unless @visible
|
321
|
+
c = 1
|
322
|
+
textarray.each_with_index { |s, i|
|
323
|
+
@win.printstring i+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, s], @color_pair
|
324
|
+
}
|
325
|
+
@win.wrefresh
|
326
|
+
end
|
327
|
+
def pause; @win.getchar; end
|
328
|
+
# pauses with the message, but doesn't ask the user to press a key.
|
329
|
+
# If he does, the key should be used by underlying window.
|
330
|
+
# Do not call destroy if you call linger, it does the destroy.
|
331
|
+
def linger caller_window=nil
|
332
|
+
begin
|
333
|
+
if caller_window
|
334
|
+
ch = @win.getchar
|
335
|
+
caller_window.ungetch(ch) # will this be available to underlying window XXX i think not !!
|
336
|
+
else
|
337
|
+
sleep 1
|
338
|
+
end
|
339
|
+
ensure
|
340
|
+
destroy
|
341
|
+
end
|
342
|
+
end
|
343
|
+
# caller must destroy after he's finished printing messages, unless
|
344
|
+
# user calls linger
|
345
|
+
def destroy; @win.destroy if @win; @win = nil; end
|
346
|
+
def hide
|
347
|
+
@win.hide
|
348
|
+
@visible = false
|
349
|
+
end
|
350
|
+
def show
|
351
|
+
@win.show unless @visible
|
352
|
+
@visible = true
|
353
|
+
end
|
354
|
+
end
|
355
|
+
# returns instance of a status_window for sending multiple
|
356
|
+
# statuses during some process
|
357
|
+
def status_window aconfig={}, &block
|
358
|
+
return StatusWindow.new aconfig
|
359
|
+
end
|
360
|
+
# this is a popup dialog box on which statuses can be printed as a process is taking place.
|
361
|
+
# I am reusing StatusWindow and so there's an issue since I've put a box, so in clearing
|
362
|
+
# the line, I might overwrite the box
|
363
|
+
def progress_dialog aconfig={}, &block
|
364
|
+
aconfig[:layout] = [10,60,10,20]
|
365
|
+
window = status_window aconfig
|
366
|
+
height = 10; width = 60
|
367
|
+
window.win.print_border_mb 1,2, height, width, $normalcolor, FFI::NCurses::A_REVERSE
|
368
|
+
return window
|
369
|
+
end
|
370
|
+
#
|
371
|
+
# Display a popup and return the seliected index from list
|
372
|
+
# Config includes row and col and title of window
|
373
|
+
# You may also pass bgcolor and color
|
374
|
+
# Returns index of selected row on pressing ENTER or space
|
375
|
+
# In case of multiple selection, returns array of selected indices only on ENTER
|
376
|
+
# Returns nil if C-q pressed
|
377
|
+
# @since 1.4.1 2011-11-1
|
378
|
+
def popuplist list, config={}, &block
|
379
|
+
raise ArgumentError, "Nil list received by popuplist" unless list
|
380
|
+
require 'rbhex/core/widgets/rlist'
|
381
|
+
|
382
|
+
max_visible_items = config[:max_visible_items]
|
383
|
+
row = config[:row] || 5
|
384
|
+
col = config[:col] || 5
|
385
|
+
relative_to = config[:relative_to]
|
386
|
+
if relative_to
|
387
|
+
layout = relative_to.form.window.layout
|
388
|
+
row += layout[:top]
|
389
|
+
col += layout[:left]
|
390
|
+
end
|
391
|
+
config.delete :relative_to
|
392
|
+
width = config[:width] || longest_in_list(list)+2 # borders take 2
|
393
|
+
if config[:title]
|
394
|
+
width = config[:title].size + 2 if width < config[:title].size
|
395
|
+
end
|
396
|
+
height = config[:height]
|
397
|
+
height ||= [max_visible_items || 10+2, list.length+2].min
|
398
|
+
#layout(1+height, width+4, row, col)
|
399
|
+
layout = { :height => 0+height, :width => 0+width, :top => row, :left => col }
|
400
|
+
window = VER::Window.new(layout)
|
401
|
+
form = RubyCurses::Form.new window
|
402
|
+
|
403
|
+
listconfig = config[:listconfig] || {}
|
404
|
+
listconfig[:list] = list
|
405
|
+
listconfig[:width] = width
|
406
|
+
listconfig[:height] = height
|
407
|
+
listconfig[:selection_mode] ||= :single
|
408
|
+
listconfig.merge!(config)
|
409
|
+
listconfig.delete(:row);
|
410
|
+
listconfig.delete(:col);
|
411
|
+
# trying to pass populists block to listbox
|
412
|
+
lb = RubyCurses::List.new form, listconfig, &block
|
413
|
+
#
|
414
|
+
# added next line so caller can configure listbox with
|
415
|
+
# events such as ENTER_ROW, LEAVE_ROW or LIST_SELECTION_EVENT or PRESS
|
416
|
+
# 2011-11-11
|
417
|
+
#yield lb if block_given? # No it won't work since this returns
|
418
|
+
window.bkgd(Ncurses.COLOR_PAIR($reversecolor));
|
419
|
+
window.wrefresh
|
420
|
+
Ncurses::Panel.update_panels
|
421
|
+
form.repaint
|
422
|
+
window.wrefresh
|
423
|
+
begin
|
424
|
+
while((ch = window.getchar()) != 999 )
|
425
|
+
case ch
|
426
|
+
when -1
|
427
|
+
next
|
428
|
+
when ?\C-q.getbyte(0)
|
429
|
+
break
|
430
|
+
else
|
431
|
+
lb.handle_key ch
|
432
|
+
form.repaint
|
433
|
+
if ch == 13 || ch == 10
|
434
|
+
return lb.current_index if lb.selection_mode != :multiple
|
435
|
+
|
436
|
+
x = lb.selected_indices
|
437
|
+
return x if x
|
438
|
+
x = lb.current_index unless x
|
439
|
+
return [x]
|
440
|
+
# if multiple selection, then return list of selected_indices and don't catch 32
|
441
|
+
elsif ch == 32 # if single selection
|
442
|
+
return lb.current_index if lb.selection_mode != :multiple
|
443
|
+
end
|
444
|
+
#yield ch if block_given?
|
445
|
+
end
|
446
|
+
end
|
447
|
+
ensure
|
448
|
+
window.destroy
|
449
|
+
end
|
450
|
+
return nil
|
451
|
+
end
|
452
|
+
# returns length of longest
|
453
|
+
def longest_in_list list #:nodoc:
|
454
|
+
raise ArgumentError, "rdialog.rb: longest_in_list recvd nil list" unless list
|
455
|
+
longest = list.inject(0) do |memo,word|
|
456
|
+
memo >= word.length ? memo : word.length
|
457
|
+
end
|
458
|
+
longest
|
459
|
+
end
|
460
|
+
# would like to deprecate this and use
|
461
|
+
# @form.help_manager.help_text = text
|
462
|
+
def install_help_text text
|
463
|
+
@_help_text = text
|
464
|
+
if @form
|
465
|
+
hm = @form.help_manager
|
466
|
+
hm.help_text = text
|
467
|
+
end
|
468
|
+
end
|
469
|
+
# this routine prints help_text for an application
|
470
|
+
# If help_text has been set using install_help_text
|
471
|
+
# it will be displayed. Else, general help will be
|
472
|
+
# displayed. Even when custom help is displayed,
|
473
|
+
# user may use <next> to see general help.
|
474
|
+
#
|
475
|
+
# earlier in app.rb
|
476
|
+
def display_app_help form=@form
|
477
|
+
if form
|
478
|
+
hm = form.help_manager
|
479
|
+
if !hm.help_text
|
480
|
+
arr = nil
|
481
|
+
# these 2 only made sense from app.rb and should be removed, too implicit
|
482
|
+
if respond_to? :help_text
|
483
|
+
arr = help_text
|
484
|
+
elsif @_help_text
|
485
|
+
arr = @_help_text
|
486
|
+
end
|
487
|
+
hm.help_text(arr) if arr
|
488
|
+
end
|
489
|
+
form.help_manager.display_help
|
490
|
+
else
|
491
|
+
raise "Form needed by display_app_help. Use form.help_manager instead"
|
492
|
+
end
|
493
|
+
end
|
494
|
+
def ORIGdisplay_app_help
|
495
|
+
filename = File.dirname(__FILE__) + "/../docs/index.txt"
|
496
|
+
# defarr contains default help
|
497
|
+
if File.exists?(filename)
|
498
|
+
defarr = File.open(filename,'r').readlines
|
499
|
+
else
|
500
|
+
arr = []
|
501
|
+
arr << " NO HELP SPECIFIED FOR APP "
|
502
|
+
arr << " "
|
503
|
+
arr << " --- General help --- "
|
504
|
+
arr << " F10 - exit application "
|
505
|
+
arr << " Alt-x - select commands "
|
506
|
+
arr << " : (or M-:) - select commands "
|
507
|
+
arr << " ? (or M-?) - current widget key bindings "
|
508
|
+
arr << " "
|
509
|
+
defarr = arr
|
510
|
+
end
|
511
|
+
defhelp = true
|
512
|
+
if respond_to? :help_text
|
513
|
+
arr = help_text()
|
514
|
+
defhelp = false
|
515
|
+
elsif @_help_text
|
516
|
+
arr = @_help_text
|
517
|
+
defhelp = false
|
518
|
+
else
|
519
|
+
arr = defarr
|
520
|
+
end
|
521
|
+
case arr
|
522
|
+
when String
|
523
|
+
arr = arr.split("\n")
|
524
|
+
when Array
|
525
|
+
end
|
526
|
+
#w = arr.max_by(&:length).length
|
527
|
+
h = FFI::NCurses.LINES - 4
|
528
|
+
w = FFI::NCurses.COLS - 10
|
529
|
+
|
530
|
+
require 'rbhex/core/util/viewer'
|
531
|
+
RubyCurses::Viewer.view(arr, :layout => [2, 4, h, w],:close_key => KEY_F10, :title => "[ Help ]", :print_footer => true) do |t|
|
532
|
+
# you may configure textview further here.
|
533
|
+
#t.suppress_borders true
|
534
|
+
#t.color = :black
|
535
|
+
#t.bgcolor = :white
|
536
|
+
# or
|
537
|
+
#t.attr = :reverse
|
538
|
+
|
539
|
+
# help was provided, so default help is provided in second buffer
|
540
|
+
unless defhelp
|
541
|
+
t.add_content defarr, :title => ' General Help '
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|
545
|
+
#
|
546
|
+
=begin
|
547
|
+
http://www.kammerl.de/ascii/AsciiSignature.php
|
548
|
+
___
|
549
|
+
|__ \
|
550
|
+
) |
|
551
|
+
/ /
|
552
|
+
|_|
|
553
|
+
(_)
|
554
|
+
|
555
|
+
_
|
556
|
+
| |
|
557
|
+
| |
|
558
|
+
| |
|
559
|
+
|_|
|
560
|
+
(_)
|
561
|
+
|
562
|
+
|
563
|
+
_____ _ _____
|
564
|
+
| __ \ | | / ____|
|
565
|
+
| |__) | _| |__ _ _ | | _ _ _ __ ___ ___ ___
|
566
|
+
| _ / | | | '_ \| | | | | | | | | | '__/ __|/ _ \/ __|
|
567
|
+
| | \ \ |_| | |_) | |_| | | |___| |_| | | \__ \ __/\__ \
|
568
|
+
|_| \_\__,_|_.__/ \__, | \_____\__,_|_| |___/\___||___/
|
569
|
+
__/ |
|
570
|
+
|___/
|
571
|
+
|
572
|
+
=end
|
573
|
+
|
574
|
+
|