rbcurse 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/CHANGELOG +33 -0
  2. data/README.markdown +7 -1
  3. data/TODO2.txt +21 -15
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +2 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +0 -1
  8. data/examples/appdirtree.rb +4 -2
  9. data/examples/appemail.rb +7 -3
  10. data/examples/appemaillb.rb +1 -1
  11. data/examples/appgcompose.rb +2 -2
  12. data/examples/appgmail.rb +1 -1
  13. data/examples/appmethods.rb +20 -2
  14. data/examples/atree.rb +9 -1
  15. data/examples/dbdemo.rb +460 -0
  16. data/examples/dirtree.rb +1 -1
  17. data/examples/menu1.rb +37 -5
  18. data/examples/multispl.rb +1 -1
  19. data/examples/rfe.rb +9 -2
  20. data/examples/splitp.rb +1 -1
  21. data/examples/sqlc.rb +6 -10
  22. data/examples/sqlm.rb +2 -20
  23. data/examples/sqlt.rb +408 -0
  24. data/examples/term2.rb +1 -1
  25. data/examples/test2.rb +169 -97
  26. data/examples/testapp.rb +1 -1
  27. data/examples/testapp2.rb +1 -1
  28. data/examples/testkeypress.rb +4 -2
  29. data/examples/testtable.rb +6 -0
  30. data/examples/testtpane.rb +35 -23
  31. data/examples/testvimsplit.rb +3 -2
  32. data/lib/rbcurse.rb +1 -1
  33. data/lib/rbcurse/action.rb +8 -0
  34. data/lib/rbcurse/app.rb +39 -23
  35. data/lib/rbcurse/extras/bottomline.rb +101 -13
  36. data/lib/rbcurse/extras/directorylist.rb +14 -5
  37. data/lib/rbcurse/extras/divider.rb +1 -1
  38. data/lib/rbcurse/extras/listselectable.rb +42 -8
  39. data/lib/rbcurse/extras/masterdetail.rb +2 -2
  40. data/lib/rbcurse/extras/scrollbar.rb +11 -2
  41. data/lib/rbcurse/extras/statusline.rb +56 -0
  42. data/lib/rbcurse/extras/stdscrwindow.rb +11 -0
  43. data/lib/rbcurse/extras/tabular.rb +2 -1
  44. data/lib/rbcurse/extras/tabularwidget.rb +60 -17
  45. data/lib/rbcurse/extras/viewer.rb +16 -4
  46. data/lib/rbcurse/keylabelprinter.rb +34 -4
  47. data/lib/rbcurse/listeditable.rb +5 -1
  48. data/lib/rbcurse/listkeys.rb +1 -1
  49. data/lib/rbcurse/listscrollable.rb +15 -8
  50. data/lib/rbcurse/rbasiclistbox.rb +44 -23
  51. data/lib/rbcurse/rcommandwindow.rb +8 -14
  52. data/lib/rbcurse/rdialogs.rb +187 -2
  53. data/lib/rbcurse/rlistbox.rb +38 -19
  54. data/lib/rbcurse/rmenu.rb +313 -93
  55. data/lib/rbcurse/rmessagebox.rb +3 -2
  56. data/lib/rbcurse/rmulticontainer.rb +5 -3
  57. data/lib/rbcurse/rmultisplit.rb +2 -11
  58. data/lib/rbcurse/rmultitextview.rb +4 -5
  59. data/lib/rbcurse/rtabbedpane.rb +223 -69
  60. data/lib/rbcurse/rtable.rb +6 -10
  61. data/lib/rbcurse/rtextarea.rb +57 -36
  62. data/lib/rbcurse/rtextview.rb +12 -15
  63. data/lib/rbcurse/rtree.rb +79 -22
  64. data/lib/rbcurse/rvimsplit.rb +16 -25
  65. data/lib/rbcurse/rwidget.rb +376 -523
  66. data/lib/rbcurse/tree/treecellrenderer.rb +24 -11
  67. data/lib/rbcurse/tree/treemodel.rb +1 -1
  68. data/lib/ver/window.rb +130 -66
  69. metadata +5 -3
  70. data/examples/term.rb +0 -48
data/examples/term2.rb CHANGED
@@ -3,7 +3,7 @@ require 'rbcurse/extras/tabular'
3
3
  require 'rbcurse/extras/scrollbar'
