rbcurse-core 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/README.md +69 -0
  2. data/VERSION +1 -0
  3. data/examples/abasiclist.rb +151 -0
  4. data/examples/alpmenu.rb +46 -0
  5. data/examples/app.sample +17 -0
  6. data/examples/atree.rb +100 -0
  7. data/examples/common/file.rb +45 -0
  8. data/examples/data/README.markdown +9 -0
  9. data/examples/data/brew.txt +38 -0
  10. data/examples/data/color.2 +37 -0
  11. data/examples/data/gemlist.txt +60 -0
  12. data/examples/data/lotr.txt +12 -0
  13. data/examples/data/ports.txt +136 -0
  14. data/examples/data/table.txt +37 -0
  15. data/examples/data/tasks.csv +88 -0
  16. data/examples/data/tasks.txt +27 -0
  17. data/examples/data/todo.txt +10 -0
  18. data/examples/data/todocsv.csv +28 -0
  19. data/examples/data/unix1.txt +21 -0
  20. data/examples/data/unix2.txt +11 -0
  21. data/examples/dbdemo.rb +487 -0
  22. data/examples/dirtree.rb +90 -0
  23. data/examples/newtabbedwindow.rb +100 -0
  24. data/examples/newtesttabp.rb +92 -0
  25. data/examples/tabular.rb +132 -0
  26. data/examples/tasks.rb +167 -0
  27. data/examples/term2.rb +83 -0
  28. data/examples/testkeypress.rb +72 -0
  29. data/examples/testlistbox.rb +158 -0
  30. data/examples/testmessagebox.rb +140 -0
  31. data/examples/testree.rb +106 -0
  32. data/examples/testwsshortcuts.rb +66 -0
  33. data/examples/testwsshortcuts2.rb +127 -0
  34. data/lib/rbcurse.rb +8 -0
  35. data/lib/rbcurse/core/docs/index.txt +73 -0
  36. data/lib/rbcurse/core/include/action.rb +40 -0
  37. data/lib/rbcurse/core/include/appmethods.rb +112 -0
  38. data/lib/rbcurse/core/include/bordertitle.rb +41 -0
  39. data/lib/rbcurse/core/include/chunk.rb +182 -0
  40. data/lib/rbcurse/core/include/io.rb +953 -0
  41. data/lib/rbcurse/core/include/listcellrenderer.rb +140 -0
  42. data/lib/rbcurse/core/include/listeditable.rb +317 -0
  43. data/lib/rbcurse/core/include/listscrollable.rb +590 -0
  44. data/lib/rbcurse/core/include/listselectable.rb +264 -0
  45. data/lib/rbcurse/core/include/multibuffer.rb +83 -0
  46. data/lib/rbcurse/core/include/orderedhash.rb +77 -0
  47. data/lib/rbcurse/core/include/ractionevent.rb +67 -0
  48. data/lib/rbcurse/core/include/rchangeevent.rb +27 -0
  49. data/lib/rbcurse/core/include/rhistory.rb +62 -0
  50. data/lib/rbcurse/core/include/rinputdataevent.rb +47 -0
  51. data/lib/rbcurse/core/include/vieditable.rb +170 -0
  52. data/lib/rbcurse/core/system/colormap.rb +163 -0
  53. data/lib/rbcurse/core/system/keyboard.rb +150 -0
  54. data/lib/rbcurse/core/system/keydefs.rb +30 -0
  55. data/lib/rbcurse/core/system/ncurses.rb +218 -0
  56. data/lib/rbcurse/core/system/panel.rb +162 -0
  57. data/lib/rbcurse/core/system/window.rb +901 -0
  58. data/lib/rbcurse/core/util/ansiparser.rb +117 -0
  59. data/lib/rbcurse/core/util/app.rb +1235 -0
  60. data/lib/rbcurse/core/util/basestack.rb +407 -0
  61. data/lib/rbcurse/core/util/bottomline.rb +1850 -0
  62. data/lib/rbcurse/core/util/colorparser.rb +71 -0
  63. data/lib/rbcurse/core/util/focusmanager.rb +31 -0
  64. data/lib/rbcurse/core/util/padreader.rb +189 -0
  65. data/lib/rbcurse/core/util/rcommandwindow.rb +587 -0
  66. data/lib/rbcurse/core/util/rdialogs.rb +619 -0
  67. data/lib/rbcurse/core/util/viewer.rb +149 -0
  68. data/lib/rbcurse/core/util/widgetshortcuts.rb +505 -0
  69. data/lib/rbcurse/core/widgets/applicationheader.rb +102 -0
  70. data/lib/rbcurse/core/widgets/box.rb +58 -0
  71. data/lib/rbcurse/core/widgets/divider.rb +310 -0
  72. data/lib/rbcurse/core/widgets/keylabelprinter.rb +178 -0
  73. data/lib/rbcurse/core/widgets/rcombo.rb +238 -0
  74. data/lib/rbcurse/core/widgets/rcontainer.rb +415 -0
  75. data/lib/rbcurse/core/widgets/rlink.rb +30 -0
  76. data/lib/rbcurse/core/widgets/rlist.rb +723 -0
  77. data/lib/rbcurse/core/widgets/rmenu.rb +939 -0
  78. data/lib/rbcurse/core/widgets/rmenulink.rb +22 -0
  79. data/lib/rbcurse/core/widgets/rmessagebox.rb +373 -0
  80. data/lib/rbcurse/core/widgets/rprogress.rb +118 -0
  81. data/lib/rbcurse/core/widgets/rtabbedpane.rb +615 -0
  82. data/lib/rbcurse/core/widgets/rtabbedwindow.rb +68 -0
  83. data/lib/rbcurse/core/widgets/rtextarea.rb +920 -0
  84. data/lib/rbcurse/core/widgets/rtextview.rb +780 -0
  85. data/lib/rbcurse/core/widgets/rtree.rb +787 -0
  86. data/lib/rbcurse/core/widgets/rwidget.rb +3040 -0
  87. data/lib/rbcurse/core/widgets/scrollbar.rb +143 -0
  88. data/lib/rbcurse/core/widgets/statusline.rb +94 -0
  89. data/lib/rbcurse/core/widgets/tabular.rb +264 -0
  90. data/lib/rbcurse/core/widgets/tabularwidget.rb +1211 -0
  91. data/lib/rbcurse/core/widgets/textpad.rb +516 -0
  92. data/lib/rbcurse/core/widgets/tree/treecellrenderer.rb +150 -0
  93. data/lib/rbcurse/core/widgets/tree/treemodel.rb +428 -0
  94. metadata +156 -0
