rbcurse 1.1.5 → 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/CHANGELOG +45 -0
  2. data/Makefile +1 -1
  3. data/Manifest.txt +91 -0
  4. data/NOTES +349 -2
  5. data/README.markdown +12 -0
  6. data/VERSION +1 -1
  7. data/examples/abasiclist.rb +25 -0
  8. data/examples/alpmenu.rb +42 -0
  9. data/examples/app.rb +883 -0
  10. data/examples/appcombo.rb +17 -0
  11. data/examples/appdirtree.rb +73 -0
  12. data/examples/appemail.rb +164 -0
  13. data/examples/appemaillb.rb +308 -0
  14. data/examples/appgcompose.rb +303 -0
  15. data/examples/appgmail.rb +951 -0
  16. data/examples/atree.rb +56 -0
  17. data/examples/dirtree.rb +78 -0
  18. data/examples/focusmanager.rb +31 -0
  19. data/examples/imap.rb +48 -0
  20. data/examples/menu1.rb +79 -0
  21. data/examples/multispl.rb +86 -0
  22. data/examples/rfe.rb +3 -4
  23. data/examples/rmail.rb +188 -0
  24. data/examples/s.rb +10 -0
  25. data/examples/scrollbar.rb +104 -0
  26. data/examples/splitp.rb +56 -0
  27. data/examples/table1.rb +30 -0
  28. data/examples/term.rb +48 -0
  29. data/examples/term2.rb +54 -0
  30. data/examples/test1.rb +4 -2
  31. data/examples/test2.rb +9 -9
  32. data/examples/testapp.rb +44 -0
  33. data/examples/testapp2.rb +51 -0
  34. data/examples/testcombo.rb +2 -2
  35. data/examples/testgmail.rb +46 -0
  36. data/examples/testlistbox.rb +0 -1
  37. data/examples/testmultispl.rb +199 -0
  38. data/examples/testree.rb +127 -0
  39. data/examples/testscroller.rb +0 -1
  40. data/examples/testscrolllb.rb +1 -1
  41. data/examples/testscrollp.rb +2 -1
  42. data/examples/testscrollta.rb +1 -1
  43. data/examples/testscrolltable.rb +1 -2
  44. data/examples/testsplit.rb +1 -1
  45. data/examples/testsplit2.rb +1 -1
  46. data/examples/testsplit3.rb +1 -1
  47. data/examples/testsplit3_1.rb +1 -1
  48. data/examples/testsplit3a.rb +1 -1
  49. data/examples/testsplit3b.rb +1 -1
  50. data/examples/testsplitta.rb +1 -1
  51. data/examples/testsplittv.rb +1 -1
  52. data/examples/testsplittvv.rb +1 -1
  53. data/examples/testtodo.rb +491 -488
  54. data/examples/testvimsplit.rb +111 -0
  55. data/examples/todo.db +0 -0
  56. data/examples/todocsv.csv +28 -0
  57. data/examples/viewtodo.rb +408 -403
  58. data/lib/rbcurse/action.rb +1 -0
  59. data/lib/rbcurse/app.rb +1294 -0
  60. data/lib/rbcurse/applicationheader.rb +7 -2
  61. data/lib/rbcurse/checkboxcellrenderer.rb +0 -12
  62. data/lib/rbcurse/colormap.rb +34 -8
  63. data/lib/rbcurse/comboboxcellrenderer.rb +0 -11
  64. data/lib/rbcurse/defaultlistselectionmodel.rb +23 -7
  65. data/lib/rbcurse/extras/bottomline.rb +1681 -0
  66. data/lib/rbcurse/extras/directorylist.rb +445 -0
  67. data/lib/rbcurse/extras/directorytree.rb +69 -0
  68. data/lib/rbcurse/extras/divider.rb +310 -0
  69. data/lib/rbcurse/extras/focusmanager.rb +31 -0
  70. data/lib/rbcurse/extras/listselectable.rb +222 -0
  71. data/lib/rbcurse/extras/masterdetail.rb +164 -0
  72. data/lib/rbcurse/extras/menutree.rb +63 -0
  73. data/lib/rbcurse/extras/rlink.rb +27 -0
  74. data/lib/rbcurse/extras/rmenulink.rb +21 -0
  75. data/lib/rbcurse/extras/scrollbar.rb +134 -0
  76. data/lib/rbcurse/extras/stdscrwindow.rb +247 -0
  77. data/lib/rbcurse/extras/tabular.rb +258 -0
  78. data/lib/rbcurse/extras/tabularwidget.rb +1070 -0
  79. data/lib/rbcurse/extras/viewer.rb +106 -0
  80. data/lib/rbcurse/io.rb +137 -80
  81. data/lib/rbcurse/keylabelprinter.rb +4 -0
  82. data/lib/rbcurse/listcellrenderer.rb +91 -59
  83. data/lib/rbcurse/listscrollable.rb +93 -95
  84. data/lib/rbcurse/listselectable.rb +60 -7
  85. data/lib/rbcurse/ractionevent.rb +67 -0
  86. data/lib/rbcurse/rbasiclistbox.rb +688 -0
  87. data/lib/rbcurse/rcombo.rb +5 -5
  88. data/lib/rbcurse/rcommandwindow.rb +555 -0
  89. data/lib/rbcurse/rinputdataevent.rb +12 -0
  90. data/lib/rbcurse/rlistbox.rb +305 -124
  91. data/lib/rbcurse/rmenu.rb +99 -46
  92. data/lib/rbcurse/rmessagebox.rb +13 -6
  93. data/lib/rbcurse/rmulticontainer.rb +54 -93
  94. data/lib/rbcurse/rmultisplit.rb +731 -0
  95. data/lib/rbcurse/rmultitextview.rb +3 -2
  96. data/lib/rbcurse/rpopupmenu.rb +0 -1
  97. data/lib/rbcurse/rprogress.rb +117 -0
  98. data/lib/rbcurse/rscrollpane.rb +2 -1
  99. data/lib/rbcurse/rsplitpane.rb +94 -20
  100. data/lib/rbcurse/rsplitpane2.rb +1009 -0
  101. data/lib/rbcurse/rtabbedpane.rb +3 -2
  102. data/lib/rbcurse/rtabbedwindow.rb +0 -1
  103. data/lib/rbcurse/rtable.rb +92 -64
  104. data/lib/rbcurse/rtextarea.rb +91 -57
  105. data/lib/rbcurse/rtextview.rb +223 -70
  106. data/lib/rbcurse/rtree.rb +723 -0
  107. data/lib/rbcurse/rviewport.rb +2 -1
  108. data/lib/rbcurse/rvimsplit.rb +768 -0
  109. data/lib/rbcurse/rwidget.rb +524 -325
  110. data/lib/rbcurse/table/tablecellrenderer.rb +1 -1
  111. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -1
  112. data/lib/rbcurse/tree/treecellrenderer.rb +137 -0
  113. data/lib/rbcurse/tree/treemodel.rb +428 -0
  114. data/lib/rbcurse/vieditable.rb +14 -13
  115. data/lib/ver/ncurses.rb +6 -0
  116. data/lib/ver/window.rb +67 -32
  117. metadata +99 -23
  118. data/bin/rbcurse +0 -0
  119. data/examples/rvimsplit.rb +0 -376
  120. data/examples/todo.rb +0 -1
  121. data/lib/rbcurse/rform.rb +0 -845
  122. data/lib/rbcurse/selectable.rb +0 -94
  123. data/rbcurse.gemspec +0 -188