4
4
 
5
5
  App.new do
6
- header = app_header "rbcurse 1.2.0", :text_center => "Tabular Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
6
+ header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Tabular Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
7
7
  message "Press F10 to escape from here"
8
8
 
9
9
  stack :margin_top => 2, :margin => 5, :width => 30 do
data/examples/test2.rb CHANGED
@@ -1,10 +1,15 @@
1
- #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
- # this program tests out various widgets.
3
- require 'rubygems'
4
- #require 'ncurses' # FFI
1
+ # This program tests out various widgets.
2
+ # This is the old style of creating an application in which the user
3
+ # has to start and stop ncurses. No shortcuts for widget constructors are available.
4
+ #
5
+ # The newer easier way is to use 'App' which manages the environment, and provides shortcuts
6
+ # for all widgets. See app*.rb, alpmenu.rb, dbdemo.rb etc for samples.
7
+ #
8
+ # In case, you are running this in a directory that does not allow writing, set LOGDIR to
9
+ # your home directory, or temp directory so a log file can be generated.
10
+ #
5
11
  require 'logger'
6
12
  require 'rbcurse'
7
- require 'rbcurse/rwidget'
8
13
  require 'rbcurse/rtextarea'
9
14
  require 'rbcurse/rtextview'
10
15
  require 'rbcurse/rmenu'
@@ -13,36 +18,18 @@ require 'rbcurse/listcellrenderer'
13
18
  require 'rbcurse/checkboxcellrenderer'
14
19
  require 'rbcurse/comboboxcellrenderer'
15
20
  require 'rbcurse/celleditor'
16
- require './qdfilechooser'
17
21
  require 'rbcurse/rlistbox'
18
22
  require 'rbcurse/rmessagebox'
19
23
  require 'rbcurse/rtree'
20
24
  require './appmethods.rb'
21
- def shell_output
22
- cmd = get_string("Enter shell command:", 50)
23
- if cmd && !cmd.empty?
24
- run_command cmd
25
- end
26
- end
27
- def run_command cmd
28
- # http://whynotwiki.com/Ruby_/_Process_management#What_happens_to_standard_error_.28stderr.29.3F
29
- require 'rbcurse/extras/viewer'
30
- begin
31
- res = `#{cmd} 2>&1`
32
- rescue => ex
33
- res = ex.to_s
34
- res << ex.backtrace.join("\n")
35
- end
36
- res.gsub!("\t"," ")
37
- RubyCurses::Viewer.view(res.split("\n"), :close_key => KEY_RETURN, :title => "<Enter> to close, M-l M-h to scroll")
38
- end
25
+ require 'rbcurse/extras/scrollbar'
39
26
  def help_text
40
27
  <<-eos
41
28
  TEST2 HELP
42
29
 
43
30
  This is some help text for test2.
44
31
 
45
- Alt-C/F1 - Exit application (F1 will become help in 1.3.1)
32
+ Alt-C/F10 - Exit application
46
33
  Alt-! - Drop to shell
47
34
  C-x c - Drop to shell
48
35
  C-x l - list of files
@@ -60,15 +47,20 @@ def help_text
60
47
  eos
61
48
  end
62
49
  if $0 == __FILE__
50
+
63
51
  include RubyCurses
52
+ include RubyCurses::Utils
64
53
 
65
54
  begin
66
55
  # Initialize curses
67
56
  VER::start_ncurses # this is initializing colors via ColorMap.setup
68
- #$log = Logger.new(ENV['LOGDIR'] || "" + "rbc13.log")
69
- $log = Logger.new((File.join(ENV['LOGDIR'] || "./" ,"rbc13.log")))
57
+ path = File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")
58
+ file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
59
+ $log = Logger.new(path)
70
60
  $log.level = Logger::DEBUG
71
61
 
62
+ @lookfeel = :classic # :dialog # or :classic
63
+
72
64
  @window = VER::Window.root_window
73
65
  # Initialize few color pairs
74
66
  # Create the window to be associated with the form
@@ -78,12 +70,13 @@ if $0 == __FILE__
78
70
  colors = Ncurses.COLORS
79
71
  $log.debug "START #{colors} colors test2.rb --------- #{@window} "
80
72
  @form = Form.new @window
