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/README.md CHANGED
@@ -35,7 +35,7 @@ Core intends to be :
35
35
 
36
36
  * be backward compatible.
37
37
 
38
- * simple, maintaible code
38
+ * simple, maintainable code
39
39
 
40
40
  I shall be standardizing core over the next one or two minor versions. I shall also be simplifying code as much as possible to make it maintainable and more bug-free.
41
41
 
@@ -44,6 +44,10 @@ The new tabbedpane and messagebox will replace the old ones, while the old ones
44
44
 
45
45
  Color formatting needs to be standardized and a proper API firmed up for that, so user code does not get affected by internal changes. Similarly, work on textpad may get integrated into some widgets since it could simplify their code.
46
46
 
47
+ I have not yet begun working on extras and experimental as yet. This contains code that was working
48
+ in rbcurse-1.5, but not tested or touched since then. I will only get around there after polishing
49
+ the core a bit more. The code lies on github.
50
+
47
51
  ## Install
48
52
 
49
53
  `gem install rbcurse-core` # just the core
@@ -58,7 +62,7 @@ Color formatting needs to be standardized and a proper API firmed up for that, s
58
62
 
59
63
  * rbcurse - <http://github.com/rkumar/rbcurse/>
60
64
 
61
- * rbcurse-core - <http://github.com/rkumar/rbcurse-core/>
65
+ * rbcurse-extras - <http://github.com/rkumar/rbcurse-extras/>
62
66
 
63
67
  * rbcurse-experimental - <http://github.com/rkumar/rbcurse-experimental/>
64
68
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -140,7 +140,7 @@ App.new do
140
140
  end
141
141
 
142
142
 
143
- label({:text => "F1 Help, F10 Quit. Press F4 and F5 to test popup, space or enter to select", :row => Ncurses.LINES-1, :col => 0})
143
+ label({:text => "F1 Help, F10 Quit. : for menu. Press F4 and F5 to test popup, space or enter to select", :row => Ncurses.LINES-1, :col => 0})
144
144
 
145
145
  @form.bind_key(FFI::NCurses::KEY_F4) { row = lb.current_index+lb.row; col=lb.col+lb.current_value.length+1; ret = popuplist(%w[ andy berlioz strauss tchaiko matz beethoven], :row => row, :col => col, :title => "Names", :bgcolor => :blue, :color => :white) ; alert "got #{ret} "}
146
146
 
data/examples/bline.rb ADDED
@@ -0,0 +1,135 @@
1
+ require 'rbcurse/core/util/app'
2
+ require 'rbcurse/core/util/bottomline'
3
+ require 'fileutils'
4
+
5
+ # this will go into top namespace so will conflict with other apps!
6
+ def testnumberedmenu
7
+ list1 = %w{ ruby perl python erlang rake java lisp scheme chicken }
8
+ list1[0] = %w{ ruby ruby1.9 ruby1.8.x jruby rubinius ROR }
9
+ list1[5] = %w{ java groovy grails }
10
+ str = numbered_menu list1, { :title => "Languages: ", :prompt => "Select :" }
11
+ $log.debug "17 We got #{str.class} "
12
+ message "We got #{str} "
13
+ end
14
+ def testdisplay_list
15
+ # scrollable list
16
+ text = Dir.glob "*.rb"
17
+ $log.debug "XXX: DDD got #{text.size} "
18
+ str = display_list text, :title => "Select a file"
19
+ $log.debug "23 We got #{str} : #{str.class} , #{str.list[str.current_index]} "
20
+ file = str.list[str.current_index]
21
+ #message "We got #{str.list[str.current_index]} "
22
+ show file
23
+ end
24
+ def testdisplay_text
25
+ str = display_text_interactive File.read($0), :title => "#{$0}"
26
+ end
27
+ def testdir
28
+ # this behaves like vim's file selector, it fills in values
29
+ str = ask("File? ", Pathname) do |q|
30
+ q.completion_proc = Proc.new {|str| Dir.glob(str +"*").collect { |f| File.directory?(f) ? f+"/" : f } }
31
+ q.help_text = "Enter start of filename and tab to get completion"
32
+ end
33
+ message "We got #{str} "
34
+ show str
35
+ end
36
+ # if components have some commands, can we find a way of passing the command to them
37
+ # method_missing gave a stack overflow.
38
+ def execute_this(meth, *args)
39
+ alert " #{meth} not found ! "
40
+ $log.debug "app email got #{meth} " if $log.debug?
41
+ cc = @form.get_current_field
42
+ [cc].each do |c|
43
+ if c.respond_to?(meth, true)
44
+ c.send(meth, *args)
45
+ return true
46
+ end
47
+ end
48
+ false
49
+ end
50
+
51
+ App.new do
52
+ def show file
53
+ w = @form.by_name["tv"]
54
+ if File.exists? file
55
+ lines = File.open(file,'r').readlines
56
+ w.text lines
57
+ w.title "[ #{file} ]"
58
+ end
59
+ end
60
+ def testchoose
61
+ # list filters as you type
62
+ $log.debug "called CHOOSE " if $log.debug?
63
+ filter = "*"
64
+ filter = ENV['PWD']+"/*"
65
+ str = choose filter, :title => "Files", :prompt => "Choose a file: (Alt-h Help) ",
66
+ :help_text => "Enter first char/s and tab to complete filename. Scroll with C-n, C-p"
67
+ if str
68
+ message "We got #{str} "
69
+ show str
70
+ end
71
+ end
72
+ ht = 24
73
+ borderattrib = :reverse
74
+ @header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Bottomline Test",
75
+ :text_right =>"Click :", :color => :white, :bgcolor => 235
76
+ message "Press F10 to exit, F1 Help, : for Menu "
77
+
78
+
79
+
80
+ # commands that can be mapped to or executed using M-x
81
+ # however, commands of components aren't yet accessible.
82
+ def get_commands
83
+ %w{ testchoose testnumberedmenu testdisplay_list testdisplay_text testdir }
84
+ end
85
+ def help_text
86
+ <<-eos
87
+ BOTTOMLINE HELP
88
+
89
+ These are some features for either getting filenames from user
90
+ at the bottom of the window like vim and others do.
91
+
92
+ : - Command mode
93
+ F1 - Help
94
+ F10 - Quit application
95
+
96
+ Some commands for using bottom of screen as vim and emacs do.
97
+ These may be selected by pressing ':'
98
+
99
+ testchoose - filter directory list as you type
100
+ testdir - vim style, tabbing completes matching files
101
+ testnumberedmenu - use menu indexes to select options
102
+ testdisplaylist - display a list at bottom of screen
103
+ Press <ENTER> to select.
104
+ testdisplaytext - display text at bottom (current file contents)
105
+ Press <ENTER> when done.
106
+
107
+ The file/dir selection options are very minimally functional. Improvements
108
+ and thorough testing are required. I've only tested them out gingerly.
109
+
110
+ -----------------------------------------------------------------------
111
+ :n or Alt-n for general help.
112
+ eos
113
+ end
114
+
115
+ #install_help_text help_text
116
+
117
+ def app_menu
118
+ menu = PromptMenu.new self do
119
+ item :c, :testchoose
120
+ item :d, :testdir
121
+ item :n, :testnumberedmenu
122
+ item :l, :testdisplay_list
123
+ item :t, :testdisplay_text
124
+ end
125
+ menu.display_new :title => "Menu"
126
+ end
127
+ @form.bind_key(?:) { app_menu; }
128
+
129
+ stack :margin_top => 1, :margin_left => 0, :width => :expand , :height => FFI::NCurses.LINES-2 do
130
+ tv = textview :height_pc => 100, :width_pc => 100, :name => "tv"
131
+ end # stack
132
+
133
+ sl = status_line :row => Ncurses.LINES-1
134
+ testdisplay_list
135
+ end # app
data/examples/dbdemo.rb CHANGED
@@ -81,7 +81,7 @@ def view_sql stmt
81
81
  rescue => err
