rbcurse 1.4.0 → 1.4.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/NOTES +68 -0
  2. data/README.markdown +73 -330
  3. data/TODO2.txt +2 -2
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +8 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +1 -24
  8. data/examples/appdirtree.rb +1 -1
  9. data/examples/appemail.rb +8 -14
  10. data/examples/appemaillb.rb +2 -2
  11. data/examples/appgcompose.rb +7 -5
  12. data/examples/common/file.rb +40 -0
  13. data/examples/{rmail.rb → common/rmail.rb} +0 -0
  14. data/examples/data/README.markdown +9 -0
  15. data/examples/data/brew.txt +38 -0
  16. data/examples/data/color.2 +37 -0
  17. data/examples/data/gemlist.txt +60 -0
  18. data/examples/data/lotr.txt +12 -0
  19. data/examples/data/ports.txt +136 -0
  20. data/examples/data/tasks.txt +27 -0
  21. data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
  22. data/examples/data/unix1.txt +21 -0
  23. data/examples/data/unix2.txt +11 -0
  24. data/examples/dbdemo.rb +49 -14
  25. data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
  26. data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
  27. data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
  28. data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
  29. data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
  30. data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
  31. data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
  32. data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
  33. data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
  34. data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
  35. data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
  36. data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
  37. data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
  38. data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
  39. data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
  40. data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
  41. data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
  42. data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
  43. data/examples/dirtree.rb +17 -7
  44. data/examples/experimental/resultsetdemo.rb +280 -0
  45. data/examples/experimental/testmform.rb +35 -0
  46. data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
  47. data/examples/experimental/teststackflow.rb +111 -0
  48. data/examples/menu1.rb +1 -0
  49. data/examples/multispl.rb +4 -4
  50. data/examples/newmessagebox.rb +130 -0
  51. data/examples/newtabbedwindow.rb +100 -0
  52. data/examples/newtesttabp.rb +0 -3
  53. data/examples/qdfilechooser.rb +0 -3
  54. data/examples/rfe.rb +134 -18
  55. data/examples/rfe_renderer.rb +48 -2
  56. data/examples/sqlc.rb +2 -1
  57. data/examples/sqlm.rb +0 -2
  58. data/examples/table1.rb +1 -7
  59. data/examples/term2.rb +4 -1
  60. data/examples/test1.rb +0 -5
  61. data/examples/test2.rb +42 -31
  62. data/examples/testapp2.rb +8 -1
  63. data/examples/testchars.rb +0 -4
  64. data/examples/testcombo.rb +5 -9
  65. data/examples/testkeypress.rb +0 -3
  66. data/examples/testmenu.rb +0 -4
  67. data/examples/testmulticomp.rb +3 -5
  68. data/examples/testmulticontainer.rb +94 -0
  69. data/examples/testtable.rb +0 -5
  70. data/examples/testtabp.rb +16 -18
  71. data/examples/testtodo.rb +1 -5
  72. data/examples/testwsshortcuts.rb +64 -0
  73. data/examples/testwsshortcuts2.rb +126 -0
  74. data/examples/viewtodo.rb +1 -4
  75. data/lib/rbcurse.rb +1 -1
  76. data/lib/rbcurse/app.rb +92 -69
  77. data/lib/rbcurse/applicationheader.rb +46 -6
  78. data/lib/rbcurse/celleditor.rb +1 -9
  79. data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
  80. data/lib/rbcurse/common/ansiparser.rb +117 -0
  81. data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
  82. data/lib/rbcurse/common/basestack.rb +407 -0
  83. data/lib/rbcurse/common/bordertitle.rb +41 -0
  84. data/lib/rbcurse/common/chunk.rb +177 -0
  85. data/lib/rbcurse/common/colorparser.rb +71 -0
  86. data/lib/rbcurse/common/keydefs.rb +30 -0
  87. data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
  88. data/lib/rbcurse/deprecated/README.markdown +12 -0
  89. data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
  90. data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
  91. data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
  92. data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
  93. data/lib/rbcurse/experimental/README.markdown +14 -0
  94. data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
  95. data/lib/rbcurse/experimental/stackflow.rb +478 -0
  96. data/lib/rbcurse/extras/bottomline.rb +85 -16
  97. data/lib/rbcurse/extras/box.rb +58 -0
  98. data/lib/rbcurse/extras/directorylist.rb +1 -1
  99. data/lib/rbcurse/extras/horizlist.rb +203 -0
  100. data/lib/rbcurse/extras/listselectable.rb +8 -0
  101. data/lib/rbcurse/extras/multiform.rb +330 -0
  102. data/lib/rbcurse/extras/multilinelabel.rb +142 -0
  103. data/lib/rbcurse/extras/newmessagebox.rb +328 -0
  104. data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
  105. data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
  106. data/lib/rbcurse/extras/padreader.rb +189 -0
  107. data/lib/rbcurse/extras/rcomboedit.rb +256 -0
  108. data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
  109. data/lib/rbcurse/extras/statusline.rb +44 -6
  110. data/lib/rbcurse/extras/tabularwidget.rb +141 -104
  111. data/lib/rbcurse/extras/textpad.rb +516 -0
  112. data/lib/rbcurse/extras/viewer.rb +2 -0
  113. data/lib/rbcurse/io.rb +120 -3
  114. data/lib/rbcurse/listcellrenderer.rb +2 -1
  115. data/lib/rbcurse/listkeys.rb +1 -1
  116. data/lib/rbcurse/listscrollable.rb +72 -7
  117. data/lib/rbcurse/rbasiclistbox.rb +64 -12
  118. data/lib/rbcurse/rchangeevent.rb +0 -1
  119. data/lib/rbcurse/rcombo.rb +54 -59
  120. data/lib/rbcurse/rcommandwindow.rb +46 -10
  121. data/lib/rbcurse/rcontainer.rb +415 -0
  122. data/lib/rbcurse/rdialogs.rb +242 -165
  123. data/lib/rbcurse/rinputdataevent.rb +0 -1
  124. data/lib/rbcurse/rlistbox.rb +19 -9
  125. data/lib/rbcurse/rmessagebox.rb +1 -5
  126. data/lib/rbcurse/rmulticontainer.rb +64 -61
  127. data/lib/rbcurse/rmultitextview.rb +0 -2
  128. data/lib/rbcurse/rpopupmenu.rb +0 -2
  129. data/lib/rbcurse/rscrollform.rb +61 -12
  130. data/lib/rbcurse/rtabbedpane.rb +89 -73
  131. data/lib/rbcurse/rtabbedwindow.rb +53 -211
  132. data/lib/rbcurse/rtable.rb +0 -2
  133. data/lib/rbcurse/rtextarea.rb +14 -14
  134. data/lib/rbcurse/rtextview.rb +165 -50
  135. data/lib/rbcurse/rvimsplit.rb +15 -12
  136. data/lib/rbcurse/rwidget.rb +404 -150
  137. data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
  138. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
  139. data/lib/ver/ncurses.rb +1 -9
  140. data/lib/ver/rpad.rb +375 -0
  141. data/lib/ver/window.rb +262 -440
  142. metadata +73 -31