data/examples/s.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rbcurse/app'
2
+
3
+ App.new do
4
+ keypress do |ch|
5
+ case ch
6
+ when :down
7
+ when :up
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,104 @@
1
+ require 'rbcurse/app'
2
+ include Ncurses
3
+ include RubyCurses
4
+
5
+ # This paints a vertical white bar given row and col, and length. It also calculates and prints
6
+ # a small bar over this based on relaetd objects list.length and current_index.
7
+ # Typically, after setup one would keep updating only current_index from the repaint method
8
+ # of caller or in the traversal event. This would look best if the listbox also has a reverse video border, or none.
9
+ # @example
10
+ # lb = list_box ....
11
+ # sb = Scrollbar.new @form, :row => lb.row, :col => lb.col, :length => lb.height, :list_length => lb.list.length, :current_index => 0
12
+ # .... later as user traverses
13
+ # sb.current_index = lb.current_index
14
+ #
15
+ # At a later stage, we will integrate this with lists and tables, so it will happen automatically.
16
+ #
17
+ # @since 1.2.0 UNTESTED
18
+ module RubyCurses
19
+ class Scrollbar < Widget
20
+ # row to start, same as listbox, required.
21
+ dsl_property :row
22
+ # column to start, same as listbox, required.
23
+ dsl_property :col
24
+ # how many rows is this (should be same as listboxes height, required.
25
+ dsl_property :length
26
+ # vertical or horizontal currently only VERTICAL
27
+ dsl_property :orientation
28
+ # to take changes or data, unused as of now
29
+ dsl_property :parent
30
+ # which row is focussed, current_index of listbox, required.
31
+ dsl_property :current_index
32
+ # how many total rows of data does the list have, same as @list.length, required.
33
+ dsl_property :list_length
34
+
35
+
36
+ def initialize form, config={}, &block
37
+
38
+ # setting default first or else Widget will place its BW default
39
+ #@color, @bgcolor = ColorMap.get_colors_for_pair $bottomcolor
40
+ super
41
+ @color_pair = get_color $datacolor, @color, @bgcolor
42
+ @scroll_pair = get_color $bottomcolor, :green, :white
43
+ @window = form.window
44
+ @editable = false
45
+ @focusable = false
46
+ @row ||= 0
47
+ @col ||= 0
48
+ @repaint_required = true
49
+ @orientation = :V
50
+ end
51
+
52
+ ##
53
+ # XXX need to move wrapping etc up and done once.
54
+ def repaint
55
+ raise ArgumentError, "current_index must be provided" unless @current_index
56
+ raise ArgumentError, "list_length must be provided" unless @list_length
57
+ my_win = @form ? @form.window : @target_window
58
+ @graphic = my_win unless @graphic
59
+ return unless @repaint_required
60
+
61
+ # first print a right side vertical line
62
+ bordercolor = @border_color || $datacolor
63
+ borderatt = @border_attrib || Ncurses::A_REVERSE
64
+
65
+
66
+ @graphic.attron(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
67
+ @graphic.mvvline(@row+0, @col, 1, @length-0)
68
+ @graphic.attroff(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
69
+
70
+ # now calculate and paint the scrollbar
71
+ pht = @length
72
+ listlen = @list_length * 1.0
73
+ @current_index = 0 if @current_index < 0
74
+ @current_index = listlen-1 if @current_index >= listlen
75
+ sclen = (pht/listlen)* @length
76
+ scloc = (@current_index/listlen)* @length
77
+ scloc = (@length - sclen) if scloc > @length - sclen # don't exceed end
78
+ @graphic.attron(Ncurses.COLOR_PAIR(@scroll_pair) | borderatt)
79
+ r = @row + scloc
80
+ c = @col + 0
81
+ @graphic.mvvline(r, c, 1, sclen)
82
+ @graphic.attroff(Ncurses.COLOR_PAIR(@scroll_pair) | borderatt)
83
+ @repaint_required = false
84
+ end
85
+ ##
86
+ ##
87
+ # ADD HERE
88
+ end
89
+ end
90
+ App.new do
91
+ r = 5
92
+ len = 20
93
+ hline :width => 20, :row => r, :attrib => Ncurses::A_REVERSE
94
+ sb = Scrollbar.new @form, :row => r, :col => 20, :length => len, :list_length => 50, :current_index => 0
95
+ hline :width => 20, :row => len+r
96
+ keypress do |ch|
97
+ case ch
98
+ when :down
99
+ sb.current_index += 1
100
+ when :up
101
+ sb.current_index -= 1
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,56 @@
1
+ require 'rbcurse/app'
2
+
3
+ App.new do
4
+ header = app_header "rbcurse 1.2.0", :text_center => "Splitpane Demo", :text_right =>""
5
+ message_row(27)
6
+ message "<TAB> between outer panes, Alt-W between inner tabs, Alt-TAb to exit Splitpane"
7
+
8
+ stack :margin_top => 5, :margin => 15, :width => 79 do
9
+ splp = splitpane "outer", :height => 15 do |s|
10
+ fc = splitpane "top", :orientation => :VERTICAL_SPLIT, :border_color => $promptcolor, :divider_at => 0.3 do |fc1|
11
+ lb = list_box "Shapes",:list => ["Square", "Oval", "Rectangle", "Somethinglarge"], :choose => ["Oval"]
12
+ fc1.first_component lb
13
+
14
+ lb2 = list_box "MyGems", :list => ["highline", "sqlite3-ruby", "thor", "ncurses"], :choose => ["thor"]
15
+ fc1.second_component lb2
16
+
17
+ end
18
+ s.first_component fc
19
+
20
+ sc = textarea "Edit"
21
+ s.second_component sc
22
+
23
+ end # splp
24
+ blank
25
+ flow do
26
+ #toggle :onvalue => "Vertical", :offvalue => "Horizontal", :value => true do |e|
27
+ #message "pressed #{e.state}"
28
+ #case e.state
29
+ #when :DESELECTED
30
+ #$log.debug " about to call orientation with V"
31
+ #splp.orientation :VERTICAL_SPLIT
32
+ ##ret = splp.reset_to_preferred_sizes
33
+ #else
34
+ #$log.debug " about to call orientation with H"
35
+ #splp.orientation :HORIZONTAL_SPLIT
36
+ ##ret = splp.reset_to_preferred_sizes
37
+ #end
38
+ #end
39
+ fc = splp
40
+ # increase split size
41
+ button "+" do
42
+ #splp.set_divider_location(splp.divider_location+1)
43
+ fc.set_divider_location(splp.divider_location+1)
44
+ end
45
+ # decrease split size
46
+ button "-" do
47
+ fc.set_divider_location(splp.divider_location-1)
48
+ end
49
+ # equalize split size
50
+ button "=" do
51
+ splp.set_resize_weight(0.50)
52
+ end
53
+ end
54
+
55
+ end # stack
56
+ end # app
@@ -0,0 +1,30 @@
1
+ require 'rbcurse/app'
2
+
3
+ if $0 == __FILE__
4
+ #app = App.new
5
+ #window = app.window
6
+ #window.printstring 2, 30, "Demo of Listbox - rbcurse", $normalcolor, 'reverse'
7
+ #app.logger.info "beforegetch"
8
+ #window.getch
9
+ #app.close
10
+ # this was the yield example, but now we've moved to instance eval
11
+ App.new do
12
+ @window.printstring 1, 30, "Demo of Table - rbcurse", $normalcolor, 'reverse'
13
+ @window.printstring 2, 30, "Hit F1 to quit", $datacolor, 'normal'
14
+ data = [["Roger Federer",16,"SWI"],
15
+ ["Pete Sampras",14, "USA"],
16
+ ["Roy Emerson", 12, "AUS"],
17
+ ["Bjorn Borg", 11, "SWE"],
18
+ ["Rod Laver", 11, "AUS"],
19
+ ["Bill Tilden", 10, "USA"]]
20
+ colnames = %w[ Player Wins Nation ]
21
+ stack :margin_top => 3, :margin => 10 do
22
+ # we leave out :width so it gets calculated by column_widths
23
+ t = table :height => 10, :columns => colnames, :data => data, :column_widths => [15,5,10], :extended_keys => true
24
+ # :estimate_widths => true
25
+ # other options are :column_widths => [12,4,12]
26
+ # :size_to_fit => true
27
+
28
+ end
29
+ end
30
+ end
data/examples/term.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'rbcurse/app'
2
+ require 'terminal-table/import'
3
+
4
+ App.new do
5
+ header = app_header "rbcurse 1.2.0", :text_center => "**** Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
6
+ message "Press F1 to escape from here"
7
+
8
+ stack :margin_top => 2, :margin => 5, :width => 30 do
9
+ t = Terminal::Table.table(['a', 'b'], [1, 2], [3, 4])
10
+ $log.debug "YYY table #{t.class} "
11
+ list_box :list => t.render2
12
+ t = Terminal::Table.table ['a', 'b']
13
+ t << [1, 2]
14
+ t << [3, 4]
15
+ t << :separator
16
+ t << [4, 6]
17
+ #list_box :list => t.to_s.split("\n")
18
+ list_box :list => t.render2
19
+ end # stack
20
+ t = Terminal::Table.table do |t|
21
+ t.headings = 'First Name', 'Last Name', 'Email'
22
+ t << %w( TJ Holowaychuk tj@vision-media.ca )
23
+ t << %w( Bob Someone bob@vision-media.ca )
24
+ t << %w( Joe Whatever bob@vision-media.ca )
25
+ end
26
+ #t = t.to_s.split(/[|+]\n/)
27
+ t = t.render2
28
+ wid = t[0].length + 2
29
+ stack :margin_top => 2, :margin => 35, :width => wid do
30
+ list_box :list => t
31
+ t = Terminal::Table.table do
32
+ self.headings = 'First Name', 'Last Name', 'Email'
33
+ add_row ['TJ', 'Holowaychuk', 'tj@vision-media.ca']
34
+ add_row ['Bob', 'Someone', 'bob@vision-media.ca']
35
+ add_row ['Joe', 'Whatever', 'joe@vision-media.ca']
36
+ add_separator
37
+ add_row ['Total', { :value => '3', :colspan => 2, :alignment => :right }]
38
+ align_column 1, :center
39
+ end
40
+ #lb = list_box :list => t.render2
41
+ lb = textview :set_content => t.render2, :height => 10
42
+ lb.bind(:PRESS){|tae|
43
+ alert "Pressed list on #{tae.word_under_cursor(nil, nil, "|")} "
44
+ }
45
+ # make a textview that is vienabled by default.
46
+ end
47
+
48
+ end # app
data/examples/term2.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'rbcurse/app'
2
+ require 'rbcurse/extras/tabular'
3
+ require 'rbcurse/extras/scrollbar'
4
+
5
+ App.new do
6
+ header = app_header "rbcurse 1.2.0", :text_center => "**** Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
7
+ message "Press F1 to escape from here"
8
+
9
+ stack :margin_top => 2, :margin => 5, :width => 30 do
10
+ t = Tabular.new(['a', 'b'], [1, 2], [3, 4])
11
+ $log.debug "YYY table #{t.class} "
12
+ list_box :list => t.render
13
+ t = Tabular.new ['a', 'b']
14
+ t << [1, 2]
15
+ t << [3, 4]
16
+ t << [4, 6]
17
+ #list_box :list => t.to_s.split("\n")
18
+ list_box :list => t.render
19
+ end # stack
20
+ t = Tabular.new do |t|
21
+ t.headings = 'First Name', 'Last Name', 'Email'
22
+ t << %w( TJ Holowaychuk tj@vision-media.ca )
23
+ t << %w( Bob Someone bob@vision-media.ca )
24
+ t << %w( Joe Whatever bob@vision-media.ca )
25
+ end
26
+
27
+ t = t.render
28
+ wid = t[0].length + 2
29
+ stack :margin_top => 2, :margin => 35, :width => wid do
30
+ list_box :list => t
31
+ t = Tabular.new do
32
+ self.headings = 'First Name', 'Last Name', 'Email'
33
+ add_row ['Roald', 'Amundsen', 'ra@explorers.org']
34
+ add_row ['Francis', 'Drake', 'joe@ducks.com']
35
+ add_row ['Hsuan', 'Tsang', 'tsang@asia.org']
36
+ add_separator
37
+ add_row ['Ernest', 'Shackleton', 'jack@radio-schakc.org']
38
+ add_row ['Fa', 'Hsien', 'fa@sheen.net']
39
+ add_row ['Vasco', 'Da Gama', 'bob@vasco.org']
40
+ add_row ['David', 'Livingstone', 'jack@trolls.com']
41
+ #add_row ['Total', { :value => '3', :colspan => 2, :alignment => :right }]
42
+ align_column 1, :center
43
+ self.numbering = true
44
+ end
45
+ #lb = list_box :list => t.render2
46
+ lb = textview :set_content => t.render, :height => 10
47
+ lb.bind(:PRESS){|tae|
48
+ alert "Pressed list on line #{tae.current_index} #{tae.word_under_cursor(nil, nil, "|")} "
49
+ }
50
+ Scrollbar.new @form, :parent => lb
51
+ #make a textview that is vienabled by default.
52
+ end
53
+
54
+ end # app
data/examples/test1.rb CHANGED
@@ -37,7 +37,7 @@ if $0 == __FILE__
37
37
  type :list
38
38
  button_type :ok_cancel
39
39
  list %w[john tim lee wong rahul edward why chad andy]
40
- list_selection_mode 'multiple'
40
+ list_selection_mode :multiple
41
41
  default_values %w[ lee why ]
42
42
 
43
43
  default_button 0
@@ -189,11 +189,13 @@ if $0 == __FILE__
189
189
  title_attrib 'bold'
190
190
  end
191
191
  #listb.list.bind(:ENTER_ROW) { field.set_buffer listb.selected_item }
192
+ # if you find that cursor goes into listbox while typing, then
193
+ # i've put set_form_row in listbox list_data_changed
192
194
  field.bind(:CHANGE) do |f|
193
195
  flist = Dir.glob(f.getvalue+"*")
194
196
  l = listb.list
195
197
  l.remove_all
196
- l.insert 0, *flist
198
+ l.insert( 0, *flist) if flist
197
199
  end
198
200
  @mb = RubyCurses::MessageBox.new @form do
199
201
  title "Sample File Selector"
data/examples/test2.rb CHANGED
@@ -402,9 +402,10 @@ if $0 == __FILE__
402
402
  col col
403
403
  mnemonic 'O'
404
404
  end
405
- ok_button.command { |form|
405
+ ok_button.command() { |eve|
406
406
  alert("About to dump data into log file!")
407
- form.dump_data; $message.value = "Dumped data to log file"
407
+ @form.dump_data
408
+ $message.value = "Dumped data to log file"
408
409
  listb.list.insert 0, "hello ruby", "so long python", "farewell java", "RIP .Net"
409
410
  }
410
411
 
@@ -416,7 +417,7 @@ if $0 == __FILE__
416
417
  col col + 10
417
418
  #surround_chars ['{ ',' }'] ## change the surround chars
418
419
  end
419
- cancel_button.command { |form|
420
+ cancel_button.command { |aeve|
420
421
  if confirm("Do your really want to quit?")== :YES
421
422
  throw(:close);
422
423
  else
@@ -479,8 +480,6 @@ if $0 == __FILE__
479
480
  @window.wrefresh
480
481
  Ncurses::Panel.update_panels
481
482
  while((ch = @window.getchar()) != KEY_F1 )
482
- #@cell.repaint @form.window, 29,1, "ok #{ch} pressed!"
483
- #@cell.repaint @form.window, 29,45, "#{ch} pressed!"
484
483
  @form.handle_key(ch)
485
484
  #@form.repaint
486
485
  @window.wrefresh
@@ -488,11 +487,12 @@ if $0 == __FILE__
488
487
  end
489
488
  rescue => ex
490
489
  ensure
491
- @window.destroy if !@window.nil?
492
- VER::stop_ncurses
493
- p ex if ex
494
- p(ex.backtrace.join("\n")) if ex
490
+ $log.debug " -==== EXCEPTION ===== -"
495
491
  $log.debug( ex) if ex
496
492
  $log.debug(ex.backtrace.join("\n")) if ex
493
+ @window.destroy if !@window.nil?
494
+ VER::stop_ncurses
495
+ puts ex if ex
496
+ puts(ex.backtrace.join("\n")) if ex
497
497
  end
498
498
  end
@@ -0,0 +1,44 @@
1
+ require 'rbcurse/app'
2
+
3
+ # this was a test to see how i could have a class and an app inside
4
+ # and i could call methods in the class and have variables available
5
+ # inside App.
6
+ #
7
+ # instance_eval inside stack and others was causing the issue putting everything in
8
+ # App. However, i have to change the app, to use yield in order not to lose context
9
+
10
+ class Testy
11
+ attr_accessor :value
12
+ def initialize val
13
+ @value = val
14
+ @my = "oldval"
15
+ run
16
+ end
17
+ def amethod
18
+ $log.debug "XXXX amethod called... " if $log.debug?
19
+ alert " self #{self.class} amethod "
20
+ @my = "hellothere"
21
+ end
22
+ def run
23
+ puts @value
24
+ app = App.new
25
+ $log.debug " APP : value #{value}" if $log.debug?
26
+ header = app.app_header "rbcurse 1.2.0", :text_center => " #{@value} Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
27
+ app.message "Press F1 to exit from here #{@value} "
28
+
29
+ app.stack :margin_top => 2, :margin => 5, :width => 30 do |s|
30
+ app.label "Hello: ", :attr => :reverse
31
+ f=app.field "abc"
32
+ #amethod()
33
+ f.bind(:CHANGE) {
34
+ amethod()
35
+ app.message "now #{@my} "
36
+ }
37
+
38
+ end # stack
39
+ app.safe_loop
40
+ end
41
+ end
42
+ if __FILE__ == $PROGRAM_NAME
43
+ Testy.new "Rahul"
44
+ end
@@ -0,0 +1,51 @@
1
+ require 'rbcurse/app'
2
+
3
+ ####
4
+ # If you want to create an application which can run standaalong from terminal, or be passed
5
+ # values from a previous form then this is one way you can do it.
6
+ #
7
+ # this was a test to see how i could have a class and an app inside
8
+ # and i could call methods in the class and have variables available
9
+ # inside App.
10
+ #
11
+ # instance_eval inside stack and others was causing the issue putting everything in
12
+ # App. However, i have to change the app, to use yield in order not to lose context
13
+
14
+ class Testy
15
+ attr_accessor :value
16
+ def initialize val
17
+ @value = val
18
+ @my = "oldval"
19
+ run
20
+ end
21
+ # i will call this method from within the App block
22
+ def amethod
23
+ $log.debug "XXXX amethod called... " if $log.debug?
24
+ #alert " self #{self.class} amethod "
25
+ # we will access @my from insdie the block, we also access @f from here
26
+ @my = "hellothere #{@f.getvalue} "
27
+ end
28
+ def run
29
+
30
+ App.new do |app|
31
+ $log.debug " APP : value #{value}" if $log.debug?
32
+ header = app.app_header "rbcurse 1.2.0", :text_center => " #{@value} Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
33
+ app.message "Press F1 to exit from here #{@value} "
34
+
35
+ app.stack :margin_top => 2, :margin => 5, :width => 30 do |s|
36
+ app.label "Hello: ", :attr => :reverse
37
+ @f=app.field "abc"
38
+ #amethod()
39
+ @f.bind(:CHANGE) {
40
+ amethod()
41
+ app.message "now #{@my} "
42
+ }
43
+
44
+ end # stack
45
+ #app.safe_loop
46
+ end
47
+ end
48
+ end
49
+ if __FILE__ == $PROGRAM_NAME
50
+ Testy.new "SomeData"
51
+ end