81
- @form.window.printstring 0, 30, "Demo of some Ruby Curses Widgets - rbcurse", $normalcolor, 'reverse'
73
+ title = (" "*30) + "Demo of some Ruby Curses Widgets - rbcurse " + Rbcurse::VERSION
74
+ Label.new @form, {'text' => title, "row" => 0, "col" => 0, :color => 'green', :bgcolor => 'black'}
82
75
  r = 1; fc = 12;
83
76
  mnemonics = %w[ n l r p]
84
77
  %w[ name line regex password].each_with_index do |w,i|
85
78
  field = Field.new @form do
86
- name w
79
+ name w
87
80
  row r
88
81
  col fc
89
82
  display_length 30
@@ -95,7 +88,9 @@ if $0 == __FILE__
95
88
 
96
89
  $message = Variable.new
97
90
  $message.value = "Message Comes Here"
98
- message_label = RubyCurses::Label.new @form, {'text_variable' => $message, "name"=>"message_label","row" => 27, "col" => 1, "display_length" => 60, "height" => 2, 'color' => 'cyan'}
91
+ message_label = RubyCurses::Label.new @form, {'text_variable' => $message,
92
+ "name"=>"message_label","row" => Ncurses.LINES-1, "col" => 1, "display_length" => 60,
93
+ "height" => 2, 'color' => 'cyan'}
99
94
 
100
95
  $results = Variable.new
101
96
  $results.value = "A variable"
@@ -120,6 +115,7 @@ if $0 == __FILE__
120
115
  title_attrib 'reverse'
121
116
  cell_editing_allowed true
122
117
  end
118
+ Scrollbar.new @form, :parent => listb # 2011-10-1 added
123
119
  #listb.insert 55, "hello ruby", "so long python", "farewell java", "RIP .Net"
124
120
  #$listdata.value.insert 55, "hello ruby", "so long python", "farewell java", "RIP .Net"
125
121
  listb.list_data_model.insert 55, "hello ruby", "so long python", "farewell java", "RIP .Net", "hi lisp", "hi clojure"
@@ -131,20 +127,20 @@ if $0 == __FILE__
131
127
  width 50
132
128
  height 14
133
129
  title "Editable box"
134
- title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
130
+ #title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
135
131
  print_footer true
136
132
  bind(:CHANGE){|e| $message.value = e.to_s+" CP:"+e.source.curpos.to_s }
137
133
  end
138
134
  texta << "I expect to pass through this world but once." << "Any good therefore that I can do, or any kindness or abilities that I can show to any fellow creature, let me do it now."
139
135
  texta << "Let me not defer it or neglect it, for I shall not pass this way again."
140
136
  texta << " "
141
- texta << " F1 to exit. or click cancel button"
137
+ texta << " F10 to exit. or click cancel button"
142
138
  texta << " Or alt-c"
143
139
 
144
140
  col3 = 92
145
141
  treemodel = nil
146
- atree = Tree.new @form, :title => "Tree", :row =>1, :col=>col3, :height => 14, :width => 15 do
147
- treemodel = root "ruby" do
142
+ atree = Tree.new @form, :title => "Tree", :row =>1, :col=>col3, :height => 14, :width => 15 do
143
+ treemodel = root "ruby language" do
148
144
  branch "mri" do
149
145
  leaf "1.9.1"
150
146
  leaf "1.9.2"
@@ -152,6 +148,8 @@ if $0 == __FILE__
152
148
  end
153
149
  branch "jruby" do
154
150
  leaf "1.5"
151
+ leaf "a really long leaf"
152
+
155
153
  end
156
154
  branch "ree" do
157
155
  leaf "1.8"
@@ -172,7 +170,7 @@ if $0 == __FILE__
172
170
  width w1
173
171
  height 11
174
172
  title "README.mark"
175
- title_attrib 'bold'
173
+ #title_attrib 'bold'
176
174
  print_footer true
177
175
  footer_attrib 'bold'
178
176
  end
@@ -217,9 +215,9 @@ if $0 == __FILE__
217
215
  list_config 'color' => 'yellow', 'bgcolor'=>'red', 'height' => 4
218
216
  end
219
217
 