@@ -73,14 +73,14 @@ def get_string(message, len=50, default="", config={})
73
73
  end
74
74
  return mb.input_value
75
75
  end
76
-
76
+
77
77
  ##
78
78
  # Added 2009-02-05 13:16
79
79
  # get a string from user with some additional checkboxes and optionally supply default values
80
80
  # Usage:
81
- #sel, inp, hash = get_string_with_options("Enter a filter pattern", 20, "*", {"checkboxes" => ["case sensitive","reverse"], "checkbox_defaults"=>[true, false]})
82
- # sel, inp, hash = get_string_with_options("Enter a filter pattern", 20, "*", {"checkboxes" => ["case sensitive","reverse"]})
83
- # $log.debug " POPUP: #{sel}: #{inp}, #{hash['case sensitive']}, #{hash['reverse']}"
81
+ #sel, inp, hash = get_string_with_options("Enter a filter pattern", 20, "*", {"checkboxes" => ["case sensitive","reverse"], "checkbox_defaults"=>[true, false]})
82
+ # sel, inp, hash = get_string_with_options("Enter a filter pattern", 20, "*", {"checkboxes" => ["case sensitive","reverse"]})
83
+ # $log.debug " POPUP: #{sel}: #{inp}, #{hash['case sensitive']}, #{hash['reverse']}"
84
84
  #
85
85
  # @param: message to print,
86
86
  # @param: length of entry field
@@ -155,9 +155,9 @@ def get_string_with_options(message, len=20, default="", config={})
155
155
  end
156
156
  hash = {}
157
157
  if !checks.nil?
158
- checks.each do |c|
159
- hash[c] = mform.by_name[c].getvalue
160
- end
158
+ checks.each do |c|
159
+ hash[c] = mform.by_name[c].getvalue
160
+ end
161
161
  end
