rbcurse-extras 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/README.md +75 -0
  2. data/VERSION +1 -0
  3. data/examples/data/list.txt +300 -0
  4. data/examples/data/lotr.txt +12 -0
  5. data/examples/data/table.txt +36 -0
  6. data/examples/data/tasks.txt +27 -0
  7. data/examples/data/unix1.txt +21 -0
  8. data/examples/inc/qdfilechooser.rb +70 -0
  9. data/examples/inc/rfe_renderer.rb +121 -0
  10. data/examples/newtabbedwindow.rb +100 -0
  11. data/examples/rfe.rb +1236 -0
  12. data/examples/test2.rb +670 -0
  13. data/examples/testeditlist.rb +78 -0
  14. data/examples/testtable.rb +270 -0
  15. data/examples/testvimsplit.rb +141 -0
  16. data/lib/rbcurse/extras/include/celleditor.rb +112 -0
  17. data/lib/rbcurse/extras/include/checkboxcellrenderer.rb +57 -0
  18. data/lib/rbcurse/extras/include/comboboxcellrenderer.rb +30 -0
  19. data/lib/rbcurse/extras/include/defaultlistselectionmodel.rb +79 -0
  20. data/lib/rbcurse/extras/include/listkeys.rb +37 -0
  21. data/lib/rbcurse/extras/include/listselectable.rb +144 -0
  22. data/lib/rbcurse/extras/include/tableextended.rb +40 -0
  23. data/lib/rbcurse/extras/widgets/horizlist.rb +203 -0
  24. data/lib/rbcurse/extras/widgets/menutree.rb +63 -0
  25. data/lib/rbcurse/extras/widgets/multilinelabel.rb +142 -0
  26. data/lib/rbcurse/extras/widgets/rcomboedit.rb +256 -0
  27. data/lib/rbcurse/extras/widgets/rlink.rb.moved +27 -0
  28. data/lib/rbcurse/extras/widgets/rlistbox.rb +1247 -0
  29. data/lib/rbcurse/extras/widgets/rmenulink.rb.moved +21 -0
  30. data/lib/rbcurse/extras/widgets/rmulticontainer.rb +304 -0
  31. data/lib/rbcurse/extras/widgets/rmultisplit.rb +722 -0
  32. data/lib/rbcurse/extras/widgets/rmultitextview.rb +306 -0
  33. data/lib/rbcurse/extras/widgets/rpopupmenu.rb +755 -0
  34. data/lib/rbcurse/extras/widgets/rtable.rb +1758 -0
  35. data/lib/rbcurse/extras/widgets/rvimsplit.rb +800 -0
  36. data/lib/rbcurse/extras/widgets/table/tablecellrenderer.rb +86 -0
  37. data/lib/rbcurse/extras/widgets/table/tabledatecellrenderer.rb +98 -0
  38. metadata +94 -0