data/examples/term2.rb ADDED
@@ -0,0 +1,83 @@
1
+ require 'rbcurse/core/util/app'
2
+ require 'rbcurse/core/widgets/tabular'
3
+ require 'rbcurse/core/widgets/scrollbar'
4
+
5
+ def my_help_text
6
+ <<-eos
7
+ term2.rb
8
+ =========================================================================
9
+ Basic Usage
10
+
11
+ This example shows different ways of putting data in tabular format.
12
+
13
+ The 2 tables on the right differ in behaviour. The first puts tabular data
14
+ into a listbox so you get single/multiple selection. The second puts tabular
15
+ data into a textview, so there's no selection. <space> scrolls instead of
16
+ selects <ENTER> allows us to use the word under cursor for further actions.
17
+
18
+ To see an example of placing tabular data in a tabular widget, see tabular.rb.
19
+ The advantage of tabular_widget is column resizing, hiding, aligning and sorting.
20
+
21
+ =========================================================================
22
+ :n or Alt-n for next buffer. 'q' to quit.
23
+
24
+ eos
25
+ end
26
+ App.new do
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"
29
+ install_help_text my_help_text
30
+
31
+ flow :width => FFI::NCurses.COLS , :height => FFI::NCurses.LINES-2 do
32
+ stack :margin_top => 1, :width_pc => 20 do
33
+ t = Tabular.new(['a', 'b'], [1, 2], [3, 4])
34
+ listbox :list => t.render
35
+
36
+ t = Tabular.new ['a', 'b']
37
+ t << [1, 2]
38
+ t << [3, 4]
39
+ t << [4, 6]
40
+ #list_box :list => t.to_s.split("\n")
41
+ listbox :list => t.render
42
+ end # stack
43
+ file = "data/tasks.csv"
44
+ lines = File.open(file,'r').readlines
45
+ heads = %w[ id sta type prio title ]
46
+ t = Tabular.new do |t|
47
+ t.headings = heads
48
+ lines.each { |e| t.add_row e.split '|' }
49
+ end
50
+
51
+ t = t.render
52
+ wid = t[0].length + 2
53
+ wid = 30
54
+ stack :margin_top => 1, :width_pc => 80 , :height_pc => 100 do
55
+ listbox :list => t, :title => '[ tasks ]', :height_pc => 60
56
+
57
+ r = `ls -l`
58
+ res = r.split("\n")
59
+
60
+ t = Tabular.new do
61
+ # self.headings = 'Perm', 'Gr', 'User', 'U', 'Size', 'Mon', 'Date', 'Time', 'File' # changed 2011 dts
62
+ self.headings = 'User', 'Size', 'Mon', 'Date', 'Time', 'File'
63
+ res.each { |e|
64
+ cols = e.split
65
+ next if cols.count < 6
66
+ cols = cols[3..-1]
67
+ cols = cols[0..5] if cols.count > 6
68
+ add_row cols
69
+ }
70
+ column_width 1, 6
71
+ align_column 1, :right
72
+ end
73
+ #lb = list_box :list => t.render2
74
+ lb = textview :set_content => t.render, :title => '[ls -l]', :height_pc => 40
75
+ lb.bind(:PRESS){|tae|
76
+ alert "Pressed list on line #{tae.current_index} #{tae.word_under_cursor(nil, nil, "|")} "
77
+ }
78
+ Scrollbar.new @form, :parent => lb
79
+ #make a textview that is vienabled by default.
80
+ end
81
+ end # end
82
+
83
+ end # app
@@ -0,0 +1,72 @@
1
+ # demo to test keypresses
2
+ # press any key and see the value that ncurses or our routines catch.
3
+ # Press alt and control combinations and Function keys
4
+ # Ideally each key should return only one value. Sometimes, some TERM setting
5
+ # or terminal emulator may not give correct values or may give different values
6
+ # from what we are expecting.
7
+ # Exit using 'q'.
8
+ require 'logger'
9
+ require 'rbcurse'
10
+ require 'rbcurse/core/widgets/rtextview'
11
+ if $0 == __FILE__
12
+ include RubyCurses
13
+ include RubyCurses::Utils
14
+
15
+ begin
16
+ # Initialize curses
17
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
18
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
19
+
20
+ $log.level = Logger::DEBUG
21
+
22
+ @window = VER::Window.root_window
23
+
24
+ catch(:close) do
25
+ colors = Ncurses.COLORS
26
+ $log.debug "START #{colors} colors ---------"
27
+ @form = Form.new @window
28
+ r = 1; c = 30;
29
+
30
+ # please use a hash to pass these values, avoid this old style
31
+ # i want to move away from it as it comlpicates code
32
+ texta = TextView.new @form do
33
+ name "mytext"
34
+ row r
35
+ col c
36
+ width 60
37
+ height 15
38
+ #editable false
39
+ focusable false
40
+ title "[ Keypresses ]"
41
+ #title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
42
+ title_attrib (Ncurses::A_BOLD)
43
+ end
44
+ help = "q to quit. Check keys. F1..10, C-a..z, Alt a-zA-Z0-9, C-left,rt, Sh-F5..10 .: #{$0}"
45
+ help1 = "Press in quick succession: 1) M-[, w and (2) M-[, M-w. (3) M-Sh-O, w."
46
+ RubyCurses::Label.new @form, {'text' => help, "row" => 21, "col" => 2, "color" => "yellow"}
47
+ RubyCurses::Label.new @form, {'text' => help1, "row" => 22, "col" => 2, "color" => "green"}
48
+
49
+ @form.repaint
50
+ @window.wrefresh
51
+ Ncurses::Panel.update_panels
52
+ while((ch = @window.getchar()) != 999 )
53
+ str = keycode_tos ch
54
+ $log.debug "#{ch} got (#{str})"
55
+ texta << "#{ch} got (#{str})"
56
+ texta.goto_end
57
+ texta.repaint
58
+ @form.repaint
59
+ @window.wrefresh
60
+ break if ch == ?\q.getbyte(0)
61
+ end
62
+ end
63
+ rescue => ex
64
+ ensure
65
+ @window.destroy if !@window.nil?
66
+ VER::stop_ncurses
67
+ p ex if ex
68
+ p(ex.backtrace.join("\n")) if ex
69
+ $log.debug( ex) if ex
70
+ $log.debug(ex.backtrace.join("\n")) if ex
71
+ end
72
+ end
@@ -0,0 +1,158 @@
1
+ # this program tests out a listbox
2
+ # This is written in the old style where we start and end ncurses and initiate a
3
+ # getch loop. It gives more control.
4
+ # The new style is to use App which does the ncurses setup and teardown, as well
5
+ # as manages keys. It also takes care of logger and includes major stuff.
6
+ require 'logger'
7
+ require 'rbcurse'
8
+ require 'rbcurse/core/widgets/rlist'
9
+ require 'rbcurse/core/widgets/rtextview'
10
+ require 'rbcurse/core/include/vieditable'
11
+ #require 'rbcurse/experimental/widgets/undomanager'
12
+ class RubyCurses::List
13
+ # vieditable includes listeditable which
14
+ # does bring in some functions which can crash program like x and X TODO
15
+ # also, f overrides list f mapping. TODO
16
+ include ViEditable
17
+ end
18
+ def my_help_text
19
+ <<-eos
20
+
21
+ =========================================================================
22
+ Basic Usage
23
+
24
+ Press <ENTER> on a class name on the first list, to view ri information
25
+ for it on the right.
26
+
27
+ Tab to right area, and press <ENTER> on a method name, to see its details
28
+ Press / <slash> in any box to search. e.g /String will take you to the
29
+ first occurrence of String. <n> will take you to next.
30
+
31
+ To go quickly to first class starting with 'S', type <f> followed by <S>.
32
+ Then press <n> to go to next match.
33
+
34
+ =========================================================================
35
+ Vim Edit Keys
36
+
37
+ The list on left has some extra vim keys enabled such as :
38
+ yy - yank/copy current line/s
39
+ P, p - paste after or before
40
+ dd - delete current line
41
+ o - insert a line after this one
42
+ C - change content of current line
43
+ These are not of use here, but are demonstrative of list capabilities.
44
+
45
+ =========================================================================
46
+ Buffers
47
+
48
+ Ordinary a textview contains only one buffer. However, the one on the right
49
+ is extended for multiple buffers. Pressing ENTER on the left on several
50
+ rows opens multiple buffers on the right. Use M-n (Alt-N) and M-p to navigate.
51
+ ALternatively, : maps to a menu, so :n and :p may also be used.
52
+ <BACKSPACE> will also go to previous buffer, like a browser.
53
+
54
+ =========================================================================
55
+ Press <M-n> for next help screen, or try :n
56
+
57
+ eos
58
+ end
59
+ if $0 == __FILE__
60
+ include RubyCurses
61
+
62
+ begin
63
+ # Initialize curses
64
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
65
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
66
+ $log.level = Logger::DEBUG
67
+
68
+ @window = VER::Window.root_window
69
+ $catch_alt_digits = true; # emacs like alt-1..9 numeric arguments
70
+ install_help_text my_help_text
71
+ # Initialize few color pairs
72
+ # Create the window to be associated with the form
73
+ # Un post form and free the memory
74
+
75
+ catch(:close) do
76
+ @form = Form.new @window
77
+ @form.bind_key(KEY_F1, 'help'){ display_app_help }
78
+
79
+ # this is the old style of printing something directly on the window.
80
+ # The new style is to use a header
81
+ @form.window.printstring 0, 30, "Demo of Listbox - some vim keys", $normalcolor, BOLD
82
+ r = 1; fc = 1;
83
+
84
+ # this is the old style of using a label at the screen bottom, you can use the status_line
85
+
86
+ v = "F10 quits. F1 Help. Try j k gg G o O C dd f<char> w yy p P / . Press ENTER on Class or Method"
87
+ var = RubyCurses::Label.new @form, {'text' => v, "row" => FFI::NCurses.LINES-2,
88
+ "col" => fc, "display_length" => 100}
89
+
90
+ h = FFI::NCurses.LINES-3
91
+ file = "./data/ports.txt"
92
+ #mylist = File.open(file,'r').readlines
93
+ mylist = `ri -f bs`.split("\n")
94
+ w = 25
95
+ #0.upto(100) { |v| mylist << "#{v} scrollable data" }
96
+ #
97
+ listb = List.new @form, :name => "mylist" ,
98
+ :row => r ,
99
+ :col => 1 ,
100
+ :width => w,
101
+ :height => h,
102
+ :list => mylist,
103
+ :selection_mode => :SINGLE,
104
+ :show_selector => true,
105
+ #row_selected_symbol "[X] "
106
+ #row_unselected_symbol "[ ] "
107
+ :title => " Ruby Classes "
108
+ #title_attrib 'reverse'
109
+ listb.one_key_selection = false # this allows us to map keys to methods
110
+ listb.vieditable_init_listbox
111
+ include Io
112
+ listb.bind_key(?r, 'get file'){ get_file("Get a file:", 70) }
113
+ listb.bind(:PRESS) {
114
+ w = @form.by_name["tv"];
115
+ lines = `ri -f bs #{listb.text}`.split("\n")
116
+ #w.set_content(lines, :ansi)
117
+ w.add_content(lines, :content_type => :ansi, :title => listb.text)
118
+ w.buffer_last
119
+ #w.title = listb.text
120
+ }
121
+
122
+ tv = RubyCurses::TextView.new @form, :row => r, :col => w+1, :height => h, :width => FFI::NCurses.COLS-w-1,
123
+ :name => "tv", :title => "Press Enter on method"
124
+ tv.set_content ["Press Enter on list to view ri information in this area.",
125
+ "Press ENTER on method name to see details"]
126
+ require 'rbcurse/core/include/multibuffer'
127
+ tv.extend(RubyCurses::MultiBuffers)
128
+
129
+ # pressing ENTER on a method name will popup details for that method
130
+ tv.bind(:PRESS) { |ev|
131
+ w = ev.word_under_cursor.strip
132
+ # check that user did not hit enter on empty area
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)
137
+ end
138
+ }
139
+
140
+
141
+ @form.repaint
142
+ @window.wrefresh
143
+ Ncurses::Panel.update_panels
144
+ while((ch = @window.getchar()) != KEY_F10 )
145
+ @form.handle_key(ch)
146
+ @window.wrefresh
147
+ end
148
+ end
149
+ rescue => ex
150
+ $log.debug( ex) if ex
151
+ $log.debug(ex.backtrace.join("\n")) if ex
152
+ ensure
153
+ @window.destroy if !@window.nil?
154
+ VER::stop_ncurses
155
+ p ex if ex
156
+ p(ex.backtrace.join("\n")) if ex
157
+ end
158
+ end
@@ -0,0 +1,140 @@
1
+ # To test out the new messagebox
2
+ # The old messagebox provided a lot of convenience methods that were complicated
3
+ # and confusing. This one is simpler.
4
+ # The examples here are based on the old test1.rb that will not work now
5
+ # since the interface has been changed and simplified
6
+ #
7
+ require 'logger'
8
+ require 'rbcurse'
9
+ require 'rbcurse/core/widgets/rmessagebox'
10
+ #require 'rbcurse/deprecated/widgets/rmessagebox'
11
+
12
+ if $0 == __FILE__
13
+ # Initialize curses
14
+ begin
15
+ # XXX update with new color and kb
16
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
17
+ $log = Logger.new((File.join(ENV['LOGDIR'] || "./" ,"rbc13.log")))
18
+ $log.level = Logger::DEBUG
19
+
20
+ # @window = VER::Window.root_window
21
+
22
+
23
+ catch(:close) do
24
+ choice = ARGV[0] && ARGV[0].to_i || 3
25
+ $log.debug "START MESSAGE BOX TEST #{ARGV[0]}. choice==#{choice} ---------"
26
+ # need to pass a form, not window.
27
+ case choice
28
+ when 1
29
+ require 'rbcurse/core/widgets/rlist'
30
+ nn = "mylist"
31
+ l = List.new nil, :row => 2, :col => 5, :list => %w[john tim lee wong rahul edward why chad andy],
32
+ :selection_mode => :multiple, :height => 10, :width => 20 , :selected_color => :green, :selected_bgcolor => :white, :selected_indices => [2,6], :name => nn
33
+ #default_values %w[ lee why ]
34
+ @mb = MessageBox.new :width => 30, :height => 18 do
35
+ title "Select a name"
36
+ button_type :ok_cancel
37
+ item Label.new :row => 1, :col => 1, :text => "Enter your name:"
38
+ item l
39
+
40
+ #default_button 0 # TODO
41
+ end
42
+ @mb.run
43
+ $log.debug "XXX: #{l.selected_indices} "
44
+ n = @mb.widget(nn)
45
+ $log.debug "XXXX: #{n.selected_indices}, #{n.name} "
46
+ when 2
47
+ @mb = RubyCurses::MessageBox.new do
48
+ title "Color selector"
49
+ message "Select a color"
50
+ #item Label.new :text => "Select a color", :row => 1 , :col => 2
51
+
52
+ r = 3
53
+ c = 2
54
+ %w[&red &green &blue &yellow].each_with_index { |b, i|
55
+ bu = Button.new :name => b, :text => b, :row => r, :col => c
56
+ bu.command { throw(:close, i) }
57
+ item bu
58
+ #bu.default_button(true) if i == 0
59
+ #r += 1
60
+ c += b.length + 5
61
+ }
62
+ end
63
+ index = @mb.run
64
+ $log.debug "XXX: messagebox 2 ret #{index} "
65
+ when 3
66
+ @mb = RubyCurses::MessageBox.new do
67
+ title "Enter your name"
68
+ #message "Enter your first name. You are not permitted to enter x z or q and must enter a capital first"
69
+ message "Enter your first name. Initcaps "
70
+ add Field.new :chars_allowed => /[^0-9xyz]/, :valid_regex => /^[A-Z][a-z]*/, :default => "Matz", :bgcolor => :cyan
71
+ button_type :ok_cancel
72
+ end
73
+ @mb.run
74
+ $log.debug "XXX: got #{@mb.widget(1).text} "
75
+ when 4
76
+ mb = MessageBox.new :title => "HTTP Configuration" , :width => 50 do
77
+ add Field.new :label => 'User', :name => "user", :display_length => 30, :bgcolor => :cyan
78
+ add CheckBox.new :text => "No &frames", :onvalue => "Selected", :offvalue => "UNselected"
79
+ add CheckBox.new :text => "Use &HTTP/1.0", :value => true
80
+ add CheckBox.new :text => "Use &passive FTP"
81
+ add Label.new :text => " Language ", :attr => REVERSE
82
+ $radio = RubyCurses::Variable.new
83
+ add RadioButton.new :text => "py&thon", :value => "python", :color => :blue, :variable => $radio
84
+ add RadioButton.new :text => "rub&y", :color => :red, :variable => $radio
85
+ button_type :ok
86
+ end
87
+ field = mb.widget("user")
88
+ field.bind(:ENTER) do |f|
89
+ listconfig = {'bgcolor' => 'blue', 'color' => 'white'}
90
+ users= %w[john tim lee wong rahul edward _why chad andy]
91
+ index = popuplist(users, :relative_to => field, :col => field.col + 6, :width => field.display_length)
92
+ field.set_buffer users[index] if index
93
+ end
94
+ mb.run
95
+
96
+ when 5
97
+ require 'rbcurse/core/widgets/rlist'
98
+ label = Label.new 'text' => 'File', 'mnemonic'=>'F', :row => 3, :col => 5
99
+ field = Field.new :name => "file", :row => 3 , :col => 10, :width => 40, :set_label => label
100
+ #flist = Dir.glob(File.join( File.expand_path("~/"), "*"))
101
+ flist = Dir.glob("*")
102
+ listb = List.new :name => "mylist", :row => 4, :col => 3, :width => 50, :height => 10,
103
+ :list => flist, :title => "File List", :selected_bgcolor => :white, :selected_color => :blue,
104
+ :selection_mode => :single, :border_attrib => REVERSE
105
+ #listb.bind(:ENTER_ROW) { field.set_buffer listb.selected_item }
106
+ # if you find that cursor goes into listbox while typing, then
107
+ # i've put set_form_row in listbox list_data_changed
108
+ field.bind(:CHANGE) do |f|
109
+ flist = Dir.glob("*"+f.getvalue+"*")
110
+ #l.insert( 0, *flist) if flist
111
+ listb.list flist
112
+ end
113
+ mb = RubyCurses::MessageBox.new :height => 20, :width => 60 do
114
+ title "Sample File Selector"
115
+ add label
116
+ add field
117
+ add listb
118
+ #height 20
119
+ #width 60
120
+ #top 5
121
+ #left 20
122
+ #default_button 0
123
+ button_type :ok_cancel
124
+
125
+ end
126
+ mb.run
127
+ $log.debug "MBOX :selected #{listb.selected_item}"
128
+ end
129
+
130
+ end
131
+ rescue => ex
132
+ ensure
133
+ @window.destroy unless @window.nil?
134
+ VER::stop_ncurses
135
+ p ex if ex
136
+ p(ex.backtrace.join("\n")) if ex
137
+ $log.debug( ex) if ex
138
+ $log.debug(ex.backtrace.join("\n")) if ex
139
+ end
140
+ end