162
162
  hash["radio"] = radio.get_value unless radio.nil?
163
163
  # returns button index (0 = OK), value of field, hash containing values of checkboxes
@@ -172,176 +172,253 @@ end
172
172
  #
173
173
  #
174
174
 
175
- # new version with a window created on 2011-10-1 12:37 AM
176
- # Now can be separate from window class, needing nothing, just a util class
177
- # prints a status message and pauses for a char
178
- def print_status_message text, aconfig={}, &block
179
- _print_message :status, text, aconfig, &block
175
+ # new version with a window created on 2011-10-1 12:37 AM
176
+ # Now can be separate from window class, needing nothing, just a util class
177
+ # prints a status message and pauses for a char
178
+ def print_status_message text, aconfig={}, &block
179
+ _print_message :status, text, aconfig, &block
180
+ end
181
+ # new version with a window created on 2011-10-1 12:30 AM
182
+ # Now can be separate from window class, needing nothing, just a util class
183
+ # Why are we dealing with $error_message, that was due to old idea which failed
184
+ # scrap it and send the message.
185
+ def print_error_message text, aconfig={}, &block
186
+ _print_message :error, text, aconfig, &block
187
+ end
188
+ def _create_footer_window h = 2 , w = Ncurses.COLS, t = Ncurses.LINES-2, l = 0
189
+ ewin = VER::Window.new(h, w , t, l)
190
+ end
191
+ # @param [:symbol] :error or :status kind of message
192
+ # @private
193
+ def _print_message type, text, aconfig={}, &block
194
+ case text
195
+ when RubyCurses::Variable # added 2011-09-20 incase variable passed
196
+ text = text.get_value
197
+ when Exception
198
+ text = text.to_s
180
199
  end
181
- # new version with a window created on 2011-10-1 12:30 AM
182
- # Now can be separate from window class, needing nothing, just a util class
183
- # Why are we dealing with $error_message, that was due to old idea which failed
184
- # scrap it and send the message.
185
- def print_error_message text, aconfig={}, &block
186
- _print_message :error, text, aconfig, &block
200
+ # NOTE we are polluting global namespace
201
+ aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
202
+ ewin = _create_footer_window #*@layout
203
+ r = 0; c = 1;
204
+ case type
205
+ when :error
206
+ @color ||= 'red'
207
+ @bgcolor ||= 'black'
208
+ else
209
+ @color ||= :white
210
+ @bgcolor ||= :black
187
211
  end
188
- def _create_footer_window h = 2 , w = Ncurses.COLS, t = Ncurses.LINES-2, l = 0
189
- ewin = VER::Window.new(h, w , t, l)
212
+ color_pair = get_color($promptcolor, @color, @bgcolor)
213
+ ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
214
+ ewin.printstring r, c, text, color_pair
215
+ ewin.printstring r+1, c, "Press a key", color_pair
216
+ ewin.wrefresh
217
+ ewin.getchar
218
+ ewin.destroy
219
+ end
220
+ #
221
+ # Alternative to confirm dialog, if you want this look and feel, at last 2 lines of screen
222
+ # @param [String] text to prompt
223
+ # @return [true, false] 'y' is true, all else if false
224
+ def confirm_window text, aconfig={}, &block
225
+ case text
226
+ when RubyCurses::Variable # added 2011-09-20 incase variable passed
227
+ text = text.get_value
228
+ when Exception
229
+ text = text.to_s
190
230
  end
191
- # @param [:symbol] :error or :status kind of message
192
- # @private
193
- def _print_message type, text, aconfig={}, &block
194
- case text
195
- when RubyCurses::Variable # added 2011-09-20 incase variable passed
196
- text = text.get_value
197
- when Exception
198
- text = text.to_s
199
- end
200
- # NOTE we are polluting global namespace
201
- aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
202
- ewin = _create_footer_window #*@layout
203
- r = 0; c = 1;
204
- case type
205
- when :error
206
- @color ||= 'red'
207
- @bgcolor ||= 'black'
208
- else
209
- @color ||= :white
210
- @bgcolor ||= :black
211
- end
212
- color_pair = get_color($promptcolor, @color, @bgcolor)
213
- ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
214
- ewin.printstring r, c, text, color_pair
215
- ewin.printstring r+1, c, "Press a key", color_pair
216
- ewin.wrefresh
217
- ewin.getchar
231
+ ewin = _create_footer_window
232
+ r = 0; c = 1;
233
+ aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
234
+ @color ||= :white
235
+ @bgcolor ||= :black
236
+ color_pair = get_color($promptcolor, @color, @bgcolor)
237
+ ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
238
+ ewin.printstring r, c, text, color_pair
239
+ ewin.printstring r+1, c, "[y/n]", color_pair
240
+ ewin.wrefresh
241
+ #retval = false
242
+ retval = :NO # consistent with confirm
243
+ begin
244
+ ch = ewin.getchar
245
+ retval = :YES if ch.chr == 'y'
246
+ ensure
218
247
  ewin.destroy