220
- list = ListDataModel.new( %w[spotty tiger panther jaguar leopard ocelot lion])
221
- list.bind(:LIST_DATA_EVENT) { |lde| $message.value = lde.to_s; $log.debug " STA: #{$message.value} #{lde}" }
222
- list.bind(:ENTER_ROW) { |obj| $message.value = "ENTER_ROW :#{obj.current_index} : #{obj.selected_item} "; $log.debug " ENTER_ROW: #{$message.value} , #{obj}" }
218
+ list = ListDataModel.new( %w[white yellow cyan magenta red blue black])
219
+ list.bind(:LIST_DATA_EVENT) { |lde| $message.value = lde.to_s; $log.debug " STA: #{$message.value} #{lde}"; }
220
+ list.bind(:ENTER_ROW) { |obj| $message.value = "ENTER_ROW :#{obj.current_index} : #{obj.selected_item} "; $log.debug " ENTER_ROW: #{$message.value} , #{obj}"; @form.widgets.each { |e| next unless e.is_a? Widget; e.color = obj.selected_item }; @mb.color = obj.selected_item }
223
221
 
224
222
  row += 1
225
223
  combo1 = ComboBox.new @form do
@@ -271,39 +269,45 @@ if $0 == __FILE__
271
269
  # a special case required since another form (combo popup also modifies)
272
270
  $message.update_command() { message_label.repaint }
273
271
 
274
- @form.by_name["line"].display_length = 3
275
- @form.by_name["line"].maxlen = 3
276
- @form.by_name["line"].set_buffer "24"
277
- @form.by_name["name"].set_buffer "Not focusable"
278
- @form.by_name["name"].set_focusable(false)
279
- @form.by_name["line"].chars_allowed = /\d/
280
- #@form.by_name["regex"].type(:ALPHA)
281
- @form.by_name["regex"].valid_regex(/^[A-Z][a-z]*/)
282
- @form.by_name["regex"].set_buffer "SYNOP"
283
- @form.by_name["regex"].display_length = 10
284
- @form.by_name["regex"].maxlen = 20
285
- #@form.by_name["regex"].bgcolor 'cyan'
286
- @form.by_name["password"].set_buffer ""
287
- @form.by_name["password"].show '*'
288
- @form.by_name["password"].color 'red'
289
- #@form.by_name["password"].bgcolor 'blue'
290
- @form.by_name["password"].values(%w[scotty tiger secret pass qwerty])
291
- @form.by_name["password"].null_allowed true
292
-
293
- # a form level event, whenever any widget is focussed
272
+ f = @form.by_name["line"]
273
+ f.display_length(3).set_buffer(24).valid_range(1..200).
274
+ maxlen(3).
275
+ type(:integer)
276
+
277
+ @form.by_name["name"].set_buffer( "Not focusable").
278
+ set_focusable(false)
279
+
280
+ @form.by_name["regex"].valid_regex(/^[A-Z][a-z]*/).
281
+ set_buffer( "SYNOP").
282
+ display_length(10).
283
+ maxlen = 20
284
+
285
+ @form.by_name["password"].set_buffer("").
286
+ show('*').
287
+ color('red').
288
+ values(%w[scotty tiger secret pass qwerty]).
289
+ null_allowed true
290
+
291
+ # a form level event, whenever any widget is focussed, make the label red
294
292
  @form.bind(:ENTER) { |f| f.label && f.label.bgcolor = 'red' if f.respond_to? :label}
295
293
  @form.bind(:LEAVE) { |f| f.label && f.label.bgcolor = 'black' if f.respond_to? :label}
296
294
 
297
295
  row += 1
298
- colorlabel = Label.new @form, {'text' => "Select a color:", "row" => row, "col" => col, "color"=>"cyan", "mnemonic" => 'S'}
296
+ colorlabel = Label.new @form, {'text' => "Select a color:", "row" => row, "col" => col,
297
+ "color"=>"cyan", "mnemonic" => 'S'}
299
298
  $radio = Variable.new
300
299
  $radio.update_command(colorlabel) {|tv, label| label.color tv.value; }
301
- $radio.update_command() {|tv| message_label.color tv.value; align.bgcolor tv.value; combo1.bgcolor tv.value}
300
+ $radio.update_command() {|tv| message_label.color tv.value; align.bgcolor tv.value;
301
+ combo1.bgcolor tv.value}
302
+ $radio.update_command() {|tv| @form.widgets.each { |e| next unless e.is_a? Widget;
303
+ e.bgcolor tv.value }; @mb.bgcolor = tv.value }
302
304
 
303
305
  # whenever updated set colorlabel and messagelabel to bold
