rbcurse-core 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1945 -0
- data/README.md +6 -2
- data/VERSION +1 -1
- data/examples/abasiclist.rb +1 -1
- data/examples/bline.rb +135 -0
- data/examples/dbdemo.rb +26 -20
- data/examples/term2.rb +1 -1
- data/examples/testlistbox.rb +6 -4
- data/lib/rbcurse/core/include/appmethods.rb +5 -3
- data/lib/rbcurse/core/include/io.rb +176 -598
- data/lib/rbcurse/core/include/rhistory.rb +22 -5
- data/lib/rbcurse/core/system/ncurses.rb +3 -4
- data/lib/rbcurse/core/system/window.rb +0 -46
- data/lib/rbcurse/core/util/app.rb +35 -48
- data/lib/rbcurse/core/util/bottomline.rb +18 -11
- data/lib/rbcurse/core/util/padreader.rb +2 -1
- data/lib/rbcurse/core/util/rcommandwindow.rb +1 -0
- data/lib/rbcurse/core/util/rdialogs.rb +74 -164
- data/lib/rbcurse/core/util/viewer.rb +1 -1
- data/lib/rbcurse/core/widgets/rmessagebox.rb +14 -4
- data/lib/rbcurse/core/widgets/rtabbedwindow.rb +1 -1
- data/lib/rbcurse/core/widgets/rtextarea.rb +59 -9
- data/lib/rbcurse/core/widgets/rtextview.rb +48 -10
- data/lib/rbcurse/core/widgets/rwidget.rb +38 -6
- data/lib/rbcurse/core/widgets/tabular.rb +4 -4
- data/lib/rbcurse/core/widgets/tabularwidget.rb +1 -1
- data/lib/rbcurse/core/widgets/textpad.rb +2 -2
- data/rbcurse-core.gemspec +134 -0
- metadata +33 -36
@@ -29,8 +29,9 @@ module RubyCurses
|
|
29
29
|
bind_key($history_key) { _show_history }
|
30
30
|
# widget should have CHANGED event, or this will either give error, or just not work
|
31
31
|
# else please update history whenever you want a value to be retrieved
|
32
|
-
bind(:CHANGED) { @history << @text
|
32
|
+
bind(:CHANGED) { @history << @text if @text && (!@history.include? @text) }
|
33
33
|
end
|
34
|
+
def history=(x); history(x); end
|
34
35
|
|
35
36
|
# pass in some configuration for histroy such as row and column to show popup on
|
36
37
|
def history_config config={}
|
@@ -42,13 +43,29 @@ module RubyCurses
|
|
42
43
|
private
|
43
44
|
def _show_history
|
44
45
|
return unless @history
|
46
|
+
return if @history.empty?
|
45
47
|
list = @history
|
48
|
+
@_history_config ||= {}
|
49
|
+
#list = ["No history"] if @history.empty?
|
50
|
+
raise ArgumentError, "show_history got nil list" unless list
|
46
51
|
# calculate r and c
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
# col if fine, except for when there's a label.
|
53
|
+
c = @_history_config[:col] || @field_col || @col # this is also dependent on window coords, as in a status_window or messagebox
|
54
|
+
sz = @history.size
|
55
|
+
wrow = 0
|
56
|
+
wrow = self.form.window.top if self.form
|
57
|
+
crow = wrow + @row
|
58
|
+
# if list can be displayed above, then fit it just above
|
59
|
+
if crow > sz + 2
|
60
|
+
r = crow - sz - 2
|
61
|
+
else
|
62
|
+
# else fit it in next row
|
63
|
+
r = crow + 1
|
51
64
|
end
|
65
|
+
#r = @row - 10
|
66
|
+
#if @row < 10
|
67
|
+
#r = @row + 1
|
68
|
+
#end
|
52
69
|
r = @_history_config[:row] || r
|
53
70
|
ret = popuplist(list, :row => r, :col => c, :title => " History ")
|
54
71
|
if ret
|
@@ -99,10 +99,9 @@ module VER
|
|
99
99
|
#puts "curses over"
|
100
100
|
ensure
|
101
101
|
return unless error = @last_error
|
102
|
-
log =
|
103
|
-
|
104
|
-
Kernel.warn "
|
105
|
-
Kernel.warn "The most recent was:"
|
102
|
+
#log = RbConfig[:logfile].value
|
103
|
+
#Kernel.warn "There may have been fatal errors logged to: #{log}."
|
104
|
+
#Kernel.warn "The most recent was:"
|
106
105
|
|
107
106
|
$stderr.puts ''
|
108
107
|
$stderr.puts @last_error_message if @last_error_message
|
@@ -36,7 +36,6 @@ module VER
|
|
36
36
|
attr_reader :window_type # window or pad to distinguish 2009-11-02 23:11
|
37
37
|
attr_accessor :name # more for debugging log files. 2010-02-02 19:58
|
38
38
|
attr_accessor :modified # has it been modified and may need a refresh
|
39
|
-
#attr_reader :bottomline # experimental here 2010-11-03 22:19
|
40
39
|
|
41
40
|
# @param [Array, Hash] window coordinates (ht, w, top, left)
|
42
41
|
# or
|
@@ -729,51 +728,6 @@ module VER
|
|
729
728
|
mvwprintw(r, c, "%s", :string, string);
|
730
729
|
wattroff(Ncurses.COLOR_PAIR(color) | att)
|
731
730
|
end
|
732
|
-
# @deprecated
|
733
|
-
def print_error_message text=$error_message.get_value
|
734
|
-
alert text
|
735
|
-
end
|
736
|
-
# added by rk 2008-11-29 19:01
|
737
|
-
# @deprecated. use global method of same name in rdialog
|
738
|
-
def print_status_message text=$status_message
|
739
|
-
#VER::print_status_message text
|
740
|
-
alert text
|
741
|
-
end
|
742
|
-
# added by rk 2008-11-29 19:01
|
743
|
-
# Since these methods write directly to window they are not advised
|
744
|
-
# since clearing previous message we don't know how much to clear.
|
745
|
-
# Best to map error_message to a label.
|
746
|
-
# 2010-09-13 00:22 WE should not use these any longer.
|
747
|
-
# Application should create a label and map a Variable named
|
748
|
-
# $errormessage to it. We should only update the Variable
|
749
|
-
def DEPRECATED_print_error_message text=$error_message.get_value
|
750
|
-
r = $error_message_row || Ncurses.LINES-1
|
751
|
-
c = $error_message_col || (Ncurses.COLS-text.length)/2
|
752
|
-
|
753
|
-
$log.debug "got ERROR MESSAGE #{text} row #{r} "
|
754
|
-
clear_error r, $datacolor
|
755
|
-
printstring r, c, text, color = $promptcolor
|
756
|
-
$error_message_clear_pending = true
|
757
|
-
end
|
758
|
-
# added by rk 2008-11-29 19:01
|
759
|
-
# @deprecated. use global method of same name
|
760
|
-
def DEPRECATED_print_status_message text=$status_message
|
761
|
-
r = $status_message_row || Ncurses.LINES-1
|
762
|
-
clear_error r, $datacolor
|
763
|
-
# print it in centre
|
764
|
-
printstring r, (Ncurses.COLS-text.length)/2, text, color = $promptcolor
|
765
|
-
end
|
766
|
-
# Clear error message printed
|
767
|
-
# I am not only clearing if something was printed. This is since
|
768
|
-
# certain small forms like TabbedForm top form throw an error on printstring.
|
769
|
-
# @deprecated
|
770
|
-
def clear_error r = $error_message_row, color = $datacolor
|
771
|
-
return unless $error_message_clear_pending
|
772
|
-
c = $error_message_col || (Ncurses.COLS-text.length)/2
|
773
|
-
sz = $error_message_size || Ncurses.COLS
|
774
|
-
printstring(r, c, "%-*s" % [sz, " "], color)
|
775
|
-
$error_message_clear_pending = false
|
776
|
-
end
|
777
731
|
##
|
778
732
|
# NOTE : FOR MESSAGEBOXES ONLY !!!!
|
779
733
|
def print_border_mb row, col, height, width, color, attr
|
@@ -18,14 +18,6 @@ require 'logger'
|
|
18
18
|
require 'rbcurse'
|
19
19
|
require 'rbcurse/core/util/widgetshortcuts'
|
20
20
|
|
21
|
-
require 'rbcurse/core/util/bottomline'
|
22
|
-
$tt ||= RubyCurses::Bottomline.new
|
23
|
-
$tt.name = "$tt"
|
24
|
-
require 'forwardable'
|
25
|
-
module Kernel
|
26
|
-
extend Forwardable
|
27
|
-
def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list, :say_with_pause, :hide_bottomline, :say_with_wait
|
28
|
-
end
|
29
21
|
include RubyCurses
|
30
22
|
include RubyCurses::Utils
|
31
23
|
include Io
|
@@ -85,9 +77,6 @@ module RubyCurses
|
|
85
77
|
# the row on which to prompt user for any inputs
|
86
78
|
#attr_accessor :prompt_row # 2011-10-17 14:06:22
|
87
79
|
|
88
|
-
extend Forwardable
|
89
|
-
def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list
|
90
|
-
|
91
80
|
# TODO: i should be able to pass window coords here in config
|
92
81
|
# :title
|
93
82
|
def initialize config={}, &block
|
@@ -134,7 +123,7 @@ module RubyCurses
|
|
134
123
|
@window.destroy if !@window.nil?
|
135
124
|
$log.debug " INSIDE CLOSE, #{@stop_ncurses_on_close} "
|
136
125
|
if @stop_ncurses_on_close
|
137
|
-
$tt.destroy # added on 2011-10-9 since we created a window, but only hid it after use
|
126
|
+
$tt.destroy if $tt # added on 2011-10-9 since we created a window, but only hid it after use
|
138
127
|
VER::stop_ncurses
|
139
128
|
$log.debug " CLOSING NCURSES"
|
140
129
|
end
|
@@ -176,10 +165,10 @@ module RubyCurses
|
|
176
165
|
begin
|
177
166
|
@form.handle_key ch
|
178
167
|
rescue => err
|
179
|
-
alert err.to_s
|
180
168
|
$log.debug( "handle_key rescue reached ")
|
181
169
|
$log.debug( err)
|
182
170
|
$log.debug(err.backtrace.join("\n"))
|
171
|
+
textdialog [err.to_s, *err.backtrace], :title => "Exception"
|
183
172
|
end
|
184
173
|
#@form.repaint # was this duplicate ?? handle calls repaint not needed
|
185
174
|
@window.wrefresh
|
@@ -222,17 +211,13 @@ module RubyCurses
|
|
222
211
|
$status_message.value = text # trying out 2011-10-9
|
223
212
|
#@message.value = text # 2011-10-17 14:07:01
|
224
213
|
end
|
225
|
-
|
226
|
-
def message_row row
|
227
|
-
raise "Please use create_message_label first as message_label is no longer default behaviour" unless @message_label
|
228
|
-
@message_label.row = row
|
229
|
-
end
|
214
|
+
|
230
215
|
# during a process, when you wish to update status, since ordinarily the thread is busy
|
231
216
|
# and form does not get control back, so the window won't refresh.
|
232
217
|
# This will only update on keystroke since it uses statusline
|
233
218
|
# @deprecated please use {#status_line} instead of a message label
|
234
219
|
def message_immediate text
|
235
|
-
$log.warn "DEPRECATED, use message(),
|
220
|
+
$log.warn "DEPRECATED, use message(), or rb_puts or use status_window"
|
236
221
|
$status_message.value = text # trying out 2011-10-9 user needs to use in statusline command
|
237
222
|
# 2011-10-17 knocking off label, should be printed on status_line
|
238
223
|
end
|
@@ -334,46 +319,49 @@ module RubyCurses
|
|
334
319
|
# FIXME: why are we using rawmessage and then getchar when ask would suffice
|
335
320
|
def bind_global
|
336
321
|
opts = get_all_commands
|
337
|
-
cmd =
|
322
|
+
cmd = rb_gets("Select a command (<tab> for choices) : ", opts)
|
338
323
|
if cmd.nil? || cmd == ""
|
339
|
-
|
324
|
+
rb_puts "Aborted."
|
340
325
|
return
|
341
326
|
end
|
342
327
|
key = []
|
343
328
|
str = ""
|
344
|
-
raw_message "Enter one or 2 keys. Finish with ENTER. Enter first key:"
|
345
|
-
#
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
329
|
+
#raw_message "Enter one or 2 keys. Finish with ENTER. Enter first key:"
|
330
|
+
#ch = @window.getchar()
|
331
|
+
#raw_message_destroy
|
332
|
+
#if [KEY_ENTER, 10, 13, ?\C-g.getbyte(0)].include? ch
|
333
|
+
#say_with_pause "Aborted."
|
334
|
+
#return
|
335
|
+
#end
|
336
|
+
# the next is fine but does not allow user to enter a control or alt or function character
|
337
|
+
# since it uses Field. It is fine if you want to force alphanum input
|
338
|
+
ch = rb_getchar("Enter one or two keys. Finish with <ENTER>. Enter first key:")
|
339
|
+
unless ch
|
340
|
+
rb_puts "Aborted. <Press a key>"
|
350
341
|
return
|
351
342
|
end
|
352
343
|
key << ch
|
353
344
|
str << keycode_tos(ch)
|
354
|
-
|
355
|
-
ch
|
356
|
-
|
357
|
-
if ch == 3 || ch == ?\C-g.getbyte(0)
|
358
|
-
say_with_pause "Aborted."
|
345
|
+
ch = rb_getchar "Got #{str}. Enter second key or hit return:"
|
346
|
+
unless ch
|
347
|
+
rb_puts "Aborted. <Press a key>"
|
359
348
|
return
|
360
349
|
end
|
361
|
-
if ch ==
|
350
|
+
if ch == KEY_ENTER || ch == 13
|
362
351
|
else
|
363
352
|
key << ch
|
364
353
|
str << keycode_tos(ch)
|
365
354
|
end
|
366
355
|
if !key.empty?
|
367
|
-
|
356
|
+
rb_puts "Binding #{cmd} to #{str}. "
|
368
357
|
key = key[0] if key.size == 1
|
369
358
|
#@form.bind_key(key, cmd.to_sym) # not finding it, getting called by that comp
|
370
359
|
@form.bind_key(key){ send(cmd.to_sym) }
|
371
360
|
end
|
372
|
-
#message "Bound #{str} to #{cmd} "
|
373
|
-
raw_message_destroy
|
374
361
|
end
|
375
362
|
def bind_component
|
376
|
-
|
363
|
+
#rb_puts "Todo. ", :color_pair => get_color($promptcolor, :red, :black)
|
364
|
+
print_error_message "Todo this. "
|
377
365
|
# the idea here is to get the current component
|
378
366
|
# and bind some keys to some methods.
|
379
367
|
# however, how do we divine the methods we can map to
|
@@ -384,9 +372,10 @@ module RubyCurses
|
|
384
372
|
f = @form.get_current_field
|
385
373
|
if f.respond_to?('help_text')
|
386
374
|
h = f.help_text
|
387
|
-
|
375
|
+
h = "No help text defined for this field.\nTry F1, or press '?' for key-bindings." unless h
|
376
|
+
textdialog "#{h}", :title => "Widget Help Text"
|
388
377
|
else
|
389
|
-
alert "Could not get field #{f} or does not respond to helptext"
|
378
|
+
alert "Could not get field #{f} or does not respond to helptext. Try F1 or '?'"
|
390
379
|
end
|
391
380
|
end
|
392
381
|
# prompts user for a command. we need to get this back to the calling app
|
@@ -395,10 +384,8 @@ module RubyCurses
|
|
395
384
|
# or lines ??
|
396
385
|
# Also may want command completion, or help so all commands can be displayed
|
397
386
|
def get_command_from_user choices=["quit","help"]
|
398
|
-
|
399
|
-
|
400
|
-
@_command_history ||= Array.new
|
401
|
-
str = ask("Cmd: ", choices) { |q| q.default = @_previous_command; q.history = @_command_history }
|
387
|
+
@_command_history ||= Array.new
|
388
|
+
str = rb_gets("Cmd: ", choices) { |q| q.default = @_previous_command; q.history = @_command_history }
|
402
389
|
@_command_history << str unless @_command_history.include? str
|
403
390
|
# shell the command
|
404
391
|
if str =~ /^!/
|
@@ -437,7 +424,7 @@ module RubyCurses
|
|
437
424
|
ret = false
|
438
425
|
# what is this execute_this: some kind of general routine for all apps ?
|
439
426
|
ret = execute_this(cmd, *cmdline) if respond_to?(:execute_this, true)
|
440
|
-
|
427
|
+
rb_puts("#{self.class} does not respond to #{cmd} ", :color_pair => $promptcolor) unless ret
|
441
428
|
# should be able to say in red as error
|
442
429
|
end
|
443
430
|
end
|
@@ -988,7 +975,7 @@ module RubyCurses
|
|
988
975
|
opts = get_all_commands()
|
989
976
|
@_command_history ||= Array.new
|
990
977
|
# previous command should be in opts, otherwise it is not in this context
|
991
|
-
cmd =
|
978
|
+
cmd = rb_gets("Command: ", opts){ |q| q.default = @_previous_command; q.history = @_command_history }
|
992
979
|
if cmd.nil? || cmd == ""
|
993
980
|
else
|
994
981
|
@_command_history << cmd unless @_command_history.include? cmd
|
@@ -1000,7 +987,7 @@ module RubyCurses
|
|
1000
987
|
if rcmd.size == 1
|
1001
988
|
cmd = rcmd.first
|
1002
989
|
elsif !rcmd.empty?
|
1003
|
-
|
990
|
+
rb_puts "Cannot resolve #{cmd}. Matches are: #{rcmd} "
|
1004
991
|
end
|
1005
992
|
end
|
1006
993
|
if respond_to?(cmd, true)
|
@@ -1013,11 +1000,11 @@ module RubyCurses
|
|
1013
1000
|
if exc
|
1014
1001
|
$log.debug( exc)
|
1015
1002
|
$log.debug(exc.backtrace.join("\n"))
|
1016
|
-
|
1003
|
+
rb_puts exc.to_s
|
1017
1004
|
end
|
1018
1005
|
end
|
1019
1006
|
else
|
1020
|
-
|
1007
|
+
rb_puts("Command [#{cmd}] not supported by #{self.class} ", :color_pair => $promptcolor)
|
1021
1008
|
end
|
1022
1009
|
end
|
1023
1010
|
}
|
@@ -95,7 +95,6 @@ module RubyCurses
|
|
95
95
|
end
|
96
96
|
#
|
97
97
|
# create a window at bottom and show and hide it.
|
98
|
-
# Causing a stack overflow since Window creates a bottomline too !
|
99
98
|
#
|
100
99
|
def _create_footer_window h = 1 , w = Ncurses.COLS, t = Ncurses.LINES-1, l = 0
|
101
100
|
ewin = VER::Window.new(h, w , t, l)
|
@@ -320,7 +319,7 @@ module RubyCurses
|
|
320
319
|
#
|
321
320
|
# text to be shown if user presses M-h
|
322
321
|
#
|
323
|
-
attr_accessor :
|
322
|
+
attr_accessor :help_text
|
324
323
|
attr_accessor :color_pair
|
325
324
|
attr_accessor :history
|
326
325
|
|
@@ -984,7 +983,7 @@ module RubyCurses
|
|
984
983
|
@key_handler_proc = @question.key_handler_proc
|
985
984
|
@default = @question.default
|
986
985
|
$log.debug "XXX: ASK RBGETS got default: #{@default} "
|
987
|
-
@
|
986
|
+
@help_text = @question.help_text
|
988
987
|
@answer_type = @question.answer_type
|
989
988
|
if @question.answer_type.is_a? Array
|
990
989
|
@completion_proc = Proc.new{|str| @answer_type.dup.grep Regexp.new("^#{str}") }
|
@@ -1242,8 +1241,8 @@ module RubyCurses
|
|
1242
1241
|
str.slice!(curpos) #rescue next
|
1243
1242
|
clear_line len+maxlen+1, @prompt_length
|
1244
1243
|
when ?\M-h.getbyte(0) # HELP KEY
|
1245
|
-
|
1246
|
-
print_help(
|
1244
|
+
help_text = @help_text || "No help provided..."
|
1245
|
+
print_help(help_text)
|
1247
1246
|
clear_line len+maxlen+1
|
1248
1247
|
print_str @statement # UGH
|
1249
1248
|
#return 7, nil
|
@@ -1473,10 +1472,10 @@ module RubyCurses
|
|
1473
1472
|
print_str("%-*s" % [len," "], :y => from)
|
1474
1473
|
end
|
1475
1474
|
|
1476
|
-
def print_help(
|
1475
|
+
def print_help(help_text)
|
1477
1476
|
# best to popup a window and hsow that with ENTER to dispell
|
1478
|
-
print_str("%-*s" % [
|
1479
|
-
print_str("%s" %
|
1477
|
+
print_str("%-*s" % [help_text.length+2," "])
|
1478
|
+
print_str("%s" % help_text)
|
1480
1479
|
sleep(5)
|
1481
1480
|
end
|
1482
1481
|
def get_response
|
@@ -1592,7 +1591,7 @@ module RubyCurses
|
|
1592
1591
|
w = rc.window
|
1593
1592
|
rc.display_menu list1
|
1594
1593
|
# earlier wmove bombed, now move is (window.rb 121)
|
1595
|
-
str = ask(prompt) { |q| q.change_proc = Proc.new { |str| w.wmove(1,1) ; w.wclrtobot;
|
1594
|
+
str = ask(prompt) { |q| q.help_text = config[:help_text] ; q.change_proc = Proc.new { |str| w.wmove(1,1) ; w.wclrtobot;
|
1596
1595
|
|
1597
1596
|
l = list1.select{|e| e.index(str)==0} ; # select those starting with str
|
1598
1597
|
|
@@ -1776,6 +1775,14 @@ module RubyCurses
|
|
1776
1775
|
end
|
1777
1776
|
end # module
|
1778
1777
|
end # module
|
1778
|
+
#require 'rbcurse/core/util/bottomline'
|
1779
|
+
$tt ||= RubyCurses::Bottomline.new
|
1780
|
+
$tt.name = "$tt"
|
1781
|
+
require 'forwardable'
|
1782
|
+
module Kernel
|
1783
|
+
extend Forwardable
|
1784
|
+
def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list, :say_with_pause, :hide_bottomline, :say_with_wait
|
1785
|
+
end
|
1779
1786
|
if __FILE__ == $PROGRAM_NAME
|
1780
1787
|
|
1781
1788
|
#tabc = Proc.new {|str| Dir.glob(str +"*") }
|
@@ -1808,7 +1815,7 @@ if __FILE__ == $PROGRAM_NAME
|
|
1808
1815
|
entry = {}
|
1809
1816
|
entry[:file] = ask("File? ", Pathname) do |q|
|
1810
1817
|
q.completion_proc = Proc.new {|str| Dir.glob(str +"*") }
|
1811
|
-
q.
|
1818
|
+
q.help_text = "Enter start of filename and tab to get completion"
|
1812
1819
|
end
|
1813
1820
|
alert "file: #{entry[:file]} "
|
1814
1821
|
$log.debug "FILE: #{entry[:file]} "
|
@@ -1824,7 +1831,7 @@ if __FILE__ == $PROGRAM_NAME
|
|
1824
1831
|
entry[:state] = ask("State? ") do |q|
|
1825
1832
|
q._case = :up
|
1826
1833
|
q.validate = /\A[A-Z]{2}\Z/
|
1827
|
-
q.
|
1834
|
+
q.help_text = "Enter 2 characters for your state"
|
1828
1835
|
end
|
1829
1836
|
entry[:zip] = ask("Zip? ") do |q|
|
1830
1837
|
q.validate = /\A\d{5}(?:-?\d{4})?\Z/
|
@@ -163,7 +163,8 @@ class PadReader
|
|
163
163
|
rescue => err
|
164
164
|
$log.debug( err) if err
|
165
165
|
$log.debug(err.backtrace.join("\n")) if err
|
166
|
-
|
166
|
+
|
167
|
+
textdialog ["Error in padreader: #{err} ", *err.backtrace], :title => "Exception"
|
167
168
|
$error_message.value = ""
|
168
169
|
ensure
|
169
170
|
end
|
@@ -22,15 +22,6 @@ require 'rbcurse/core/widgets/rwidget'
|
|
22
22
|
#require 'rbcurse/deprecated/widgets/rmessagebox'
|
23
23
|
require 'rbcurse/core/widgets/rmessagebox'
|
24
24
|
|
25
|
-
# trying out 2011-12-4 so non-apps can get it.
|
26
|
-
require 'rbcurse/core/util/bottomline'
|
27
|
-
$tt ||= RubyCurses::Bottomline.new
|
28
|
-
$tt.name = "$tt"
|
29
|
-
require 'forwardable'
|
30
|
-
module Kernel
|
31
|
-
extend Forwardable
|
32
|
-
def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list, :say_with_pause, :hide_bottomline, :say_with_wait
|
33
|
-
end
|
34
25
|
# -- moving to the new Messagebox 2011-11-19 v 1.5.0
|
35
26
|
# Alert user with a one line message
|
36
27
|
#
|
@@ -66,7 +57,8 @@ end
|
|
66
57
|
# Are we doing anyhting to let caller know, cancel was pressed. FIXME
|
67
58
|
# @param [String] a label such as "Enter name:"
|
68
59
|
# @return [String] value entered by user
|
69
|
-
|
60
|
+
# @yield [Field] field created by messagebox
|
61
|
+
def get_string label, config={} # yield Field
|
70
62
|
config[:title] ||= "Entry"
|
71
63
|
label_config = config[:label_config] || {}
|
72
64
|
label_config[:row] ||= 2
|
@@ -97,6 +89,8 @@ def get_string label, config={}
|
|
97
89
|
item Label.new nil, label_config
|
98
90
|
item Field.new nil, field_config
|
99
91
|
end
|
92
|
+
# added yield to override settings
|
93
|
+
yield tp.form.by_name[:name] if block_given?
|
100
94
|
index = tp.run
|
101
95
|
if index == 0 # OK
|
102
96
|
return tp.form.by_name[:name].text
|
@@ -109,14 +103,15 @@ end
|
|
109
103
|
# new version using new messagebox
|
110
104
|
# @param [String] question
|
111
105
|
# @return [Boolean] true or false
|
112
|
-
#
|
106
|
+
# @yield [Label]
|
107
|
+
#
|
113
108
|
def confirm text, config={}, &block
|
114
109
|
title = config['title'] || "Confirm"
|
115
110
|
config[:default_button] ||= 0
|
116
|
-
|
111
|
+
|
117
112
|
mb = RubyCurses::MessageBox.new config do
|
118
113
|
title title
|
119
|
-
message text
|
114
|
+
message text, &block
|
120
115
|
button_type :yes_no
|
121
116
|
end
|
122
117
|
index = mb.run
|
@@ -131,140 +126,6 @@ end
|
|
131
126
|
# alert("You did not enter anything!", {"title"=>"Wake Up", "bgcolor"=>"blue", "color"=>"white"})
|
132
127
|
# block currently ignored. don't know what to do, can't pass it to MB since alread sending in a block
|
133
128
|
#
|
134
|
-
def DEPalert text, config={}, &block
|
135
|
-
title = config['title'] || "Alert"
|
136
|
-
#instance_eval &block if block_given?
|
137
|
-
if text.is_a? RubyCurses::Variable # added 2011-09-20 incase variable passed
|
138
|
-
text = text.get_value
|
139
|
-
end
|
140
|
-
mb = RubyCurses::MessageBox.new nil, config do
|
141
|
-
title title
|
142
|
-
message text
|
143
|
-
button_type :ok
|
144
|
-
end
|
145
|
-
end
|
146
|
-
# confirms from user returning :YES or :NO
|
147
|
-
# Darn, should have returned boolean, now have to live with it.
|
148
|
-
def OLDconfirm text, config={}, &block
|
149
|
-
title = config['title'] || "Confirm"
|
150
|
-
#instance_eval &block if block_given?
|
151
|
-
mb = RubyCurses::MessageBox.new nil, config do
|
152
|
-
title title
|
153
|
-
message text
|
154
|
-
button_type :yes_no
|
155
|
-
end
|
156
|
-
return mb.selected_index == 0 ? :YES : :NO
|
157
|
-
end
|
158
|
-
|
159
|
-
##
|
160
|
-
# allows user entry of a string.
|
161
|
-
# In config you may pass Field related properties such as chars_allowed, valid_regex, values, etc.
|
162
|
-
def DEPget_string(message, len=50, default="", config={})
|
163
|
-
|
164
|
-
config["input_config"] = {}
|
165
|
-
config["input_config"]["maxlen"] = len
|
166
|
-
config["maxlen"]=len
|
167
|
-
title = config["title"] || "Input required"
|
168
|
-
mb = RubyCurses::MessageBox.new nil, config do
|
169
|
-
title title
|
170
|
-
message message
|
171
|
-
type :input
|
172
|
-
button_type :ok
|
173
|
-
default_value default
|
174
|
-
end
|
175
|
-
return mb.input_value
|
176
|
-
end
|
177
|
-
|
178
|
-
##
|
179
|
-
# Added 2009-02-05 13:16
|
180
|
-
# get a string from user with some additional checkboxes and optionally supply default values
|
181
|
-
# Usage:
|
182
|
-
#sel, inp, hash = get_string_with_options("Enter a filter pattern", 20, "*", {"checkboxes" => ["case sensitive","reverse"], "checkbox_defaults"=>[true, false]})
|
183
|
-
# sel, inp, hash = get_string_with_options("Enter a filter pattern", 20, "*", {"checkboxes" => ["case sensitive","reverse"]})
|
184
|
-
# $log.debug " POPUP: #{sel}: #{inp}, #{hash['case sensitive']}, #{hash['reverse']}"
|
185
|
-
#
|
186
|
-
# @param: message to print,
|
187
|
-
# @param: length of entry field
|
188
|
-
# @param: default value of field
|
189
|
-
# @param: configuration of box or field
|
190
|
-
# checkboxes: array of strings to use as checkboxes
|
191
|
-
# checkbox_defaults : array of true/false default values for each cb
|
192
|
-
# @return: int 0 OK, 1 cancel pressed
|
193
|
-
# @return: string value entered
|
194
|
-
# @return: hash of strings and booleans for checkboxes and values
|
195
|
-
#
|
196
|
-
# @deprecated - user should be able to do this quite easily now.
|
197
|
-
def TODOget_string_with_options(message, len=20, default="", config={})
|
198
|
-
title = config["title"] || "Input required"
|
199
|
-
input_config = config["input_config"] || {}
|
200
|
-
checks = config["checkboxes"]
|
201
|
-
checkbox_defaults = config["checkbox_defaults"] || []
|
202
|
-
|
203
|
-
height = config["height"] || 1
|
204
|
-
display_length = config["display_length"] || 30
|
205
|
-
|
206
|
-
r = 3
|
207
|
-
c = 4
|
208
|
-
mform = RubyCurses::Form.new nil
|
209
|
-
message_label = RubyCurses::Label.new mform, {'text' => message, "name"=>"message_label","row" => r, "col" => c, "display_length" => display_length, "height" => height, "attr"=>"reverse"}
|
210
|
-
|
211
|
-
r += 1
|
212
|
-
input = RubyCurses::Field.new mform, input_config do
|
213
|
-
name "input"
|
214
|
-
row r
|
215
|
-
col c
|
216
|
-
display_length display_length
|
217
|
-
maxlen len
|
218
|
-
set_buffer default
|
219
|
-
end
|
220
|
-
if !checks.nil?
|
221
|
-
r += 2
|
222
|
-
checks.each_with_index do |cbtext,ix|
|
223
|
-
field = RubyCurses::CheckBox.new mform do
|
224
|
-
text cbtext
|
225
|
-
name cbtext
|
226
|
-
value checkbox_defaults[ix]||false
|
227
|
-
color 'black'
|
228
|
-
bgcolor 'white'
|
229
|
-
row r
|
230
|
-
col c
|
231
|
-
end
|
232
|
-
r += 1
|
233
|
-
end
|
234
|
-
end
|
235
|
-
radios = config["radiobuttons"]
|
236
|
-
if !radios.nil?
|
237
|
-
radio_default = config["radio_default"] || radios[0]
|
238
|
-
radio = RubyCurses::Variable.new radio_default
|
239
|
-
r += 2
|
240
|
-
radios.each_with_index do |cbtext,ix|
|
241
|
-
field = RubyCurses::RadioButton.new mform do
|
242
|
-
variable radio
|
243
|
-
text cbtext
|
244
|
-
value cbtext
|
245
|
-
color 'black'
|
246
|
-
bgcolor 'white'
|
247
|
-
row r
|
248
|
-
col c
|
249
|
-
end
|
250
|
-
r += 1
|
251
|
-
end
|
252
|
-
end
|
253
|
-
mb = RubyCurses::MessageBox.new mform do
|
254
|
-
title title
|
255
|
-
button_type :ok_cancel
|
256
|
-
default_button 0
|
257
|
-
end
|
258
|
-
hash = {}
|
259
|
-
if !checks.nil?
|
260
|
-
checks.each do |c|
|
261
|
-
hash[c] = mform.by_name[c].getvalue
|
262
|
-
end
|
263
|
-
end
|
264
|
-
hash["radio"] = radio.get_value unless radio.nil?
|
265
|
-
# returns button index (0 = OK), value of field, hash containing values of checkboxes
|
266
|
-
return mb.selected_index, mform.by_name['input'].getvalue, hash
|
267
|
-
end
|
268
129
|
|
269
130
|
# ------------------------ We've Moved here from window class ---------------- #
|
270
131
|
# #
|
@@ -277,22 +138,33 @@ end
|
|
277
138
|
# new version with a window created on 2011-10-1 12:37 AM
|
278
139
|
# Now can be separate from window class, needing nothing, just a util class
|
279
140
|
# prints a status message and pauses for a char
|
141
|
+
# @param [String] text to print
|
142
|
+
# @param [Hash] config: :color :bgcolor :color_pair
|
143
|
+
# :wait (numbr of seconds to wait for a key press and then close) if not givn
|
144
|
+
# will keep waiting for keypress (the default)
|
280
145
|
def print_status_message text, aconfig={}, &block
|
281
146
|
_print_message :status, text, aconfig, &block
|
282
147
|
end
|
148
|
+
alias :rb_puts print_status_message
|
149
|
+
|
283
150
|
# new version with a window created on 2011-10-1 12:30 AM
|
284
151
|
# Now can be separate from window class, needing nothing, just a util class
|
285
152
|
# Why are we dealing with $error_message, that was due to old idea which failed
|
286
153
|
# scrap it and send the message.
|
154
|
+
# @param [String] text to print
|
155
|
+
# @param [Hash] config: :color :bgcolor :color_pair
|
156
|
+
# :wait (numbr of seconds to wait for a key press and then close) if not givn
|
157
|
+
# will keep waiting for keypress (the default)
|
287
158
|
def print_error_message text, aconfig={}, &block
|
288
159
|
_print_message :error, text, aconfig, &block
|
289
160
|
end
|
290
|
-
|
161
|
+
private
|
162
|
+
def _create_footer_window h = 2 , w = Ncurses.COLS, t = Ncurses.LINES-2, l = 0 #:nodoc:
|
291
163
|
ewin = VER::Window.new(h, w , t, l)
|
292
164
|
end
|
293
165
|
# @param [:symbol] :error or :status kind of message
|
294
|
-
#
|
295
|
-
def _print_message type, text, aconfig={}, &block
|
166
|
+
#private
|
167
|
+
def _print_message type, text, aconfig={}, &block #:nodoc:
|
296
168
|
case text
|
297
169
|
when RubyCurses::Variable # added 2011-09-20 incase variable passed
|
298
170
|
text = text.get_value
|
@@ -300,30 +172,55 @@ def _print_message type, text, aconfig={}, &block
|
|
300
172
|
text = text.to_s
|
301
173
|
end
|
302
174
|
# NOTE we are polluting global namespace
|
303
|
-
|
175
|
+
# fixed on 2011-12-6 . to test
|
176
|
+
#aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
|
177
|
+
color = aconfig[:color]
|
178
|
+
bgcolor = aconfig[:bgcolor]
|
304
179
|
ewin = _create_footer_window #*@layout
|
305
180
|
r = 0; c = 1;
|
306
181
|
case type
|
307
182
|
when :error
|
308
|
-
|
309
|
-
|
183
|
+
color ||= 'red'
|
184
|
+
bgcolor ||= 'black'
|
310
185
|
else
|
311
|
-
|
312
|
-
|
186
|
+
color ||= :white
|
187
|
+
bgcolor ||= :black
|
313
188
|
end
|
314
|
-
color_pair = get_color($promptcolor,
|
189
|
+
color_pair = get_color($promptcolor, color, bgcolor)
|
190
|
+
color_pair = aconfig[:color_pair] || color_pair
|
315
191
|
ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
|
316
192
|
ewin.printstring r, c, text, color_pair
|
317
|
-
ewin.printstring
|
193
|
+
ewin.printstring(r+1, c, "Press a key ", color_pair) unless aconfig[:wait]
|
318
194
|
ewin.wrefresh
|
319
|
-
|
195
|
+
if aconfig[:wait]
|
196
|
+
#try this out, if user wants a wait, then it will wait for 5 seconds, or if a key is pressed sooner
|
197
|
+
value = aconfig[:wait]
|
198
|
+
if value.is_a? Fixnum
|
199
|
+
value = value * 10
|
200
|
+
else
|
201
|
+
value = 50
|
202
|
+
end
|
203
|
+
Ncurses::halfdelay(tenths = value)
|
204
|
+
ewin.getch
|
205
|
+
Ncurses::halfdelay(tenths = 10)
|
206
|
+
else
|
207
|
+
ewin.getchar
|
208
|
+
end
|
320
209
|
ewin.destroy
|
321
210
|
end
|
322
211
|
#
|
323
212
|
# Alternative to confirm dialog, if you want this look and feel, at last 2 lines of screen
|
324
213
|
# @param [String] text to prompt
|
325
214
|
# @return [true, false] 'y' is true, all else if false
|
326
|
-
|
215
|
+
public
|
216
|
+
def rb_confirm text, aconfig={}, &block
|
217
|
+
# backward compatibility with agree()
|
218
|
+
if aconfig == true || aconfig == false
|
219
|
+
default = aconfig
|
220
|
+
aconfig = {}
|
221
|
+
else
|
222
|
+
default = aconfig[:default]
|
223
|
+
end
|
327
224
|
case text
|
328
225
|
when RubyCurses::Variable # added 2011-09-20 incase variable passed
|
329
226
|
text = text.get_value
|
@@ -332,10 +229,13 @@ def confirm_window text, aconfig={}, &block
|
|
332
229
|
end
|
333
230
|
ewin = _create_footer_window
|
334
231
|
r = 0; c = 1;
|
335
|
-
aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
|
336
|
-
|
337
|
-
|
338
|
-
|
232
|
+
#aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
|
233
|
+
# changed on 2011-12-6
|
234
|
+
color = aconfig[:color]
|
235
|
+
bgcolor = aconfig[:bgcolor]
|
236
|
+
color ||= :white
|
237
|
+
bgcolor ||= :black
|
238
|
+
color_pair = get_color($promptcolor, color, bgcolor)
|
339
239
|
ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
|
340
240
|
ewin.printstring r, c, text, color_pair
|
341
241
|
ewin.printstring r+1, c, "[y/n]", color_pair
|
@@ -344,13 +244,21 @@ def confirm_window text, aconfig={}, &block
|
|
344
244
|
retval = false
|
345
245
|
begin
|
346
246
|
ch = ewin.getchar
|
247
|
+
retval = (ch == 'y'.ord || ch == 'Y'.ord )
|
248
|
+
# if caller passed a default value and user pressed ENTER return that
|
249
|
+
# can be true or false so don't change this to "if default". 2011-12-8
|
250
|
+
if !default.nil?
|
251
|
+
if ch == 13 || ch == KEY_ENTER
|
252
|
+
retval = default
|
253
|
+
end
|
254
|
+
end
|
347
255
|
#retval = :YES if ch.chr == 'y'
|
348
|
-
retval = (ch.chr == 'y' )
|
349
256
|
ensure
|
350
257
|
ewin.destroy
|
351
258
|
end
|
352
259
|
retval
|
353
260
|
end
|
261
|
+
alias :confirm_window :rb_confirm
|
354
262
|
# class created to display multiple messages without asking for user to hit a key
|
355
263
|
# returns a window to which one can keep calling printstring with 0 or 1 as row.
|
356
264
|
# destroy when finished.
|
@@ -451,6 +359,7 @@ end
|
|
451
359
|
# You may also pass bgcolor and color
|
452
360
|
# @since 1.4.1 2011-11-1
|
453
361
|
def popuplist list, config={}, &block
|
362
|
+
raise ArgumentError, "Nil list received by popuplist" unless list
|
454
363
|
require 'rbcurse/core/widgets/rlist'
|
455
364
|
|
456
365
|
max_visible_items = config[:max_visible_items]
|
@@ -522,6 +431,7 @@ def popuplist list, config={}, &block
|
|
522
431
|
end
|
523
432
|
# returns length of longest
|
524
433
|
def longest_in_list list #:nodoc:
|
434
|
+
raise ArgumentError, "rdialog.rb: longest_in_list recvd nil list" unless list
|
525
435
|
longest = list.inject(0) do |memo,word|
|
526
436
|
memo >= word.length ? memo : word.length
|
527
437
|
end
|