219
248
  end
220
- #
221
- # Alternative to confirm dialog, if you want this look and feel, at last 2 lines of screen
222
- # @param [String] text to prompt
223
- # @return [true, false] 'y' is true, all else if false
224
- def confirm_window text, aconfig={}, &block
225
- case text
226
- when RubyCurses::Variable # added 2011-09-20 incase variable passed
227
- text = text.get_value
228
- when Exception
229
- text = text.to_s
230
- end
231
- ewin = _create_footer_window
232
- r = 0; c = 1;
233
- aconfig.each_pair { |k,v| instance_variable_set("@#{k}",v) }
234
- @color ||= :white
235
- @bgcolor ||= :black
236
- color_pair = get_color($promptcolor, @color, @bgcolor)
237
- ewin.bkgd(Ncurses.COLOR_PAIR(color_pair));
238
- ewin.printstring r, c, text, color_pair
239
- ewin.printstring r+1, c, "[y/n]", color_pair
240
- ewin.wrefresh
241
- #retval = false
242
- retval = :NO # consistent with confirm
249
+ retval
250
+ end
251
+ # class created to display multiple messages without asking for user to hit a key
252
+ # returns a window to which one can keep calling printstring with 0 or 1 as row.
253
+ # destroy when finished.
254
+ # Also, one can pause if one wants, or linger.
255
+ # This is meant to be a replacement for the message_immediate and message_raw
256
+ # I was trying out in App.rb. 2011-10-1 1:27 AM
257
+ # Testing from test2.rb
258
+ # TODO: add option of putting progress_bar
259
+ class StatusWindow
260
+ attr_reader :h, :w, :top, :left # height, width, top row, left col of window
261
+ attr_reader :win
262
+ attr_accessor :color_pair
263
+ def initialize config={}, &block
264
+ @color_pair = config[:color_pair]
265
+ @row_offset = config[:row_offset] || 0
266
+ @col_offset = config[:col_offset] || 0
267
+ create_window *config[:layout]
268
+ end
269
+ def create_window h = 2 , w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0
270
+ return @win if @win
271
+ @win = VER::Window.new(h, w , t, l)
272
+ @h = h ; @w = w; @top = t ; @left = l
273
+ @color_pair ||= get_color($promptcolor, 'white','black')
274
+ @win.bkgd(Ncurses.COLOR_PAIR(@color_pair));
275
+ @win
276
+ end
277
+ # creates a color pair based on given bg and fg colors as strings
278
+ #def set_colors bgcolor, fgcolor='white'
279
+ #@color_pair = get_color($datacolor, 'white','black')
280
+ #end
281
+ # prints a string on given row (0 or 1)
282
+ def printstring r, c, text, color_pair=@color_pair
283
+ create_window unless @win
284
+ show unless @visible
285
+ r = @h-1 if r > @h-1
286
+ #@win.printstring r, c, ' '*@w, @color_pair
287
+ # FIXME this padding overwrites the border and the offset means next line wiped
288
+ # However, now it may now totally clear a long line.
289
+ @win.printstring r+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, text], color_pair
290
+ @win.wrefresh
291
+ end
292
+ # print given strings from first first column onwards
293
+ def print *textarray
294
+ create_window unless @win
295
+ show unless @visible
296
+ c = 1
297
+ textarray.each_with_index { |s, i|
298
+ @win.printstring i+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, s], @color_pair
299
+ }
300
+ @win.wrefresh
301
+ end
302
+ def pause; @win.getchar; end
303
+ # pauses with the message, but doesn't ask the user to press a key.
304
+ # If he does, the key should be used by underlying window.
305
+ # Do not call destroy if you call linger, it does the destroy.
306
+ def linger caller_window=nil
243
307
  begin
244
- ch = ewin.getchar
245
- retval = :YES if ch.chr == 'y'
308
+ if caller_window
309
+ ch = @win.getchar
310
+ caller_window.ungetch(ch) # will this be available to underlying window XXX i think not !!
311
+ else
312
+ sleep 1
313
+ end
246
314
  ensure