@@ -0,0 +1,670 @@
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
+ #
11
+ require 'logger'
12
+ require 'rbcurse'
13
+ require 'rbcurse/core/widgets/rtextarea'
14
+ require 'rbcurse/core/widgets/rtextview'
15
+ require 'rbcurse/core/widgets/rmenu'
16
+ require 'rbcurse/core/widgets/rcombo'
17
+ require 'rbcurse/extras/widgets/rcomboedit'
18
+ require 'rbcurse/core/include/listcellrenderer'
19
+ require 'rbcurse/extras/include/checkboxcellrenderer'
20
+ require 'rbcurse/extras/include/comboboxcellrenderer'
21
+ require 'rbcurse/extras/include/celleditor'
22
+ require 'rbcurse/extras/widgets/rlistbox'
23
+ require 'rbcurse/core/widgets/rlist'
24
+ #require 'rbcurse/deprecated/widgets/rmessagebox'
25
+ require 'rbcurse/core/widgets/rtree'
26
+ require 'rbcurse/core/include/appmethods.rb'
27
+ require 'rbcurse/core/widgets/scrollbar'
28
+ def help_text
29
+ <<-eos
30
+ TEST2 HELP 1.5.0
31
+
32
+ This is some help text for test2.
33
+
34
+ Alt-C/F10 - Exit application
35
+ Alt-! - Drop to shell
36
+ C-x c - Drop to shell
37
+ C-x l - list of files
38
+ C-x p - process list
39
+ C-x d - disk usage list
40
+ C-x s - Git status
41
+ C-x d - Git diff
42
+ C-x w - Git whatchanged
43
+ Alt-x - Command mode (<tab> to see commands and select)
44
+
45
+ Some commands for using bottom of screen as vim and emacs do.
46
+ To add
47
+
48
+ -----------------------------------------------------------------------
49
+ eos
50
+ end
51
+ if $0 == __FILE__
52
+
53
+ include RubyCurses
54
+ include RubyCurses::Utils
55
+
56
+ begin
57
+ # Initialize curses
58
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
59
+ path = File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")
60
+ file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
61
+ $log = Logger.new(path)
62
+ $log.level = Logger::DEBUG
63
+
64
+ @lookfeel = :classic # :dialog # or :classic
65
+
66
+ @window = VER::Window.root_window
67
+ # Initialize few color pairs
68
+ # Create the window to be associated with the form
69
+ # Un post form and free the memory
70
+
71
+ catch(:close) do
72
+ colors = Ncurses.COLORS
73
+ $log.debug "START #{colors} colors test2.rb --------- #{@window} "
74
+ @form = Form.new @window
75
+ title = (" "*30) + "Original Demo of basic Ruby Curses Widgets " + Rbcurse::VERSION
76
+ Label.new @form, {'text' => title, :row => 0, :col => 0, :color => 'green', :bgcolor => 'black'}
77
+ r = 1; fc = 12;
78
+ mnemonics = %w[ n l r p]
79
+ %w[ name line regex password].each_with_index do |w,i|
80
+ field = Field.new @form do
81
+ name w
82
+ row r
83
+ col fc
84
+ display_length 30
85
+ #set_buffer "abcd "
86
+ set_label Label.new @form, {'text' => w, 'color'=>'cyan','mnemonic'=> mnemonics[i]}
87
+ end
88
+ r += 1
89
+ end
90
+
91
+ $message = Variable.new
92
+ $message.value = "Message Comes Here"
93
+ message_label = RubyCurses::Label.new @form, {'text_variable' => $message,
94
+ "name"=>"message_label","row" => Ncurses.LINES-1, "col" => 1, "display_length" => 60,
95
+ "height" => 2, 'color' => 'cyan'}
96
+
97
+ $results = Variable.new
98
+ $results.value = "A variable"
99
+ var = RubyCurses::Label.new @form, {'text_variable' => $results, "row" => r, "col" => fc}
100
+ r += 1
101
+ mylist = File.open("data/tasks.txt",'r').readlines
102
+ #0.upto(100) { |v| mylist << "#{v} scrollable data" }
103
+ listb = List.new @form do
104
+ name "mylist"
105
+ row r
106
+ col 1
107
+ width 40
108
+ height 11
109
+ list mylist
110
+ #selection_mode :SINGLE
111
+ show_selector true
112
+ #row_selected_symbol "*"
113
+ #row_unselected_symbol " "
114
+ selected_bgcolor :white
115
+ selected_color :blue
116
+ title "Todo List"
117
+ end
118
+ Scrollbar.new @form, :parent => listb # 2011-10-1 added
119
+ #listb.list_data_model.insert -1, "rake build", "rake release", "bump version", "fix bugs"
120
+ col2 = 42
121
+ texta = TextArea.new @form do
122
+ name "mytext"
123
+ row 1
124
+ col col2
125
+ width 50
126
+ height 14
127
+ title "Editable box"
128
+ #title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
129
+ print_footer true
130
+ bind(:CHANGE){|e| $message.value = e.to_s+" CP:"+e.source.curpos.to_s }
131
+ end
132
+ lines = File.open("data/unix1.txt",'r').readlines
133
+ lines.each { |e| texta << e }
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."
135
+ #texta << "Let me not defer it or neglect it, for I shall not pass this way again."
136
+ #texta << " "
137
+ #texta << " F10 to exit. or click cancel button"
138
+ #texta << " Or alt-c"
139
+
140
+ col3 = 92
141
+ treemodel = nil
142
+ atree = Tree.new @form, :title => "Tree", :row =>1, :col=>col3, :height => 14, :width => 15 do
143
+ treemodel = root "ruby language" do
144
+ branch "mri" do
145
+ leaf "1.9.1"
146
+ leaf "1.9.2"
147
+ leaf "1.9.3"
148
+ end
149
+ branch "jruby" do
150
+ leaf "1.5"
151
+ leaf "a really long leaf"
152
+
153
+ end
154
+ branch "ree" do
155
+ leaf "1.8"
156
+ leaf "1.9"
157
+ leaf "2.0"
158
+ end
159
+ end
160
+ end
161
+ root = treemodel.root
162
+ atree.set_expanded_state root, true
163
+ #listcb.cell_editor.component.form = @form
164
+
165
+ w1 = Ncurses.COLS-col2-1
166
+ @textview = TextView.new @form do
167
+ name "myView"
168
+ row 15
169
+ col col2
170
+ width w1
171
+ height 11
172
+ title "README.mark"
173
+ #title_attrib 'bold'
174
+ print_footer true
175
+ footer_attrib 'bold'
176
+ end
177
+ content = File.open("../README.md","r").readlines
178
+ @textview.set_content content #, :WRAP_WORD
179
+ #@textview.top_row 21
180
+
181
+ # just for demo, lets scroll the text view as we scroll this.
182
+ listb.bind(:ENTER_ROW, @textview) { |alist, tview| tview.top_row alist.current_index
183
+ pb = @form.by_name["pbar"]
184
+ pb.visible true
185
+ len = alist.current_index
186
+ ct = (listb.size-1) * 1.00
187
+ pb.fraction(len/ct)
188
+ i = ((len/ct)*100).to_i
189
+ i = 100 if i > 100
190
+ pb.text = "completed:#{i}"
191
+ }
192
+ listb.bind(:LEAVE) {
193
+ pb = @form.by_name["pbar"]
194
+ pb.visible false
195
+ r = pb.row
196
+ c = pb.col
197
+ @window.wmove(r,c); @window.wclrtoeol
198
+ #@window.wrefresh
199
+ }
200
+
201
+ # just for demo, lets scroll the text view to the line you enter
202
+ @form.by_name["line"].bind(:LEAVE, @textview) { |fld, tv| raise(FieldValidationException, "#{fld.getvalue.to_i} Outside range 1,200") if fld.getvalue.to_i >200; tv.top_row(fld.getvalue.to_i) }
203
+ @form.by_name["regex"].bind(:LEAVE, @textview) { |fld, tv| tv.top_row(tv.find_first_match(fld.getvalue)) }
204
+ @form.by_name["regex"].bind(:CHANGED) { |fld|
205
+ $message.value = "REGEX CHANGED!!! #{fld.getvalue} " }
206
+ row = 17
207
+ col = 2
208
+ align = ComboBox.new @form do
209
+ name "combo"
210
+ row row
211
+ col fc
212
+ display_length 10
213
+ editable false
214
+ list %w[left right center]
215
+ set_label Label.new @form, {'text' => "Align", 'color'=>'cyan','col'=>1, "mnemonic"=>"I"}
216
+ list_config :color => :yellow, :bgcolor=>:blue
217
+ end
218
+
219
+ list = ListDataModel.new( %w[white yellow cyan magenta red blue black])
220
+ list.bind(:LIST_DATA_EVENT) { |lde| $message.value = lde.to_s; $log.debug " STA: #{$message.value} #{lde}"; }
221
+ 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 }
222
+
223
+ row += 1
224
+ combo1 = ComboBoxEdit.new @form do
225
+ name "combo1"
226
+ row row
227
+ col fc
228
+ display_length 10
229
+ editable true
230
+ list_data_model list
231
+ set_label Label.new @form, {'text' => "Edit Combo",'color'=>'cyan','col'=>1}
232
+ list_config 'color' => 'white', 'bgcolor'=>'blue', 'max_visible_items' => 6, 'height' => 7
233
+ end
234
+ row += 1
235
+ checkbutton = CheckBox.new @form do
236
+ variable $results
237
+ #value = true
238
+ onvalue "Selected bold "
239
+ offvalue "UNselected bold"
240
+ text "Bold attribute "
241
+ display_length 18 # helps when right aligning
242
+ row row
243
+ col col
244
+ mnemonic 'B'
245
+ end
246
+ row += 1
247
+ @cb_rev = Variable.new false # related to checkbox reverse
248
+ cbb = @cb_rev
249
+ checkbutton1 = CheckBox.new @form do
250
+ variable cbb # $cb_rev
251
+ #value = true
252
+ onvalue "Selected reverse "
253
+ offvalue "UNselected reverse"
254
+ text "Reverse attribute "
255
+ display_length 18
256
+ row row
257
+ col col
258
+ mnemonic 'R'
259
+ end
260
+ row += 1
261
+ togglebutton = ToggleButton.new @form do
262
+ value true
263
+ onvalue " Toggle Down "
264
+ offvalue " Untoggle "
265
+ row row
266
+ col col
267
+ mnemonic 'T'
268
+ #underline 0
269
+ end
270
+ # a special case required since another form (combo popup also modifies)
271
+ $message.update_command() { message_label.repaint }
272
+
273
+ f = @form.by_name["line"]
274
+ f.display_length(3).set_buffer(24).valid_range(1..200).
275
+ maxlen(3).
276
+ type(:integer)
277
+
278
+ @form.by_name["name"].set_buffer( "Not focusable").
279
+ set_focusable(false)
280
+
281
+ @form.by_name["regex"].valid_regex(/^[A-Z][a-z]*/).
282
+ set_buffer( "SYNOP").
283
+ display_length(10).
284
+ maxlen = 20
285
+
286
+ @form.by_name["password"].set_buffer("").
287
+ show('*').
288
+ color('red').
289
+ values(%w[scotty tiger secret pass qwerty]).
290
+ null_allowed true
291
+
292
+ # a form level event, whenever any widget is focussed, make the label red
293
+ @form.bind(:ENTER) { |f| f.label && f.label.bgcolor = 'red' if f.respond_to? :label}
294
+ @form.bind(:LEAVE) { |f| f.label && f.label.bgcolor = 'black' if f.respond_to? :label}
295
+
296
+ row += 1
297
+ colorlabel = Label.new @form, {'text' => "Select a color:", "row" => row, "col" => col,
298
+ "color"=>"cyan", "mnemonic" => 'S'}
299
+ $radio = Variable.new
300
+ $radio.update_command(colorlabel) {|tv, label| label.color tv.value; }
301
+ $radio.update_command() {|tv| message_label.color tv.value; align.bgcolor tv.value;
302
+ combo1.bgcolor tv.value}
303
+ $radio.update_command() {|tv| @form.widgets.each { |e| next unless e.is_a? Widget;
304
+ e.bgcolor tv.value }; @mb.bgcolor = tv.value }
305
+
306
+ # whenever updated set colorlabel and messagelabel to bold
307
+ $results.update_command(colorlabel,checkbutton) {|tv, label, cb|
308
+ attrs = cb.value ? 'bold' : 'normal'; label.attr(attrs); message_label.attr(attrs)}
309
+
310
+ align.bind(:ENTER_ROW) {|fld| message_label.justify fld.getvalue}
311
+
312
+ align.bind(:ENTER_ROW) {|fld|
313
+ if fld.getvalue == 'right'
314
+ checkbutton1.align_right true
315
+ checkbutton.align_right true
316
+ else
317
+ checkbutton1.align_right false
318
+ checkbutton.align_right false
319
+ end
320
+ }
321
+
322
+ # whenever updated set colorlabel and messagelabel to reverse
323
+ #@cb_rev.update_command(colorlabel,checkbutton1) {|tv, label, cb| attrs = cb.value ? 'reverse' : nil; label.attr(attrs); message_label.attr(attrs)}
324
+ # changing nil to normal since PROP CHAN handler will not fire if nil being set.
325
+ @cb_rev.update_command(colorlabel,checkbutton1) {|tv, label, cb|
326
+ attrs = cb.value ? 'reverse' : 'normal'; label.attr(attrs); message_label.attr(attrs)}
327
+
328
+ row += 1
329
+ dlen = 10
330
+ radio1 = RadioButton.new @form do
331
+ variable $radio
332
+ text "red"
333
+ value "red"
334
+ color "red"
335
+ display_length dlen # helps when right aligning
336
+ row row
337
+ col col
338
+ end
339
+ radio11 = RadioButton.new @form do
340
+ variable $radio
341
+ text "c&yan"
342
+ value "cyan"
343
+ color "cyan"
344
+ display_length dlen # helps when right aligning
345
+ row row
346
+ col col+24
347
+ end
348
+
349
+ row += 1
350
+ radio2 = RadioButton.new @form do
351
+ variable $radio
352
+ text "&green"
353
+ value "green"
354
+ color "green"
355
+ display_length dlen # helps when right aligning
356
+ row row
357
+ col col
358
+ end
359
+ radio22 = RadioButton.new @form do
360
+ variable $radio
361
+ text "magenta"
362
+ value "magenta"
363
+ color "magenta"
364
+ display_length dlen # helps when right aligning
365
+ row row
366
+ col col+24
367
+ end
368
+ colorlabel.label_for radio1
369
+ align.bind(:ENTER_ROW) {|fld|
370
+ if fld.getvalue == 'right'
371
+ radio1.align_right true
372
+ radio2.align_right true
373
+ radio11.align_right true
374
+ radio22.align_right true
375
+ else
376
+ radio1.align_right false
377
+ radio2.align_right false
378
+ radio11.align_right false
379
+ radio22.align_right false
380
+ end
381
+ }
382
+
383
+ # instead of using frozen, I will use a PropertyVeto
384
+ # to disallow changes to color itself
385
+ veto = lambda { |e, name|
386
+ if e.property_name == 'color'
387
+ if e.newvalue != name
388
+ raise PropertyVetoException.new("Cannot change this at all!", e)
389
+ end
390
+ elsif e.property_name == 'bgcolor'
391
+ raise PropertyVetoException.new("Cannot change this!", e)
392
+ end
393
+ }
394
+ [radio1, radio2, radio11, radio22].each { |r|
395
+ r.bind(:PROPERTY_CHANGE) do |e| veto.call(e, r.text) end
396
+ }
397
+
398
+ #
399
+ # define the menu
400
+ #
401
+ @mb = RubyCurses::MenuBar.new
402
+ filemenu = RubyCurses::Menu.new "File"
403
+ filemenu.add(item = RubyCurses::MenuItem.new("Open",'O'))
404
+ item.command(@form) {|it, form| $message.value = "Open called on menu bar";
405
+ require './inc//qdfilechooser'
406
+ fchooser = QDFileChooser.new
407
+ #option = fchooser.show_open_dialog
408
+ #$message.value = "File Selection #{option}, #{fchooser.get_selected_file}"
409
+ option = :dummy # we need to redo QDF as per new Messagebox
410
+ if option == :OK
411
+ filesel = fchooser.get_selected_file
412
+ if !filesel.nil?
413
+ texta.remove_all
414
+ content = File.open(filesel,"r").readlines
415
+ content.each do |line|
416
+ texta << line
417
+ end
418
+ else
419
+ alert "File name #{filesel} nil. Pls check code. "
420
+ end
421
+ else
422
+ alert "Functionality temporarily revoked due to change in Messagebox"
423
+ end
424
+ }
425
+
426
+ filemenu.insert_separator 1
427
+ filemenu.add(RubyCurses::MenuItem.new "New",'N')
428
+ filemenu.add(item = RubyCurses::MenuItem.new("Save",'S'))
429
+ item.command() do |it|
430
+ filename = get_string("Please enter file to save in", 20, "t.t")
431
+ $message.value = "file: #{filename}"
432
+ filename ||= "tmpzzzz.tmp"
433
+ str = texta.to_s
434
+ File.open(filename, 'w') {|f| f.write(str) }
435
+ $message.value = " written #{str.length} bytes to file: #{filename}"
436
+ end
437
+ filemenu.add(item = RubyCurses::MenuItem.new("Test",'T'))
438
+ item.command(@form, texta) do |it, form, testa|
439
+ $message.value = "Testing textarea"
440
+ str = File.open("data/lotr.txt",'r').readlines.join
441
+ #str = "Hello there good friends and fellow rubyists. Here is a textarea that I am testing out with"
442
+ #str << " some long data, to see how it acts, how the wrapping takes place. Sit back and enjoy the "
443
+ #str << " bugs as they crop up."
444
+ testa.goto_start
445
+ #testa.cursor_bol
446
+ testa.handle_key ?\C-a.getbyte(0)
447
+ str.each_char {|c| testa.putch(c)}
448
+ testa.repaint
449
+ 3.times { testa.handle_key KEY_DOWN }
450
+ testa.handle_key ?\C-a.getbyte(0)
451
+
452
+ str.each_char {|c| testa.putch(c)}
453
+ $message.value = "Wrapping textarea"
454
+ testa.repaint
455
+ throw(:menubarclose)
456
+ end
457
+ filemenu.add(item = RubyCurses::MenuItem.new("Wrap",'W'))
458
+ item.command(@form, texta) do |it, form, testa|
459
+ #testa.goto_start
460
+ testa.handle_key ?\C-a.getbyte(0)
461
+ testa.wrap_para
462
+ testa.repaint
463
+ throw(:menubarclose)
464
+ end
465
+ filemenu.add(item = RubyCurses::MenuItem.new("Exit",'X'))
466
+ item.command() {
467
+ #throw(:menubarclose);
468
+ throw(:close)
469
+ }
470
+ item = RubyCurses::CheckBoxMenuItem.new "Reverse"
471
+ # item.onvalue="On"
472
+ # item.offvalue="Off"
473
+ #item.checkbox.text "Labelcb"
474
+ #item.text="Labelcb"
475
+ # in next line, an explicit repaint is required since label is on another form.
476
+ item.command(colorlabel){|it, label| att = it.getvalue ? 'reverse' : 'normal'; label.attr(att); label.repaint}
477
+ @status_line = status_line :row => Ncurses.LINES-2
478
+ @status_line.command {
479
+ "F1 Help | F2 Menu | F3 View | F4 Shell | F5 Sh | %20s" % [$message.value]
480
+ }
481
+ row += 1 #2
482
+ ok_button = Button.new @form do
483
+ text "OK"
484
+ name "OK"
485
+ row row
486
+ col col
487
+ #attr 'reverse'
488
+ #highlight_background "white"
489
+ #highlight_foreground "blue"
490
+ mnemonic 'O'
491
+ end
492
+ ok_button.command() { |eve|
493
+ alert("Hope you enjoyed this demo ", {'title' => "Hello", :bgcolor => :blue, :color => :white})
494
+ sw = case @lookfeel
495
+ when :dialog
496
+ progress_dialog :color_pair => $reversecolor, :row_offset => 4, :col_offset => 5
497
+ else
498
+ status_window # at footer last 2 rows
499
+ end
500
+
501
+ sw.print "I am adding some stuff to list", "And testing out StatusWindow"
502
+ sleep 1.0
503
+ listb.list.insert 0, "hello ruby", "so long python", "farewell java", "RIP .Net"
504
+ sw.printstring 1,1, "And some more now ..."
505
+ sleep 0.5
506
+ listb.list.insert 0, "get milk", "make beds", "clean shark pond","sell summer house"
507
+ sleep 0.5
508
+ sw.print "This was a test of Window", "we are almost done now ..."
509
+ clock = %w[ | / - \ ]
510
+ listb.list.each_with_index { |e, index| sw.print e, clock[index%4]; sleep 0.1 }
511
+ sw.linger #@window
512
+ }
513
+
514
+ # using ampersand to set mnemonic
515
+ cancel_button = Button.new @form do
516
+ #variable $results
517
+ text "&Cancel"
518
+ name "Cancel"
519
+ row row
520
+ col col + 10
521
+ #attr 'reverse'
522
+ #highlight_background "white"
523
+ #highlight_foreground "blue"
524
+ #surround_chars ['{ ',' }'] ## change the surround chars
525
+ end
526
+ cancel_button.command { |aeve|
527
+ if @lookfeel == :dialog
528
+ ret = confirm("Do your really want to quit?")
529
+ else
530
+ ret = confirm_window("Do your really want to quit?")
531
+ end
532
+ if ret == :YES || ret == true
533
+ throw(:close);
534
+ else
535
+ $message.value = "Quit aborted"
536
+ end
537
+ }
538
+ #col += 22
539
+ col += 15
540
+ require 'rbcurse/core/widgets/rprogress'
541
+ pbar = Progress.new @form, {:width => 20, :row => Ncurses.LINES-1, :col => Ncurses.COLS-20 ,
542
+ :bgcolor => 'white', :color => 'red', :name => "pbar"}
543
+ #len = 1
544
+ #pbar.fraction(len/100.0)
545
+ pbar.visible false
546
+
547
+
548
+ filemenu.add(item)
549
+ @mb.add(filemenu)
550
+ editmenu = RubyCurses::Menu.new "Edit"
551
+ item = RubyCurses::MenuItem.new "Cut"
552
+ editmenu.add(item)
553
+ item.accelerator = "Ctrl-X"
554
+ item=RubyCurses::MenuItem.new "Copy"
555
+ editmenu.add(item)
556
+ item.accelerator = "Ctrl-C"
557
+ item=RubyCurses::MenuItem.new "Paste"
558
+ editmenu.add(item)
559
+ item.accelerator = "Ctrl-V"
560
+ @mb.add(editmenu)
561
+ @mb.add(menu=RubyCurses::Menu.new("Others"))
562
+ #item=RubyCurses::MenuItem.new "Save","S"
563
+ item = RubyCurses::MenuItem.new "Options ..."
564
+ item.command() do |it|
565
+ require './newtabbedwindow'
566
+ tp = SetupTabbedPane.new
567
+ tp.run
568
+ $message.value=$config_hash.inspect
569
+ $log.debug " returning with #{$config_hash}: #{$config_hash.inspect}"
570
+ end
571
+ menu.add(item)
572
+ item = RubyCurses::MenuItem.new "Shell Command..."
573
+ item.command { shell_output }
574
+ menu.add(item)
575
+ savemenu = RubyCurses::Menu.new "Shell"
576
+ item = RubyCurses::MenuItem.new "Processes"
577
+ item.command { run_command "ps -l" }
578
+ savemenu.add(item)
579
+ item = RubyCurses::MenuItem.new "Files"
580
+ item.command { run_command "ls -l" }
581
+ savemenu.add(item)
582
+ item = RubyCurses::MenuItem.new "Disk"
583
+ item.command { run_command "df -h" }
584
+ savemenu.add(item)
585
+ menu.add(savemenu)
586
+
587
+ savemenu2 = RubyCurses::Menu.new "Git"
588
+ item = RubyCurses::MenuItem.new "Status"
589
+ item.command { run_command "git status" }
590
+ savemenu2.add(item)
591
+ item = RubyCurses::MenuItem.new "Diff"
592
+ item.command { run_command "git diff" }
593
+ savemenu2.add(item)
594
+ item = RubyCurses::MenuItem.new "Name"
595
+ item.command { run_command "git diff --name-status" }
596
+ savemenu2.add(item)
597
+ savemenu.add(savemenu2)
598
+
599
+ @mb.toggle_key = FFI::NCurses::KEY_F2
600
+ @form.set_menu_bar @mb
601
+
602
+ # END
603
+ @form.bind_key(FFI::NCurses::KEY_F3,'view log') {
604
+ require 'rbcurse/core/util/viewer'
605
+ RubyCurses::Viewer.view(path || "rbc13.log", :close_key => KEY_ENTER, :title => "<Enter> to close")
606
+ }
607
+ @form.bind_key(FFI::NCurses::KEY_F4, 'system command') { shell_output }
608
+ @form.bind_key(FFI::NCurses::KEY_F5, 'shell') { suspend }
609
+ @form.bind_key([?\C-x,?c], 'shell') { suspend }
610
+ @form.bind_key(?\M-!, 'shell') { suspend }
611
+ @form.bind_key([?\C-x,?l], 'ls -al') { run_command "ls -al" }
612
+ @form.bind_key([?\C-x,?p], 'ps -l') { run_command "ps -l" }
613
+ @form.bind_key([?\C-x,?d], 'df -h') { run_command "df -h" }
614
+ @form.bind_key([?\C-x,?d], 'git diff') { run_command "git diff --name-status" }
615
+ @form.bind_key([?\C-x, ?s], 'git st') { run_command "git status" }
616
+ @form.bind_key([?\C-x,?w], 'git whatchanged') { run_command "git whatchanged" }
617
+ @form.bind_key(FFI::NCurses::KEY_F1, 'help') { display_app_help help_text() }
618
+ @form.repaint
619
+ @window.wrefresh
620
+ Ncurses::Panel.update_panels
621
+
622
+ # the main loop
623
+
624
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
625
+ break if ch == ?\C-q.getbyte(0)
626
+ begin
627
+ @form.handle_key(ch)
628
+
629
+ rescue FieldValidationException => fve
630
+ alert fve.to_s
631
+
632
+ f = @form.get_current_field
633
+ # lets restore the value
634
+ if f.respond_to? :restore_original_value
635
+ f.restore_original_value
636
+ @form.repaint
637
+ end
638
+ $error_message.value = ""
639
+ rescue => err
640
+ $log.error( err) if err
641
+ $log.error(err.backtrace.join("\n")) if err
642
+ textdialog err
643
+ $error_message.value = ""
644
+ end
645
+
646
+ # this should be avoided, we should not muffle the exception and set a variable
647
+ # However, we have been doing that
648
+ if $error_message.get_value != ""
649
+ if @lookfeel == :dialog
650
+ alert($error_message, {:bgcolor => :red, 'color' => 'yellow'}) if $error_message.get_value != ""
651
+ else
652
+ print_error_message $error_message, {:bgcolor => :red, :color => :yellow}
653
+ end
654
+ $error_message.value = ""
655
+ end
656
+
657
+ @window.wrefresh
658
+ end # while loop
659
+ end # catch
660
+ rescue => ex
661
+ ensure
662
+ $log.debug " -==== EXCEPTION =====-"
663
+ $log.debug( ex) if ex
664
+ $log.debug(ex.backtrace.join("\n")) if ex
665
+ @window.destroy if !@window.nil?
666
+ VER::stop_ncurses
667
+ puts ex if ex
668
+ puts(ex.backtrace.join("\n")) if ex
669
+ end
670
+ end