82
82
  $log.error err.to_s
83
83
  $log.error(err.backtrace.join("\n"))
84
- alert err.to_s
84
+ textdialog [err.to_s, *err.backtrace], :title => "Exception"
85
85
  end
86
86
  end
87
87
 
@@ -279,23 +279,23 @@ App.new do
279
279
  alert "Select a table first."
280
280
  end
281
281
  end
282
- clist.bind_key('w') {
282
+ clist.bind_key('w', 'add to where condition') {
283
283
  c = clist.current_value
284
284
  $where_columns ||= []
285
285
  hist = ["#{c} = "]
286
- w = ask("(UP arrow to edit) where "){ |q| q.default = "#{c} = "; q.history = hist }
286
+ w = rb_gets("where "){ |q| q.default = "#{c} = "; q.history = hist }
287
287
  $where_columns << w if w
288
288
  message "where: #{$where_columns.last}. Press F4 when done"
289
289
  $log.debug "XXX: WHERE: #{$where_columns} "
290
290
  }
291
- clist.bind_key('o') {
291
+ clist.bind_key('o', 'add to order by') {
292
292
  c = clist.current_value
293
293
  $order_columns ||= []
294
294
  $order_columns << c if c
295
295
  message "order (asc): #{$order_columns.last}. Press F4 when done"
296
296
  $log.debug "XXX: ORDER: #{$order_columns} "
297
297
  }
298
- clist.bind_key('O') {
298
+ clist.bind_key('O', 'add to ordery by desc') {
299
299
  c = clist.current_value
300
300
  $order_columns ||= []
301
301
  $order_columns << " #{c} desc " if c
@@ -338,7 +338,7 @@ App.new do
338
338
  tarea_keyarray = keyarray + [ ["M-z", "Commands"], nil ]
339
339
  #tarea_sub_keyarray = [ ["r", "Run"], ["c", "clear"], ["w","Save"], ["a", "Append next"],
340
340
  #["y", "Yank"], ["Y", "yank pop"] ]
341
- tarea_sub_keyarray = [ ["r", "Run"], ["c", "clear"], ["w","Kill Ring Save (M-w)"], ["a", "Append Next"],
341
+ tarea_sub_keyarray = [ ["r", "Run"], ["c", "clear"], ["e", "Edit externally"], ["w","Kill Ring Save (M-w)"], ["a", "Append Next"],
342
342
  ["y", "Yank (C-y)"], ["Y", "yank pop (M-y)"],
343
343
  ["u", "Undo (C-_)"], ["R", "Redo (C-r)"],
344
344
  ]
@@ -373,18 +373,18 @@ App.new do
373
373
  end
374
374
 
375
375
 
376
- @form.bind_key([?q,?q]) { throw :close }
377
- @form.bind_key(?\M-t) do
376
+ @form.bind_key([?q,?q], 'quit') { throw :close }
377
+ @form.bind_key(?\M-t, 'select table') do
378
378
  if $current_db.nil?
379
379
  alert "Please select database first"
380
380
  else
381
381
  create_popup( get_table_names,:single) {|value| $selected_table = $current_table = value}
382
382
  end
383
383
  end
384
- @form.bind_key(?\M-d) do
384
+ @form.bind_key(?\M-d, 'select database') do
385
385
  ask_databases
386
386
  end
387
- @form.bind_key(FFI::NCurses::KEY_F4) do
387
+ @form.bind_key(FFI::NCurses::KEY_F4, 'view data') do
388
388
  $where_string = nil
389
389
  $order_string = nil
390
390
  if $where_columns
@@ -409,7 +409,7 @@ App.new do
409
409
  stack :width_pc => 80 do
410
410
  tarea = textarea :name => 'tarea', :height => 5, :title => 'Sql Statement'
411
411
  #undom = SimpleUndo.new tarea
412
- tarea.bind_key(Ncurses::KEY_F4) do
412
+ tarea.bind_key(Ncurses::KEY_F4, 'view data') do
413
413
  text = tarea.get_text
414
414
  if text == ""
415
415
  alert "Please enter a query and then hit F4. Or press F4 over column list"
@@ -418,9 +418,10 @@ App.new do
418
418
  end
419
419
  end
420
420
  tarea.bind(:ENTER) { @adock.mode :tarea }
421
- tarea.bind_key(?\M-z){
421
+ tarea.bind_key(?\M-z, 'textarea submenu'){
422
422
 
423
423
  hash = { 'c' => lambda{ tarea.remove_all },
424
+ 'e' => lambda{ tarea.edit_external },
424
425
  'w' => lambda{ tarea.kill_ring_save },
425
426
  'a' => lambda{ tarea.append_next_kill },
426
427
  'y' => lambda{ tarea.yank },
@@ -451,7 +452,7 @@ App.new do
451
452
  #button_row = 17
452
453
  button "Save" do
453
454
  @cmd_history ||= []
454
- filename = ask("File to append contents to: ") { |q| q.default = @oldfilename; q.history = @cmd_history }
455
+ filename = rb_gets("File to append contents to: ") { |q| q.default = @oldfilename; q.history = @cmd_history }
455
456
 
456
457
  if filename
457
458
  str = tarea.get_text
@@ -463,16 +464,21 @@ App.new do
463
464
  else
464
465
  message "Aborted operation"
465
466
  end
466
- hide_bottomline
467
+ #hide_bottomline
467
468
  end
468
469
  button "Read" do
469
470
  filter = "*"
470
- str = choose filter, :title => "Files", :prompt => "Choose a file: "
471
- begin
472
- tarea.set_content(str)
473
- message "Read content from #{str} "
474
- rescue => err
475
- say_with_pause "No file named: #{str}: #{err.to_s} "
471
+ #str = choose filter, :title => "Files", :prompt => "Choose a file: "
472
+ cproc = Proc.new { |str| Dir.glob(str + "*") }
473
+ str = rb_gets "Choose a file: ", :title => "Files", :tab_completion => cproc,
474
+ :help_text => "Press <tab> to complete filenames. C-a, C-e, C-k. Alt-?"
475
+ if str && File.exists?(str)
476
+ begin
477
+ tarea.set_content(str)
478
+ message "Read content from #{str} "
479
+ rescue => err
480
+ print_error_message "No file named: #{str}: #{err.to_s} "
481
+ end
476
482
  end
477
483
  end
478
484
  #ok_button = button( [button_row,30], "OK", {:mnemonic => 'O'}) do
data/examples/term2.rb CHANGED
@@ -25,7 +25,7 @@ require 'rbcurse/core/widgets/scrollbar'
25
25
  end
26
26
  App.new do
27
27
  header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Tabular Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
28
- message "Press F10 to escape from here"
28
+ message "F10 quit, F1 Help, ? Bindings"
29
29
  install_help_text my_help_text
30
30
 
31
31
  flow :width => FFI::NCurses.COLS , :height => FFI::NCurses.LINES-2 do
@@ -109,7 +109,7 @@ if $0 == __FILE__
109
109
  listb.one_key_selection = false # this allows us to map keys to methods
110
110
  listb.vieditable_init_listbox
111
111
  include Io
112
- listb.bind_key(?r, 'get file'){ get_file("Get a file:", 70) }
112
+ listb.bind_key(?r, 'get file'){ get_file("Get a file:") }
113
113
  listb.bind(:PRESS) {
114
114
  w = @form.by_name["tv"];
115
115
  lines = `ri -f bs #{listb.text}`.split("\n")
@@ -131,9 +131,11 @@ if $0 == __FILE__
131
131
  w = ev.word_under_cursor.strip
132
132
  # check that user did not hit enter on empty area
133
133
  if w != ""
134
- text = `ri -f bs #{tv.title}.#{w}` rescue "No details for #{w}"
135
- text = text.split("\n")
136
- view(text, :content_type => :ansi)
134
+ _text = `ri -f bs #{tv.title}.#{w} 2>&1`
135
+ _text = _text.split("\n")
136
+ if _text && _text.size != 0
137
+ view(_text, :content_type => :ansi)
138
+ end
137
139
  end
138
140
  }
139
141
 
@@ -100,12 +100,14 @@ module RubyCurses
100
100
  RubyCurses::Viewer.view(res.split("\n"), :close_key => KEY_ENTER, :title => "<Enter> to close, M-l M-h to scroll")
101
101
  end
102
102
  def shell_out command
103
- @window.hide
103
+ w = @window || @form.window
104
+ w.hide
104
105
  Ncurses.endwin
105
- system command
106
+ ret = system command
106
107
  Ncurses.refresh
107
108
  #Ncurses.curs_set 0 # why ?
108
- @window.show
109
+ w.show
110
+ return ret
109
111
  end
110
112
  end # utils
111
113
  end # module RubyC
@@ -7,252 +7,207 @@
7
7
  # Current are:
8
8
  # * rbgetstr (and those it calls)
9
9
  # * display_cmenu and create_mitem
10
+ # Changes:
11
+ # 2011-12-6 : removed many old, outdated methods.
10
12
  #*******************************************************#
11
- ##
12
- # added RK 2010-11-02 18:11 so can be used in widgets too
13
- # maybe can be removed from app, if accessible there too.
14
- require 'forwardable'
15
- require 'rbcurse/core/util/bottomline'
16
- #$terminal = RubyCurses::Bottomline.new
17
- #$terminal.name = "$terminal io.rb"
18
- #module Kernel
19
- #extend Forwardable
20
- #def_delegators :$terminal, :agree, :ask, :choose, :say
21
- #end
22
- #$tt.window = @window; $tt.message_row = @message_row # <<-- TODO somewhere
23
13
  module Io
24
14
 
25
- # from which line to print in footer_win
26
- LINEONE = 1
27
- FOOTER_COLOR_PAIR = 6
28
- MAIN_WINDOW_COLOR_PAIR = 5
29
- ERROR_COLOR_PAIR = 7
30
-
15
+ # create a 2 line window at bottom to accept user input
16
+ #
17
+ def __create_footer_window h = 2 , w = Ncurses.COLS, t = Ncurses.LINES-2, l = 0
18
+ ewin = VER::Window.new(h, w , t, l)
19
+ end
20
+ # 2011-11-27 I have replaced the getting of chars with a field
21
+
22
+ # routine to get a string at bottom of window.
23
+ # The first 3 params are no longer required since we create a window
24
+ # of our own.
25
+ # @param [String] prompt - label to show
26
+ # @param [Fixnum] maxlen - max length of input
27
+ # @param [Hash] config - :default, :display_length of Field, :help_text, :tab_completion
28
+ # help_text is displayed on F1
29
+ # tab_completion is a proc which helps to complete user input
30
+ # This method is now only for backward compatibility
31
+ # rbgetstr had various return codes based on whether user asked for help
32
+ # possibly mimicking alpine, or because i could do nothing about it.
33
+ # Now, rbgets handles that and only returns if the user cancels or enters
34
+ # a string, so rbgets does not need to return other codes.
35
+ def rbgetstr(nolongerused, r, c, prompt, maxlen, config={})
36
+ config[:maxlen] = maxlen
37
+ str = rb_gets(prompt, config)
38
+ if str
39
+ return 0, str
40
+ else
41
+ return -1, nil
42
+ end
43
+ end
44
+
45
+ # get a string at the bottom of the screen
46
+ #
47
+ # @param [String] prompt - label to show
48
+ # @param [Hash] config - :default, :display_length of Field, :help_text, :tab_completion
49
+ # help_text is displayed on F1
50
+ # tab_completion is a proc which helps to complete user input
51
+ # @yield [Field] for overriding or customization
52
+ # @return [String, nil] String if entered, nil if canceled
53
+ def rb_gets(prompt, config={}) # yield field
54
+ if config.is_a? Array
55
+ options = config
56
+ completion_proc = Proc.new{|str|
57
+ options.dup.grep Regexp.new("^#{str}");
58
+ }
59
+ config = {}
60
+ config[:tab_completion] = completion_proc
61
+ end
62
+ begin
63
+ win = __create_footer_window
64
+ form = Form.new win
65
+ r = 0; c = 1;
66
+ default = config[:default] || ""
67
+ prompt = "#{prompt} [#{default}]:" if default.size > 0
68
+ _max = FFI::NCurses.COLS-1-prompt.size-4
69
+ displen = config[:display_length] || [config[:maxlen] || 999, _max].min
70
+ maxlen = config[:maxlen] || _max
71
+ field = Field.new form, :row => r, :col => c, :maxlen => maxlen, :default => default, :label => prompt,
72
+ :display_length => displen
73
+ bg = Ncurses.COLORS >= 236 ? 233 : :blue
74
+ field.bgcolor = bg
75
+ field.cursor_end if default.size > 0
76
+ def field.default=(x); default(x);end
77
+
78
+ # if user wishes to use the yield and say "field.history = [x,y,z] then
79
+ # we should alredy have extended this, so lets make it permanent
80
+ #if config[:history]
81
+ #raise ArgumentError, "Field history must be an array" unless config[:history].is_a? Array
82
+ require 'rbcurse/core/include/rhistory'
83
+ field.extend(FieldHistory)
84
+ #field.history_config :row =>
85
+ field.history = config[:history]
86
+ #end
31
87
 
32
- def __create_footer_window h = 2 , w = Ncurses.COLS, t = Ncurses.LINES-2, l = 0
33
- ewin = VER::Window.new(h, w , t, l)
34
- end
35
- # complex version of get_string that allows for trappng of control character
36
- # such as C-c and C-h and TAB for completion
37
- # validints contains int codes not chars.
38
- # NOTE: change. C-g was help key in alpine but abort key in emacs. C-c sometimes
39
- # crashes app, so i am using C-g as abort. Help on M-h
40
- # TODO We should put a field there, make it visible and mv it to after the prompt
41
- # and handle all editing events on it.
42
- # @return status_code, string (0 if okay, 7 if help asked for, -1 for abort
43
- #def rbgetstr(win, r, c, prompt, maxlen, default, labels, validints=[], helptext="")
44
- # 2011-11-27 I have replaced the getting of chars with a field
45
- # Still need to handle tab-completion, can do that with horizlist !! YEAHHH !!!
46
- def rbgetstr(nolongerused, r, c, prompt, maxlen, config={})
47
- begin
48
- win = __create_footer_window
49
- form = Form.new win
50
- r = 0; c = 1;
51
- default = config[:default] || ""
52
- displen = config[:display_length] || maxlen
53
- prompt = "#{prompt} [#{default}]: " unless default
54
- field = Field.new form, :row => r, :col => c, :maxlen => maxlen, :default => default, :label => prompt,
55
- :display_length => displen
56
- #require 'rbcurse/core/include/rhistory'
57
- #field.extend(FieldHistory)
58
- #field.history_config :row => FFI::NCurses.LINES-12
59
- #field.history %w[ jim john jack ruby jane jill just testing ]
60
- form.repaint
61
- win.wrefresh
62
- prevchar = 0
63
- entries = nil
64
- while ((ch = win.getchar()) != 999)
65
- break if ch == 10 || ch == 13
66
- return -1, nil if ch == ?\C-c.getbyte(0) || ch == ?\C-g.getbyte(0)
67
- #if ch == ?\M-h.getbyte(0) # HELP KEY
68
- #helptext = config[:helptext] || "No help provided"
88
+ yield field if block_given?
89
+ form.repaint
90
+ win.wrefresh
91
+ prevchar = 0
92
+ entries = nil
93
+ oldstr = nil # for tab completion, origal word entered by user
94
+ while ((ch = win.getchar()) != 999)
95
+ break if ch == 10 || ch == 13 || ch == KEY_ENTER
96
+ #return -1, nil if ch == ?\C-c.getbyte(0) || ch == ?\C-g.getbyte(0)
97
+ return nil if ch == ?\C-c.getbyte(0) || ch == ?\C-g.getbyte(0)
98
+ #if ch == ?\M-h.getbyte(0) # HELP KEY
99
+ #help_text = config[:help_text] || "No help provided"
69
100
  #color = $datacolor
70
- #print_help(win, r, c, color, helptext)
101
+ #print_help(win, r, c, color, help_text)
71
102
  ## this will come over our text
72
- #end
73
- # TODO tab completion and help_text print on F1
74
- # that field objects can extend, same for tab completion and gmail completion
75
- if ch == KEY_TAB
103
+ #end
104
+ # TODO tab completion and help_text print on F1
105
+ # that field objects can extend, same for tab completion and gmail completion
106
+ if ch == KEY_TAB
76
107
  if config
77
108
  str = field.text
78
- if prevchar == 9
109
+ if prevchar == KEY_TAB
79
110
  if !entries.nil? && !entries.empty?
80
111
  str = entries.delete_at(0)
112
+ else
113
+ str = oldstr if oldstr
114
+ prevchar = ch = nil # so it can start again completing
81
115
  end
82
116
  else
83
117
  tabc = config[:tab_completion] unless tabc
84
118
  next unless tabc
85
- entries = tabc.call(str)
86
- $log.debug " tab got #{entries} "
119
+ oldstr = str.dup
120
+ entries = tabc.call(str).dup
121
+ $log.debug " tab got #{entries} for str=#{str}"
87
122
  str = entries.delete_at(0) unless entries.nil? || entries.empty?
123
+ str = str.to_s.dup
88
124
  end
89
125
  if str
90
126
  field.text = str
127
+ field.cursor_end
91
128
  field.set_form_col # shit why are we doign this, text sets curpos to 0
92
129
  end
93
130
  form.repaint
94
131
  win.wrefresh
95
132
  end
96
133
 
97
- # tab_completion
98
- # if previous char was not tab, execute tab_completion_proc and push first entry
99
- # else push the next entry
100
- elsif ch == KEY_F1
101
- helptext = config[:helptext] || "No help provided. C-c/C-g aborts. <TAB> completion. Alt-h history. C-a/e"
102
- print_status_message helptext
134
+ # tab_completion
135
+ # if previous char was not tab, execute tab_completion_proc and push first entry
136
+ # else push the next entry
137
+ elsif ch == KEY_F1
138
+ help_text = config[:help_text] || "No help provided. C-c/C-g aborts. <TAB> completion. Alt-h history. C-a/e"
139
+ print_status_message help_text, :wait => 7
140
+ else
141
+ form.handle_key ch
142
+ end
143
+ prevchar = ch
144
+ win.wrefresh
103
145
  end
104
- prevchar = ch
105
- form.handle_key ch
106
- win.wrefresh
146
+ rescue => err
147
+ Ncurses.beep
148
+ textdialog [err.to_s, *err.backtrace], :title => "Exception"
149
+ $log.error "EXC in rbgetsr #{err} "
150
+ $log.error(err.backtrace.join("\n"))
151
+ ensure
152
+ win.destroy if win
107
153
  end
108
- rescue => err
109
- Ncurses.beep
110
- $log.error "EXP in rbgetsr #{err} "
111
- $log.error(err.backtrace.join("\n"))
112
- ensure
113
- win.destroy if win
154
+ config[:history] << field.text if config[:history] && field.text
155
+ return field.text
114
156
  end
115
- return 0, field.text
116
- end
117
- def originalrbgetstr(nolongerused, r, c, prompt, maxlen, config={})
118
- #win ||= @target_window
119
- win = __create_footer_window
120
- $log.debug " inside io.rb rbgetstr #{win} r:#{r} c:#{c} p:#{prompt} m:#{maxlen} #{win.name} "
121
- r = 0; c = 1;
122
- ins_mode = false
123
- default = config[:default] || ""
124
- prompt = "#{prompt} [#{default}]: " unless default
125
- len = prompt.length
126
157
 
127
- # clear the area of len+maxlen
128
- color = $datacolor
129
- str = default
130
- #clear_this win, r, c, color, len+maxlen+1
131
- print_this(win, prompt+str, color, r, c)
132
- len = prompt.length + str.length
133
- #x mylabels=["^G~Help ", "^C~Cancel"]
134
- #x mylabels += labels if !labels.nil?
158
+ # get a character.
159
+ # unlike rb_gets allows user to enter control or alt or function character too.
160
+ # @param [String] prompt or label to show.
161
+ # @param [Hash] configuration such as default or regexp for validation
162
+ # @return [Fixnum] nil if canceled, or ret value of getchar which is numeric
163
+ # If default provided, then ENTER returns the default
164
+ def rb_getchar(prompt, config={}) # yield field
135
165
  begin
136
- Ncurses.noecho(); # FFI RK 2011-09-11 seems this was causing issue of writing on top
137
- #x print_key_labels( 0, 0, mylabels)
138
- #curpos = 0
139
- curpos = str.length
166
+ win = __create_footer_window
167
+ #form = Form.new win
168
+ r = 0; c = 1;
169
+ default = config[:default]
170
+ prompt = "#{prompt} [#{default}] " if default
171
+ win.mvprintw(r, c, "%s: " % prompt);
172
+ bg = Ncurses.COLORS >= 236 ? 236 : :blue
173
+ color_pair = get_color($reversecolor, :white, bg)
174
+ win.printstring r, c + prompt.size + 2, " ", color_pair
175
+
176
+ win.wrefresh
140
177
  prevchar = 0
141
178
  entries = nil
142
- #win.mvwgetnstr(LINEONE-3,askstr.length,yn,maxlen)
143
- while true
144
- #ch=win.mvwgetch(r, len) # get to right of prompt - WHY NOT WORKING ???
145
- ch=win.getchar()
146
- $log.debug "io.rb rbgetstr got ch:#{ch}, #{win} , str:#{str}, len: #{len} "
147
- case ch
148
- when 3 # -1 # C-c
149
- return -1, nil
150
- when ?\C-g.getbyte(0) # ABORT
151
- return -1, nil
152
- when 10, 13 # hits ENTER
153
- break
154
- when ?\C-h.getbyte(0), ?\C-?.getbyte(0), KEY_BSPACE, 263 # delete previous character/backspace
155
- # currently hitting C-h is giving 263 instead of 8
156
- len -= 1 if len > prompt.length
157
- curpos -= 1 if curpos > 0
158
- str.slice!(curpos)
159
- clear_this win, r, c, color, len+maxlen+1
160
- #print_this(win, prompt+str, color, r, c)
161
- when 330 # delete character on cursor
162
- #len -= 1 if len > prompt.length
163
- #curpos -= 1 if curpos > 0
164
- str.slice!(curpos) #rescue next
165
- clear_this win, r, c, color, len+maxlen+1
166
- when ?\M-h.getbyte(0) # HELP KEY
167
- #x print_footer_help(helptext)
168
- helptext = config[:helptext] || "No help provided"
169
- print_help(win, r, c, color, helptext)
170
- return 7, nil
171
- when KEY_LEFT
172
- curpos -= 1 if curpos > 0
173
- len -= 1 if len > prompt.length
174
- win.wmove r, c+len # since getchar is not going back on del and bs
175
- win.wrefresh # FFI 2011-09-19 otherwise not showing
179
+ while ((ch = win.getchar()) != 999)
180
+ return default.ord if default && (ch == 13 || ch == KEY_ENTER)
181
+ return nil if ch == ?\C-c.getbyte(0) || ch == ?\C-g.getbyte(0)
182
+ if ch == KEY_F1
183
+ help_text = config[:help_text] || "No help provided. C-c/C-g aborts."
184
+ print_status_message help_text, :wait => 7
185
+ win.wrefresh # nevr had to do this with ncurses, but have to with ffi-ncurses ??
176
186
  next
177
- when KEY_RIGHT
178
- if curpos < str.length
179
- curpos += 1 #if curpos < str.length
180
- len += 1
181
- win.wmove r, c+len # since getchar is not going back on del and bs
182
- win.wrefresh # FFI 2011-09-19 otherwise not showing
183
- end
184
- next
185
- when ?\C-a.getbyte(0)
186
- #olen = str.length
187
- #clear_this win, r, c, color, len+maxlen+1
188
- #clear_line len+maxlen+1, @prompt_length
189
- len -= curpos
190
- curpos = 0
191
- win.move r, c+len # since getchar is not going back on del and bs
192
- win.wrefresh # FFI 2011-09-19 otherwise not showing
193
- when ?\C-e.getbyte(0)
194
- olen = str.length
195
- len += (olen - curpos)
196
- curpos = olen
197
- #clear_line len+maxlen+1, @prompt_length
198
- win.move r, c+len # since getchar is not going back on del and bs
199
- win.wrefresh # FFI 2011-09-19 otherwise not showing
200
- when ?\M-i.getbyte(0)
201
- ins_mode = !ins_mode
202
- next
203
- when KEY_TAB # TAB
204
- # this is where we can use the horizlist !!! TODO when he tabs !!!
205
- if config
206
- if prevchar == 9
207
- if !entries.nil? and !entries.empty?
208
- str = entries.delete_at(0)
209
- end
210
- else
211
- tabc = config[:tab_completion] unless tabc
212
- next unless tabc
213
- entries = tabc.call(str)
214
- $log.debug " tab got #{entries} "
215
- str = entries.delete_at(0) unless entries.nil? or entries.empty?
216
- end
217
- end
218
- else
219
- #if validints.include?ch
220
- #print_status("Found in validints")
221
- #return ch, nil
222
- #else
223
- if ch < 0 || ch > 255
224
- Ncurses.beep
225
- next
226
- end
227
- # if control char, beep
228
- if ch.chr =~ /[[:cntrl:]]/
229
- Ncurses.beep
230
- next
231
- end
232
- # we need to trap KEY_LEFT and RIGHT and what of UP for history ?
233
- #end
234
- #str << ch.chr
235
- if ins_mode
236
- str[curpos] = ch.chr
187
+ end
188
+ if config[:regexp]
189
+ reg = config[:regexp]
190
+ if ch > 0 && ch < 256
191
+ chs = ch.chr
192
+ return ch if chs =~ reg
193
+ alert "Wrong character. #{reg} "
237
194
  else
238
- str.insert(curpos, ch.chr)
195
+ alert "Wrong character. #{reg} "
239
196
  end
240
- len += 1
241
- curpos += 1
242
- break if str.length > maxlen
197
+ else
198
+ return ch
243
199
  end
244
- print_this(win, prompt+str, color, r, c)
245
- win.wmove r, c+len # more for arrow keys, curpos may not be end
200
+ #form.handle_key ch
246
201
  win.wrefresh
247
- prevchar = ch
248
202
  end
249
- str = default if str == ""
203
+ rescue => err
204
+ Ncurses.beep
205
+ $log.error "EXC in rbgetsr #{err} "
206
+ $log.error(err.backtrace.join("\n"))
250
207
  ensure
251
- Ncurses.noecho();
252
- win.destroy # now that we created a window 2011-11-26
253
- #x restore_application_key_labels # must be done after using print_key_labels
208
+ win.destroy if win
254
209
  end
255
- return 0, str
210
+ return nil
256
211
  end
257
212
 
258
213
  # This is just experimental, trying out tab_completion
@@ -260,10 +215,11 @@ end
260
215
  # @param [String] label to print before field
261
216
  # @param [Fixnum] max length of field
262
217
  # @return [String] filename or blank if user cancelled
263
- def get_file prompt, maxlen=70 #:nodoc:
218
+ def get_file prompt, config={} #:nodoc:
219
+ maxlen = 70
264
220
  tabc = Proc.new {|str| Dir.glob(str +"*") }
265
- config={}; config[:tab_completion] = tabc
266
- config[:default] = "test"
221
+ config[:tab_completion] ||= tabc
222
+ #config[:default] = "test"
267
223
  ret, str = rbgetstr(nil,0,0, prompt, maxlen, config)
268
224
  #$log.debug " get_file returned #{ret} , #{str} "
269
225
  return "" if ret != 0
@@ -272,163 +228,19 @@ end
272
228
  def clear_this win, r, c, color, len
273
229
  print_this(win, "%-*s" % [len," "], color, r, c)
274
230
  end
275
- def print_help(win, r, c, color, helptext)
276
- print_this(win, "%-*s" % [helptext.length+2," "], color, r, c)
277
- print_this(win, "%s" % helptext, color, r, c)
278
- sleep(5)
279
- end
280
- # @table_width is a constant in caller based on which we decide where to show
281
- # key_labels and error messages.
282
- # WHEN WE CREATE A PANEL BWLOW we can do away wit that. FIXME XXX
283
- # return true for y, false for n
284
- # e.g.
285
- # <code>
286
- # ret = @main.askyesno(nil, "Are you sure you wish to proceed?")
287
- # </code>
288
- # 2008-10-09 18:27 added call to print_footer_help
289
- def askyesno(win, askstr, default = "N", helptext="Helptext for this question")
290
- win ||= @footer_win
291
- askstr = "#{askstr} [#{default}]: "
292
- len = askstr.length
293
-
294
- clear_error # 2008-10-13 20:26
295
- print_this(win, askstr, 4, LINEONE, 0)
296
- labels=["?~Help "," ~ ", "N~No ", "Y~Yes "]
297
- print_key_labels( 0, 0, labels)
298
- win.refresh
299
- #Ncurses.echo();
300
- yn=''
301
- #win.mvwgetnstr(Ncurses.LINES-3,askstr.length,yn,maxlen)
302
- while true
303
- ch=win.mvwgetch(LINEONE,askstr.length)
304
- if ch < 0 || ch > 255
305
- next
306
- end
307
- yn = ch.chr
308
- yn = default if yn == '' or ch == 10 # KEY_ENTER
309
- yn.downcase!
310
- break if yn =~/[yn]/
311
- if yn == '?'
312
- print_footer_help(helptext)
313
- print_key_labels( 0, 0, labels)
314
- next
315
- end
316
- Ncurses.beep
317
- end
318
- #Ncurses.noecho();
319
- clear_error # 2008-11-06 19:27
320
- restore_application_key_labels # must be done after using print_key_labels
321
- win.refresh
322
- return yn == 'y'
323
- end
324
-
325
- # return y or n or c
326
-
327
- def askyesnocancel(win, askstr, default = "N")
328
- win ||= @footer_win
329
- askstr = "#{askstr} [#{default}]: "
330
- len = askstr.length
331
-
332
- clear_error # 2008-10-13 20:26
333
- print_this(win, askstr, 4, LINEONE, 0)
334
- labels=["N~No ", "Y~Yes ","C~Cancel"," ~ "]
335
- print_key_labels( 0, 0, labels)
336
- win.refresh
337
- yn=''
338
- #win.mvwgetnstr(LINEONE,askstr.length,yn,maxlen)
339
- while true
340
- ch=win.mvwgetch(LINEONE,askstr.length)
341
- yn = ch.chr
342
- yn = default if yn == '' or ch == 10 # KEY_ENTER
343
- yn.downcase!
344
- break if yn =~/[ync]/
345
- Ncurses.beep
346
- end
347
- restore_application_key_labels # must be done after using print_key_labels
348
- return yn
349
- end
350
231
 
351
- # return single digit from given choices
352
- # e.g.
353
- # <code>
354
- # labels=["N~No ", "Y~Yes ","C~Cancel"," ~ ","S~SurpiseMe","G~GoAway! "]
355
- # ret = @main.askchoice(nil, "Are you sure you wish to proceed?","N",labels,"NYCSG")
356
- # @main.clear_error
357
- # </code>
358
232
 
359
- def askchoice(win, askstr, default, labels, validchars, config={})
360
- win ||= @footer_win
361
- askstr = "#{askstr} [#{default}]: "
362
- len = askstr.length
363
- helptext = config.fetch("helptext", "No helptext provided for this action")
364
233
 
365
- clear_error # 2008-10-13 20:26
366
- print_this(win, askstr, 4, LINEONE, 0)
367
- #labels=["N~No ", "Y~Yes ","C~Cancel"," ~ "]
368
- print_key_labels( 0, 0, labels)
369
- yn=''
370
- validchars.downcase!
371
- #win.mvwgetnstr(LINEONE-3,askstr.length,yn,maxlen)
372
- while true
373
- ch=win.mvwgetch(LINEONE,askstr.length)
374
- yn = ch.chr
375
- # 2008-10-31 18:08
376
- if ch == ?\C-g or yn == '?'
377
- print_footer_help(helptext)
378
- print_key_labels( 0, 0, labels)
379
- next
380
- end
381
- yn = default if yn == '' or ch == 10 # KEY_ENTER
382
- yn.downcase!
383
- break if validchars.include?yn
384
- Ncurses.beep
385
- end
386
- restore_application_key_labels # must be done after using print_key_labels
387
- return yn
388
- end
389
- def get_string(win, askstr, maxlen=20, default="", labels=nil )
390
- win ||= @footer_win
391
- askstr = "#{askstr} [#{default}]: "
392
- len = askstr.length
393
-
394
- clear_error # 2008-11-06 19:25
395
- print_this(win, askstr, 4, LINEONE, 0)
396
- #labels=["N~No ", "Y~Yes ","C~Cancel"," ~ "]
397
- mylabels = ["^G~Help ", "^C~Cancel"]
398
- mylabels = (mylabels + labels) if !labels.nil?
399
-
400
- print_key_labels( 0, 0, mylabels)
401
- Ncurses.echo();
402
- yn=''
403
- begin
404
- Signal.trap("INT"){ return nil }
405
- win.mvwgetnstr(LINEONE,askstr.length,yn,maxlen)
406
- rescue
407
- yn=''
408
- ensure
409
- Ncurses.noecho();
410
- clear_error # 2008-11-02 11:51
411
- restore_application_key_labels # must be done after using print_key_labels
412
- end
413
- yn = default if yn == "" # 2008-10-31 18:59
414
- return yn
415
- end
416
-
417
-
418
- ##
419
- # prints given text to window, in color at x and y coordinates
420
- # @param [Window] window to write to
421
- # @param [String] text to print
422
- # @param [int] color pair such as $datacolor or $promptcolor
423
- # @param [int] x row
424
- # @param [int] y col
425
- # @see Window#printstring
426
- # Consider using Window#printstring
234
+ ##
235
+ # prints given text to window, in color at x and y coordinates
236
+ # @param [Window] window to write to
237
+ # @param [String] text to print
238
+ # @param [int] color pair such as $datacolor or $promptcolor
239
+ # @param [int] x row
240
+ # @param [int] y col
241
+ # @see Window#printstring
427
242
  def print_this(win, text, color, x, y)
428
- if !win
429
- raise "win nil in print_this"
430
- end
431
- #$log.debug " printthis #{win} , #{text} , #{x} , #{y} "
243
+ raise "win nil in print_this" unless win
432
244
  color=Ncurses.COLOR_PAIR(color);
433
245
  win.attron(color);
434
246
  #win.mvprintw(x, y, "%-40s" % text);
@@ -436,242 +248,7 @@ end
436
248
  win.attroff(color);
437
249
  win.refresh
438
250
  end
439
- # prints error in footer_win only
440
- def print_error(text)
441
- clear_error
442
- print_in_middle(@footer_win, LINEONE, 10, 80, text, Ncurses.COLOR_PAIR(ERROR_COLOR_PAIR))
443
- end
444
- # prints status in footer_win only
445
- def print_status(text)
446
- text = text[text.length-80..-1] if text.length > 80
447
- print_error(text)
448
- end
449
- # clear previous error, call inside getch loop after each ch.
450
- def clear_error
451
- print_this(@footer_win, "%-*s" % [Ncurses.COLS," "], 5, LINEONE, 0)
452
- end
453
- # This is only for the menu program, in which we print current action/menu string in the
454
- # key labels below.
455
- # Its a dirty hack edpending on:
456
- # * String CurRow present in key labels
457
- # * field_init_proc called this method to set it.
458
- def print_action(text)
459
- print_this(@footer_win, " %-10s" % ("["+text+"]"), FOOTER_COLOR_PAIR, @action_posy, @action_posx)
460
- end
461
-
462
- # the old historical program which prints a string in middle of whereever
463
- # thanks to this i was using stdscr which must never be used
464
-
465
- def print_in_middle(win, starty, startx, width, string, color)
466
- if(win == nil)
467
- raise "window is nil"
468
- end
469
- x = Array.new
470
- y = Array.new
471
- Ncurses.getyx(win, y, x);
472
- if(startx != 0)
473
- x[0] = startx;
474
- end
475
- if(starty != 0)
476
- y[0] = starty;
477
- end
478
- if(width == 0)
479
- width = 80;
480
- end
481
- length = string.length;
482
- temp = (width - length)/ 2;
483
- x[0] = startx + temp.floor;
484
- win.attron(color);
485
- win.mvprintw(y[0], x[0], "%s", string);
486
- win.attroff(color);
487
- win.refresh();
488
- end
489
- # splits that bad hack array into even and odd arrays
490
- # and prints on last 2 lines
491
-
492
- def print_key_labels(posy, posx, arr)
493
- ## paint so-called key bindings from key_labels
494
- posx = 0
495
- even = []
496
- odd = []
497
- arr.each_index { |i|
498
- if i % 2 == 0
499
- even << arr[i]
500
- else
501
- odd << arr[i]
502
- end
503
- }
504
- posy = LINEONE+1
505
- print_key_labels_row(posy, posx, even)
506
- posy = LINEONE+2
507
- print_key_labels_row(posy, posx, odd)
508
- # 2008-09-29 21:58
509
- @footer_win.wrefresh # needed else secod row not shown after askchoice XXX
510
- end
511
-
512
- def print_key_labels_row(posy, posx, arr)
513
- #clear first
514
- my_form_win = @footer_win
515
- # first clear the line
516
- print_this(my_form_win, "%-*s" % [Ncurses.COLS," "], FOOTER_COLOR_PAIR, posy, 0)
517
- padding = 8
518
- padding = 4 if arr.length > 5
519
- padding = 0 if arr.length > 7
520
- arr.each_index { |i|
521
- kl = arr[i].split('~')
522
- if kl[0].strip !="" # don't print that white blank space for fillers
523
- color_pair=2
524
- my_form_win.attron(Ncurses.COLOR_PAIR(color_pair))
525
- my_form_win.mvprintw(posy, posx, "%s" % kl[0] );
526
- my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair))
527
- end
528
- color_pair=FOOTER_COLOR_PAIR
529
- posx = posx + kl[0].length
530
- my_form_win.attron(Ncurses.COLOR_PAIR(color_pair))
531
- lab = sprintf(" %s %*s" , kl[1], padding, " ");
532
- # hack
533
- if kl[1].strip == "CurRow"
534
- @action_posx = posx
535
- @action_posy = posy
536
- end
537
- my_form_win.mvprintw(posy, posx, lab)
538
- my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair))
539
- posx = posx + lab.length
540
- }
541
- end
542
-
543
- # since it must always be @header_win, we should remove the first param
544
- # why should user have any direct access to those 2 windows.
545
- def old_print_header(win, htext, posy = 0, posx = 0)
546
- win.attron(Ncurses.COLOR_PAIR(6))
547
- win.mvprintw(posy, posx, "%-*s" % [Ncurses.COLS, htext] );
548
- win.attroff(Ncurses.COLOR_PAIR(6))
549
- end
550
- def print_header(htext, posy = 0, posx = 0)
551
- win = @header_win
552
- win.attron(Ncurses.COLOR_PAIR(6))
553
- win.mvprintw(posy, posx, "%-*s" % [Ncurses.COLS, htext] );
554
- win.attroff(Ncurses.COLOR_PAIR(6))
555
- end
556
-
557
- # since it must always be @header_win, we should remove the first param
558
- # why should user have any direct access to those 2 windows.
559
- def old_print_top_right(win, htext)
560
- hlen = htext.length
561
- win.attron(Ncurses.COLOR_PAIR(6))
562
- win.mvprintw(0, Ncurses.COLS-hlen, htext );
563
- win.attroff(Ncurses.COLOR_PAIR(6))
564
- #win.refresh
565
- end
566
- def print_top_right(htext)
567
- hlen = htext.length
568
- win = @header_win
569
- win.attron(Ncurses.COLOR_PAIR(6))
570
- win.mvprintw(0, Ncurses.COLS-hlen, htext );
571
- win.attroff(Ncurses.COLOR_PAIR(6))
572
- #win.refresh
573
- end
574
- # prints labels defined by user in the DSL.
575
- #
576
- # Array of labels with:
577
- #
578
- # * position = [y,x] i.e, row, column
579
- # * text = "label text"
580
- # * color_pair = 6 (optional, default 6)
581
-
582
- def print_screen_labels(my_form_win, labelarr)
583
- table_width = @table_width || Ncurses.LINES-1
584
- return if labelarr.nil?
585
- labelarr.each{ |lhash|
586
- posy, posx = lhash["position"]
587
- posy = table_width + posy if posy < 0
588
- posx = Ncurses.COLS + posy if posx < 0
589
-
590
- text = lhash["text"]
591
- color_pair = lhash["color_pair"] || 6
592
- my_form_win.attron(Ncurses.COLOR_PAIR(color_pair))
593
- my_form_win.mvprintw(posy, posx, "%-s" % text );
594
- my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair))
595
- }
596
- end
597
-
598
- @deprecated
599
- def print_headers(form_hash)
600
- header = form_hash["header"]
601
- header_top_left = form_hash["header_top_left"] || ""
602
- header_top_center = form_hash["header_top_center"] || ""
603
- header_top_right = form_hash["header_top_right"] || ""
604
- posy = 0
605
- posx = 0
606
- htext = " <APP NAME> <VERSION> MAIN MENU"
607
251
 
608
- posy, posx, htext = header if !header.nil?
609
- print_header(htext + " %15s " % header_top_left + " %20s" % header_top_center , posy, posx)
610
- print_top_right(header_top_right)
611
- @header_win.wrefresh();
612
- end
613
-
614
-
615
- # 2008-10-09 18:27 askyesno and ask_string can be passed some text
616
- # to be popped up when a user enters ?
617
- @deprecated
618
- def print_footer_help(helptext)
619
- print_this(@footer_win, "%-*s" % [Ncurses.COLS," "], 6, LINEONE+1, 0)
620
- print_this(@footer_win, "%-*s" % [Ncurses.COLS," "], 6, LINEONE+2, 0)
621
- print_this(@footer_win, "%s" % helptext, 6, LINEONE+1, 0)
622
- sleep(5)
623
- end
624
- def print_help_page(filename = "TODO")
625
- #require 'panelreader' obsolete used FORN and fiELD
626
- #tp = PanelReader.new()
627
- #tp.view_file(filename)
628
-
629
- end
630
- #def newaskyesno(win, askstr, default = "N", helptext="Helptext for this question")
631
- ##
632
- # user may pass in actions for each key along with other config values in config hash.
633
- # config can contain default, helptext, labels and 'y', 'n'
634
- @deprecated
635
- def newaskyesno(win, askstr, config = {})
636
- win ||= @footer_win
637
- default = config.fetch("default", "N")
638
- helptext = config.fetch("helptext", "This is helptext for this action")
639
- askstr = "#{askstr} [#{default}]: "
640
- len = askstr.length
641
-
642
- clear_error # 2008-10-13 20:26
643
- print_this(win, askstr, 4, LINEONE, 0)
644
- labels=config.fetch("labels", ["?~Help "," ~ ", "N~No ", "Y~Yes "])
645
- print_key_labels( 0, 0, labels)
646
- win.refresh
647
- yn=''
648
- #win.mvwgetnstr(Ncurses.LINES-3,askstr.length,yn,maxlen)
649
- while true
650
- ch=win.mvwgetch(LINEONE,askstr.length)
651
- if ch < 0 || ch > 255
652
- next
653
- end
654
- yn = ch.chr
655
- yn = default if yn == '' or ch == 10 # KEY_ENTER
656
- yn.downcase!
657
- break if yn =~/[yn]/
658
- if yn == '?'
659
- print_footer_help(helptext)
660
- print_key_labels( 0, 0, labels)
661
- next
662
- end
663
- Ncurses.beep
664
- end # while
665
-
666
- begin
667
- config[yn].call if config.include? yn
668
- ensure
669
- restore_application_key_labels # must be done after using print_key_labels
670
- win.refresh
671
- end
672
-
673
- return yn == 'y'
674
- end
675
252
 
676
253
  #
677
254
  # warn user: currently flashes and places error in log file
@@ -885,6 +462,7 @@ end
885
462
  # @see display_new - it presents in a much better manner
886
463
  # and is not restricted to one row. Avoid this.
887
464
  def display win, r, c, color
465
+ raise "Please use display_new, i've replace this with that"
888
466
  # FIXME use a oneline window, user should not have to give all this crap.
889
467
  # What about panning if we can;t fit, should we use horiz list to show ?
890
468
  menu = @options