247
- ewin.destroy
315
+ destroy
248
316
  end
249
- retval
250
317
  end
251
- # class created to display multiple messages without asking for user to hit a key
252
- # returns a window to which one can keep calling printstring with 0 or 1 as row.
253
- # destroy when finished.
254
- # Also, one can pause if one wants, or linger.
255
- # This is meant to be a replacement for the message_immediate and message_raw
256
- # I was trying out in App.rb. 2011-10-1 1:27 AM
257
- # Testing from test2.rb
258
- # TODO: add option of putting progress_bar
259
- class StatusWindow
260
- attr_reader :h, :w, :top, :left # height, width, top row, left col of window
261
- attr_reader :win
262
- attr_accessor :color_pair
263
- def initialize config={}, &block
264
- @color_pair = config[:color_pair]
265
- @row_offset = config[:row_offset] || 0
266
- @col_offset = config[:col_offset] || 0
267
- create_window *config[:layout]
268
- end
269
- def create_window h = 2 , w = Ncurses.COLS-0, t = Ncurses.LINES-2, l = 0
270
- return @win if @win
271
- @win = VER::Window.new(h, w , t, l)
272
- @h = h ; @w = w; @top = t ; @left = l
273
- @color_pair ||= get_color($promptcolor, 'white','black')
274
- @win.bkgd(Ncurses.COLOR_PAIR(@color_pair));
275
- @win
276
- end
277
- # creates a color pair based on given bg and fg colors as strings
278
- #def set_colors bgcolor, fgcolor='white'
279
- #@color_pair = get_color($datacolor, 'white','black')
280
- #end
281
- # prints a string on given row (0 or 1)
282
- def printstring r, c, text, color_pair=@color_pair
283
- create_window unless @win
284
- show unless @visible
285
- r = @h-1 if r > @h-1
286
- #@win.printstring r, c, ' '*@w, @color_pair
287
- # FIXME this padding overwrites the border and the offset means next line wiped
288
- # However, now it may now totally clear a long line.
289
- @win.printstring r+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, text], color_pair
290
- @win.wrefresh
291
- end
292
- # print given strings from first first column onwards
293
- def print *textarray
294
- create_window unless @win
295
- show unless @visible
296
- c = 1
297
- textarray.each_with_index { |s, i|
298
- @win.printstring i+@row_offset, c+@col_offset, "%-*s" % [@w-(@col_offset*2)-c, s], @color_pair
299
- }
300
- @win.wrefresh
301
- end
302
- def pause; @win.getchar; end
303
- # pauses with the message, but doesn't ask the user to press a key.
304
- # If he does, the key should be used by underlying window.
305
- # Do not call destroy if you call linger, it does the destroy.
306
- def linger caller_window=nil
307
- begin
308
- if caller_window
309
- ch = @win.getchar
310
- caller_window.ungetch(ch) # will this be available to underlying window XXX i think not !!
311
- else
312
- sleep 1
318
+ # caller must destroy after he's finished printing messages, unless
319
+ # user calls linger
320
+ def destroy; @win.destroy if @win; @win = nil; end
321
+ def hide
322
+ @win.hide
323
+ @visible = false
324
+ end
325
+ def show
326
+ @win.show unless @visible
327
+ @visible = true
328
+ end
329
+ end
330
+ # returns instance of a status_window for sending multiple
331
+ # statuses during some process
332
+ def status_window aconfig={}, &block
333
+ return StatusWindow.new aconfig
334
+ end
335
+ # this is a popup dialog box on which statuses can be printed as a process is taking place.
336
+ # I am reusing StatusWindow and so there's an issue since I've put a box, so in clearing
337
+ # the line, I might overwrite the box
338
+ def progress_dialog aconfig={}, &block
339
+ aconfig[:layout] = [10,60,10,20]
340
+ window = status_window aconfig
341
+ height = 10; width = 60
342
+ window.win.print_border_mb 1,2, height, width, $normalcolor, FFI::NCurses::A_REVERSE
343
+ return window
344
+ end
345
+ #
346
+ # Display a popup and return the seliected index from list
347
+ # Config includes row and col and title of window
348
+ # You may also pass bgcolor and color
349
+ # @since 1.4.1 2011-11-1
350
+ def popuplist list, config={}, &block
351
+ require 'rbcurse/rbasiclistbox'
352
+
353
+ max_visible_items = config[:max_visible_items]
354
+ row = config[:row] || 5
355
+ col = config[:col] || 5
356
+ relative_to = config[:relative_to]
357
+ if relative_to
358
+ layout = relative_to.form.window.layout
359
+ row += layout[:top]
360
+ col += layout[:left]
361
+ end
362
+ config.delete :relative_to
363
+ width = config[:width] || longest_in_list(list)+2 # borders take 2
364
+ height = config[:height]
365
+ height ||= [max_visible_items || 10+2, list.length+2].min
366
+ #layout(1+height, width+4, row, col)
367
+ layout = { :height => 0+height, :width => 0+width, :top => row, :left => col }
368
+ window = VER::Window.new(layout)
369
+ form = RubyCurses::Form.new window
370
+
371
+ listconfig = config[:listconfig] || {}
372
+ listconfig[:list] = list
373
+ listconfig[:width] = width
374
+ listconfig[:height] = height
375
+ listconfig[:selection_mode] = :single
376
+ listconfig.merge!(config)
377
+ listconfig.delete(:row);
378
+ listconfig.delete(:col);
379
+ # trying to pass populists block to listbox
380
+ lb = RubyCurses::BasicListbox.new form, listconfig, &block
381
+ #
382
+ # added next line so caller can configure listbox with
383
+ # events such as ENTER_ROW, LEAVE_ROW or LIST_SELECTION_EVENT or PRESS
384
+ # 2011-11-11
385
+ #yield lb if block_given? # No it won't work since this returns
386
+ window.bkgd(Ncurses.COLOR_PAIR($reversecolor));
387
+ window.wrefresh
388
+ Ncurses::Panel.update_panels
389
+ form.repaint
390
+ window.wrefresh
391
+ begin
392
+ while((ch = window.getchar()) != 999 )
393
+ case ch
394
+ when -1
395
+ next
396
+ when ?\C-q.getbyte(0)
397
+ break
398
+ else
399
+ lb.handle_key ch
400
+ form.repaint
401
+ if ch == 13 || ch == 10
402
+ return lb.current_index
403
+ # if multiple selection, then return list of selected_indices and don't catch 32
404
+ elsif ch == 32 # if single selection
405
+ return lb.current_index
313
406
  end