304
- $results.update_command(colorlabel,checkbutton) {|tv, label, cb| attrs = cb.value ? 'bold' : 'normal'; label.attr(attrs); message_label.attr(attrs)}
306
+ $results.update_command(colorlabel,checkbutton) {|tv, label, cb|
307
+ attrs = cb.value ? 'bold' : 'normal'; label.attr(attrs); message_label.attr(attrs)}
305
308
 
306
309
  align.bind(:ENTER_ROW) {|fld| message_label.justify fld.getvalue}
310
+
307
311
  align.bind(:ENTER_ROW) {|fld|
308
312
  if fld.getvalue == 'right'
309
313
  checkbutton1.align_right true
@@ -317,7 +321,9 @@ if $0 == __FILE__
317
321
  # whenever updated set colorlabel and messagelabel to reverse
318
322
  #@cb_rev.update_command(colorlabel,checkbutton1) {|tv, label, cb| attrs = cb.value ? 'reverse' : nil; label.attr(attrs); message_label.attr(attrs)}
319
323
  # changing nil to normal since PROP CHAN handler will not fire if nil being set.
320
- @cb_rev.update_command(colorlabel,checkbutton1) {|tv, label, cb| attrs = cb.value ? 'reverse' : 'normal'; label.attr(attrs); message_label.attr(attrs)}
324
+ @cb_rev.update_command(colorlabel,checkbutton1) {|tv, label, cb|
325
+ attrs = cb.value ? 'reverse' : 'normal'; label.attr(attrs); message_label.attr(attrs)}
326
+
321
327
  row += 1
322
328
  dlen = 10
323
329
  radio1 = RadioButton.new @form do
@@ -338,6 +344,7 @@ if $0 == __FILE__
338
344
  row row
339
345
  col col+24
340
346
  end
347
+
341
348
  row += 1
342
349
  radio2 = RadioButton.new @form do
343
350
  variable $radio
@@ -372,10 +379,29 @@ if $0 == __FILE__
372
379
  end
373
380
  }
374
381
 
382
+ # instead of using frozen, I will use a PropertyVeto
383
+ # to disallow changes to color itself
384
+ veto = lambda { |e, name|
385
+ if e.property_name == 'color'
386
+ if e.newvalue != name
387
+ raise PropertyVetoException.new("Cannot change this at all!", e)
388
+ end
389
+ elsif e.property_name == 'bgcolor'
390
+ raise PropertyVetoException.new("Cannot change this!", e)
391
+ end
392
+ }
393
+ [radio1, radio2, radio11, radio22].each { |r|
394
+ r.bind(:PROPERTY_CHANGE) do |e| veto.call(e, r.text) end
395
+ }
396
+
397
+ #
398
+ # define the menu
399
+ #
375
400
  @mb = RubyCurses::MenuBar.new
376
401
  filemenu = RubyCurses::Menu.new "File"
377
402
  filemenu.add(item = RubyCurses::MenuItem.new("Open",'O'))