314
- ensure
315
- destroy
407
+ #yield ch if block_given?
316
408
  end
317
409
  end
318
- # caller must destroy after he's finished printing messages, unless
319
- # user calls linger
320
- def destroy; @win.destroy if @win; @win = nil; end
321
- def hide
322
- @win.hide
323
- @visible = false
324
- end
325
- def show
326
- @win.show unless @visible
327
- @visible = true
328
- end
329
- end
330
- # returns instance of a status_window for sending multiple
331
- # statuses during some process
332
- def status_window aconfig={}, &block
333
- return StatusWindow.new aconfig
334
- end
335
- # this is a popup dialog box on which statuses can be printed as a process is taking place.
336
- # I am reusing StatusWindow and so there's an issue since I've put a box, so in clearing
337
- # the line, I might overwrite the box
338
- def progress_dialog aconfig={}, &block
339
- aconfig[:layout] = [10,60,10,20]
340
- window = status_window aconfig
341
- height = 10; width = 60
342
- window.win.print_border_mb 1,2, height, width, $normalcolor, FFI::NCurses::A_REVERSE
343
- return window
410
+ ensure
411
+ window.destroy
344
412
  end
413
+ return nil
414
+ end
415
+ # returns length of longest
416
+ def longest_in_list list #:nodoc:
417
+ longest = list.inject(0) do |memo,word|
418
+ memo >= word.length ? memo : word.length
419
+ end
420
+ longest
421
+ end
345
422
  #
346
423
  =begin
347
424
  http://www.kammerl.de/ascii/AsciiSignature.php
@@ -358,7 +435,7 @@ http://www.kammerl.de/ascii/AsciiSignature.php
358
435
  | |
359
436
  |_|
360
437
  (_)
361
-
438
+
362
439
 
363
440
  _____ _ _____
364
441
  | __ \ | | / ____|
@@ -13,7 +13,6 @@ this is NOT how to code in rubyland. Please see this link, for how to code such
13
13
  http://blog.grayproductions.net/articles/all_about_struct
14
14
 
15
15
  =end
16
- require 'rubygems'
17
16
 
18
17
  # Event created when data modified in Field or TextEdit
19
18
  # 2008-12-24 17:54