378
403
  item.command(@form) {|it, form| $message.value = "Open called on menu bar";
404
+ require './qdfilechooser'
379
405
  fchooser = QDFileChooser.new
380
406
  option = fchooser.show_open_dialog
381
407
  $message.value = "File Selection #{option}, #{fchooser.get_selected_file}"
@@ -412,14 +438,12 @@ if $0 == __FILE__
412
438
  str << " bugs as they crop up."
413
439
  testa.goto_start
414
440
  #testa.cursor_bol
415
- testa.handle_key ?\C-a.getbyte(0) # bol XXX should it be getbytes(0) now
441
+ testa.handle_key ?\C-a.getbyte(0)
416
442
  str.each_char {|c| testa.putch(c)}
417
443
  testa.repaint
418
- testa.handle_key KEY_DOWN # down
419
- testa.handle_key KEY_DOWN # down
420
- testa.handle_key KEY_DOWN # down
421
- testa.handle_key ?\C-a.getbyte(0) # bol XXX should it be getbytes(0) now
422
- #testa.cursor_bol
444
+ 3.times { testa.handle_key KEY_DOWN }
445
+ testa.handle_key ?\C-a.getbyte(0)
446
+
423
447
  str.each_char {|c| testa.putch(c)}
424
448
  $message.value = "Wrapping textarea"
425
449
  testa.repaint
@@ -428,7 +452,7 @@ if $0 == __FILE__
428
452
  filemenu.add(item = RubyCurses::MenuItem.new("Wrap",'W'))
429
453
  item.command(@form, texta) do |it, form, testa|
430
454
  #testa.goto_start
431
- testa.handle_key ?\C-a.getbyte(0) # bol XXX should it be getbytes(0) now
455
+ testa.handle_key ?\C-a.getbyte(0)
432
456
  testa.wrap_para
433
457
  testa.repaint
434
458
  throw(:menubarclose)
@@ -445,22 +469,41 @@ if $0 == __FILE__
445
469
  #item.text="Labelcb"
446
470
  # in next line, an explicit repaint is required since label is on another form.
447
471
  item.command(colorlabel){|it, label| att = it.getvalue ? 'reverse' : 'normal'; label.attr(att); label.repaint}
448
- row += 2
449
- ftext = " | F2 Menu | F3 View | F4 Shell | F5 Sh | F9 Help "
450
- @form.window.printstring row, 0, "%-*s" % [Ncurses.COLS, ftext], $datacolor, Ncurses::A_REVERSE
472
+ @status_line = status_line :row => Ncurses.LINES-2
473
+ @status_line.command {
474
+ "%-20s | F1 Help | F2 Menu | F3 View | F4 Shell | F5 Sh | %20s" % [Time.now, $message.value]
475
+ }
476
+ row += 1 #2
451
477
  ok_button = Button.new @form do
452
478
  text "OK"
453
479
  name "OK"
454
480
  row row
455
481
  col col
456
- attr 'reverse'
457
- highlight_background "white"
458
- highlight_foreground "blue"
482
+ #attr 'reverse'
483
+ #highlight_background "white"
484
+ #highlight_foreground "blue"
459
485
  mnemonic 'O'
460
486
  end
461
487
  ok_button.command() { |eve|
462
- alert("Hope you enjoyed this demo", {'title' => "Hello", :bgcolor => :blue, :color => :white})
488
+ #alert("Hope you enjoyed this demo ", {'title' => "Hello", :bgcolor => :blue, :color => :white})
489
+ sw = case @lookfeel
490
+ when :dialog
491
+ progress_dialog :color_pair => $reversecolor, :row_offset => 4, :col_offset => 5
492
+ else
493
+ status_window # at footer last 2 rows
494
+ end
495
+
496
+ sw.print "I am adding some stuff to list", "And testing out StatusWindow"
497
+ sleep 1.0
463
498
  listb.list.insert 0, "hello ruby", "so long python", "farewell java", "RIP .Net"
499
+ sw.printstring 1,1, "And some more now ..."
500
+ sleep 0.5
501
+ listb.list.insert 0, "get milk", "make beds", "clean shark pond","sell summer house"
502
+ sleep 0.5
503
+ sw.print "This was a test of Window", "we are almost done now ..."
504
+ clock = %w[ | / - \ ]
505
+ listb.list.each_with_index { |e, index| sw.print e, clock[index%4]; sleep 0.1 }
506
+ sw.linger #@window
464
507
  }
465
508
 
466
509
  # using ampersand to set mnemonic
@@ -469,26 +512,28 @@ if $0 == __FILE__
469
512
  text "&Cancel"
470
513
  row row
471
514
  col col + 10
472
- attr 'reverse'
473
- highlight_background "white"
474
- highlight_foreground "blue"
515
+ #attr 'reverse'
516
+ #highlight_background "white"
517
+ #highlight_foreground "blue"
475
518
  #surround_chars ['{ ',' }'] ## change the surround chars
476
519
  end
477
520
  cancel_button.command { |aeve|
478
- if confirm("Do your really want to quit?")== :YES
521
+ if @lookfeel == :dialog
522
+ ret = confirm("Do your really want to quit?")
523
+ else
524
+ ret = confirm_window("Do your really want to quit?")
525
+ end
526
+ if ret == :YES
479
527
  throw(:close);
480
528
  else
481
529
  $message.value = "Quit aborted"
482
530
  end
483
531
  }
484
532
  #col += 22
485
- #Label.new @form, {'text' => "| F2 - Menu", "row" => row, "col" => col}
486
- #col += 12
487
- #Label.new @form, {'text' => "| F3 - View", "row" => row, "col" => col}
488
533
  col += 15
489
534
  require 'rbcurse/rprogress'
490
- pbar = Progress.new @form, {:width => 20, :row => 27, :col => Ncurses.COLS-20 , :bgcolor => 'white',
491
- :color => 'red', :name => "pbar"}
535
+ pbar = Progress.new @form, {:width => 20, :row => Ncurses.LINES-1, :col => Ncurses.COLS-20 ,
536
+ :bgcolor => 'white', :color => 'red', :name => "pbar"}
492
537
  #len = 1
493
538
  #pbar.fraction(len/100.0)
494
539
  pbar.visible false
@@ -544,14 +589,14 @@ if $0 == __FILE__
544
589
  item.command { run_command "git diff --name-status" }
545
590
  savemenu2.add(item)
546
591
  savemenu.add(savemenu2)
547
- # 2008-12-20 13:06 no longer hardcoding toggle key of menu_bar.
592
+
548
593
  @mb.toggle_key = FFI::NCurses::KEY_F2
549
594
  @form.set_menu_bar @mb
550
- #@cell = CellRenderer.new "Hello", {"col" => 1, "row"=>29, "justify"=>:right, "display_length" => 30}
595
+
551
596
  # END
552
597
  @form.bind_key(FFI::NCurses::KEY_F3) {
553
598
  require 'rbcurse/extras/viewer'
554
- RubyCurses::Viewer.view("rbc13.log", :close_key => KEY_RETURN, :title => "<Enter> to close")
599
+ RubyCurses::Viewer.view(path || "rbc13.log", :close_key => KEY_RETURN, :title => "<Enter> to close")
555
600
  }
556
601
  @form.bind_key(FFI::NCurses::KEY_F4) { shell_output }
557
602
  @form.bind_key(FFI::NCurses::KEY_F5) { suspend }
@@ -563,24 +608,51 @@ if $0 == __FILE__
563
608
  @form.bind_key([?\C-x,?d]) { run_command "git diff --name-status" }
564
609
  @form.bind_key([?\C-x, ?s]) { run_command "git status" }
565
610
  @form.bind_key([?\C-x,?w]) { run_command "git whatchanged" }
566
- @form.bind_key(FFI::NCurses::KEY_F9) { display_app_help help_text() }
611
+ @form.bind_key(FFI::NCurses::KEY_F1) { display_app_help help_text() }
567
612
  @form.repaint
568
613
  @window.wrefresh
569
614
  Ncurses::Panel.update_panels
570
- while((ch = @window.getchar()) != KEY_F1 )
571
- @form.handle_key(ch)
572
- # print_error_message was taking away cursor, not clearing properly
615
+
616
+ # the main loop
617
+
618
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
619
+ begin
620
+ @form.handle_key(ch)
621
+
622
+ rescue FieldValidationException => fve
623
+ alert fve.to_s
624
+
625
+ f = @form.get_current_field
626
+ # lets restore the value
627
+ if f.respond_to? :restore_original_value
628
+ f.restore_original_value
629
+ @form.repaint
630
+ end
631
+ $error_message.value = ""
632
+ rescue => err
633
+ $log.debug( err) if err
634
+ $log.debug(err.backtrace.join("\n")) if err
635
+ alert "Got an exception in test2: #{err} "
636
+ $error_message.value = ""
637
+ end
638
+
639
+ # this should be avoided, we should not muffle the exception and set a variable
640
+ # However, we have been doing that
573
641
  if $error_message.get_value != ""
574
- alert($error_message, {:bgcolor => :red, :color => :yellow}) if $error_message.get_value != ""
642
+ if @lookfeel == :dialog
643
+ alert($error_message, {:bgcolor => :red, 'color' => 'yellow'}) if $error_message.get_value != ""
644
+ else
645
+ print_error_message $error_message, {:bgcolor => :red, :color => :yellow}
646
+ end
575
647
  $error_message.value = ""
576
- @form.repaint
577
648
  end
649
+
578
650
  @window.wrefresh
579
- end
580
- end
651
+ end # while loop
652
+ end # catch
581
653
  rescue => ex
582
654
  ensure
583
- $log.debug " -==== EXCEPTION ===== -"
655
+ $log.debug " -==== EXCEPTION =====-"
584
656
  $log.debug( ex) if ex
585
657
  $log.debug(ex.backtrace.join("\n")) if ex
586
658
  @window.destroy if !@window.nil?