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
@@ -46,10 +46,16 @@ module RubyCurses
46
46
  # painting the footer does slow down cursor painting slightly if one is moving cursor fast
47
47
  dsl_accessor :print_footer
48
48
  dsl_accessor :suppress_borders # added 2010-02-10 20:05 values true or false
49
+ attr_reader :current_index
50
+ dsl_accessor :border_attrib, :border_color #
51
+ dsl_accessor :sanitization_required
49
52
 
50
53
  def initialize form = nil, config={}, &block
51
54
  @focusable = true
52
55
  @editable = false
56
+ @sanitization_required = true
57
+ @suppress_borders = false
58
+ @row_offset = @col_offset = 1
53
59
  @row = 0
54
60
  @col = 0
55
61
  @show_focus = false # don't highlight row under focus
@@ -57,19 +63,20 @@ module RubyCurses
57
63
  super
58
64
  # ideally this should have been 2 to take care of borders, but that would break
59
65
  # too much stuff !
60
- @row_offset = @col_offset = 1
61
- #@scrollatrow = @height-2
62
- @content_rows = @list.length
63
66
  @win = @graphic
64
67
 
65
- install_keys
68
+ @_events.push :CHANGE # thru vieditable
69
+ @_events << :PRESS # new, in case we want to use this for lists and allow ENTER
70
+ @_events << :ENTER_ROW # new, should be there in listscrollable ??
71
+ install_keys # do something about this nonsense FIXME
66
72
  init_vars
73
+ map_keys
67
74
  end
68
- def init_vars
75
+ def init_vars #:nodoc:
69
76
  @curpos = @pcol = @toprow = @current_index = 0
70
77
  @repaint_all=true
78
+ @repaint_required=true
71
79
  ## 2010-02-10 20:20 RFED16 taking care if no border requested
72
- @suppress_borders ||= false
73
80
  @row_offset = @col_offset = 0 if @suppress_borders == true
74
81
  # added 2010-02-11 15:11 RFED16 so we don't need a form.
75
82
  @win_left = 0
@@ -79,20 +86,27 @@ module RubyCurses
79
86
  # currently i scroll right only if current line is longer than display width, i should use
80
87
  # longest line on screen.
81
88
  @longest_line = 0 # the longest line printed on this page, used to determine if scrolling shd work
89
+ @internal_width = 2
90
+ @internal_width = 0 if @suppress_borders
82
91
 
92
+ end
93
+ def map_keys
83
94
  bind_key([?g,?g]){ goto_start } # mapping double keys like vim
84
95
  bind_key([?',?']){ goto_last_position } # vim , goto last row position (not column)
85
96
  bind_key(?/, :ask_search)
86
97
  bind_key(?n, :find_more)
87
98
  bind_key([?\C-x, ?>], :scroll_right)
88
99
  bind_key([?\C-x, ?<], :scroll_left)
89
- bind_key(?r) { getstr("Enter a word") }
100
+ bind_key([?\C-x, ?\C-s], :saveas)
101
+ bind_key(?r) { getstr("Enter a word: ") }
90
102
  bind_key(?m, :disp_menu)
91
103
  end
92
104
  ##
93
105
  # send in a list
94
106
  # e.g. set_content File.open("README.txt","r").readlines
95
107
  # set wrap at time of passing :WRAP_NONE :WRAP_WORD
108
+ # XXX if we widen the textview later, as in a vimsplit that data
109
+ # will still be wrapped at this width !!
96
110
  def set_content list, wrap = :WRAP_NONE
97
111
  @wrap_policy = wrap
98
112
  if list.is_a? String
@@ -112,27 +126,36 @@ module RubyCurses
112
126
  else
113
127
  raise "set_content expects Array not #{list.class}"
114
128
  end
129
+ init_vars
130
+ end
131
+ def remove_all
132
+ @list = []
133
+ init_vars
134
+ @repaint_required = true
115
135
  end
116
136
  ## display this row on top
117
- def top_row(*val)
137
+ def top_row(*val) #:nodoc:
118
138
  if val.empty?
119
139
  @toprow
120
140
  else
121
141
  @toprow = val[0] || 0
122
- #@prow = val[0] || 0
123
142
  end
124
143
  @repaint_required = true
125
144
  end
126
145
  ## ---- for listscrollable ---- ##
127
- def scrollatrow
128
- @height - 3 # trying out 2009-10-31 15:22 XXX since we seem to be printing one more line
146
+ def scrollatrow #:nodoc:
147
+ if @suppress_borders
148
+ @height - 1 # should be 2 FIXME but erasing lower line. see appemail
149
+ else
150
+ @height - 3
151
+ end
129
152
  end
130
153
  def row_count
131
154
  @list.length
132
155
  end
133
156
  ##
134
157
  # returns row of first match of given regex (or nil if not found)
135
- def find_first_match regex
158
+ def find_first_match regex #:nodoc:
136
159
  @list.each_with_index do |row, ix|
137
160
  return ix if !row.match(regex).nil?
138
161
  end
@@ -140,31 +163,44 @@ module RubyCurses
140
163
  end
141
164
  ## returns the position where cursor was to be positioned by default
142
165
  # It may no longer work like that.
143
- def rowcol
166
+ def rowcol #:nodoc:
144
167
  return @row+@row_offset, @col+@col_offset
145
168
  end
146
- def wrap_text(txt, col = @maxlen)
147
- col ||= @width-2
148
- $log.debug "inside wrap text for :#{txt}"
169
+ def wrap_text(txt, col = @maxlen) #:nodoc:
170
+ col ||= @width-@internal_width
171
+ #$log.debug "inside wrap text for :#{txt}"
149
172
  txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
150
173
  "\\1\\3\n")
151
174
  end
152
175
  ## print a border
153
176
  ## Note that print_border clears the area too, so should be used sparingly.
154
- def print_borders
177
+ def print_borders #:nodoc:
178
+ raise "textview needs width" unless @width
179
+ raise "textview needs height" unless @height
180
+
155
181
  $log.debug " #{@name} print_borders, #{@graphic.name} "
156
- color = $datacolor
157
- @graphic.print_border @row, @col, @height-1, @width, color #, Ncurses::A_REVERSE
182
+
183
+ bordercolor = @border_color || $datacolor
184
+ borderatt = @border_attrib || Ncurses::A_NORMAL
185
+ @graphic.print_border @row, @col, @height-1, @width, bordercolor, borderatt
158
186
  print_title
159
187
  end
160
- def print_title
161
- $log.debug " print_title #{@row}, #{@col}, #{@width} "
162
- @graphic.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil?
188
+ def print_title #:nodoc:
189
+ return unless @title
190
+ raise "textview needs width" unless @width
191
+ @color_pair ||= get_color($datacolor) # should we not use this ??? XXX
192
+ #$log.debug " print_title #{@row}, #{@col}, #{@width} "
193
+ # check title.length and truncate if exceeds width
194
+ _title = @title
195
+ if @title.length > @width - 2
196
+ _title = @title[0..@width-2]
197
+ end
198
+ @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless @title.nil?
163
199
  end
164
- def print_foot
200
+ def print_foot #:nodoc:
165
201
  @footer_attrib ||= Ncurses::A_REVERSE
166
202
  footer = "R: #{@current_index+1}, C: #{@curpos+@pcol}, #{@list.length} lines "
167
- $log.debug " print_foot calling printstring with #{@row} + #{@height} -1, #{@col}+2"
203
+ #$log.debug " print_foot calling printstring with #{@row} + #{@height} -1, #{@col}+2"
168
204
  @graphic.printstring( @row + @height -1 , @col+2, footer, $datacolor, @footer_attrib)
169
205
  @repaint_footer_required = false # 2010-01-23 22:55
170
206
  end
@@ -172,11 +208,11 @@ module RubyCurses
172
208
  def get_content
173
209
  @list
174
210
  end
175
- def get_window
211
+ def get_window #:nodoc:
176
212
  @graphic
177
213
  end
178
- ### FOR scrollable ###
179
- def repaint # textview
214
+
215
+ def repaint # textview :nodoc:
180
216
  if @screen_buffer.nil?
181
217
  safe_create_buffer
182
218
  @screen_buffer.name = "Pad::TV_PAD_#{@name}" unless @screen_buffer.nil?
@@ -186,14 +222,18 @@ module RubyCurses
186
222
  #return unless @repaint_required # 2010-02-12 19:08 TRYING - won't let footer print for col move
187
223
  paint if @repaint_required
188
224
  # raise "TV 175 graphic nil " unless @graphic
189
- print_foot if @print_footer && @repaint_footer_required
225
+ print_foot if @print_footer && !@suppress_borders && @repaint_footer_required
190
226
  buffer_to_window
191
227
  end
192
228
  def getvalue
193
229
  @list
194
230
  end
231
+ def current_value
232
+ @list[@current_index]
233
+ end
195
234
  # textview
196
- def handle_key ch
235
+ def handle_key ch #:nodoc:
236
+ $log.debug " textview got ch #{ch} "
197
237
  @buffer = @list[@current_index]
198
238
  if @buffer.nil? and row_count == 0
199
239
  @list << "\r"
@@ -228,7 +268,7 @@ module RubyCurses
228
268
  cursor_backward
229
269
  when KEY_RIGHT, ?l.getbyte(0)
230
270
  cursor_forward
231
- when KEY_BACKSPACE, 127, 330
271
+ when KEY_BACKSPACE, KEY_BSPACE, KEY_DELETE
232
272
  cursor_backward
233
273
  when ?\C-a.getbyte(0) #, ?0.getbyte(0)
234
274
  # take care of data that exceeds maxlen by scrolling and placing cursor at start
@@ -246,6 +286,9 @@ module RubyCurses
246
286
  ask_search
247
287
  when @KEY_FIND_MORE
248
288
  find_more
289
+ when 10, 13, KEY_ENTER
290
+ #fire_handler :PRESS, self
291
+ fire_action_event
249
292
  when ?0.getbyte(0)..?9.getbyte(0)
250
293
  # FIXME the assumption here was that if numbers are being entered then a 0 is a number
251
294
  # not a beg-of-line command.
@@ -289,13 +332,13 @@ module RubyCurses
289
332
  return 0 # added 2010-01-12 22:17 else down arrow was going into next field
290
333
  end
291
334
  # newly added to check curpos when moving up or down
292
- def check_curpos
335
+ def check_curpos #:nodoc:
293
336
  @buffer = @list[@current_index]
294
337
  # if the cursor is ahead of data in this row then move it back
295
338
  if @pcol+@curpos > @buffer.length
296
339
  addcol((@pcol+@buffer.length-@curpos)+1)
297
340
  @curpos = @buffer.length
298
- maxlen = (@maxlen || @width-2)
341
+ maxlen = (@maxlen || @width-@internal_width)
299
342
 
300
343
  # even this row is gt maxlen, i.e., scrolled right
301
344
  if @curpos > maxlen
@@ -309,11 +352,11 @@ module RubyCurses
309
352
  end
310
353
  end
311
354
  # set cursor on correct column tview
312
- def set_form_col col1=@curpos
355
+ def set_form_col col1=@curpos #:nodoc:
313
356
  @cols_panned ||= 0
314
357
  @pad_offset ||= 0 # added 2010-02-11 21:54 since padded widgets get an offset.
315
358
  @curpos = col1
316
- maxlen = @maxlen || @width-2
359
+ maxlen = @maxlen || @width-@internal_width
317
360
  #@curpos = maxlen if @curpos > maxlen
318
361
  if @curpos > maxlen
319
362
  @pcol = @curpos - maxlen
@@ -330,8 +373,8 @@ module RubyCurses
330
373
  setrowcol nil, col2
331
374
  @repaint_footer_required = true
332
375
  end
333
- def cursor_forward
334
- maxlen = @maxlen || @width-2
376
+ def cursor_forward #:nodoc:
377
+ maxlen = @maxlen || @width-@internal_width
335
378
  repeatm {
336
379
  if @curpos < @width and @curpos < maxlen-1 # else it will do out of box
337
380
  @curpos += 1
@@ -344,16 +387,16 @@ module RubyCurses
344
387
  #@repaint_required = true
345
388
  @repaint_footer_required = true # 2010-01-23 22:41
346
389
  end
347
- def addcol num
390
+ def addcol num #:nodoc:
348
391
  #@repaint_required = true
349
392
  @repaint_footer_required = true # 2010-01-23 22:41
350
393
  if @form
351
394
  @form.addcol num
352
395
  else
353
- @parent_component.form.addcol num
396
+ @parent_component.form && @parent_component.form.addcol(num)
354
397
  end
355
398
  end
356
- def addrowcol row,col
399
+ def addrowcol row,col #:nodoc:
357
400
  #@repaint_required = true
358
401
  @repaint_footer_required = true # 2010-01-23 22:41
359
402
  if @form
@@ -362,7 +405,7 @@ module RubyCurses
362
405
  @parent_component.form.addrowcol num
363
406
  end
364
407
  end
365
- def cursor_backward
408
+ def cursor_backward #:nodoc:
366
409
  repeatm {
367
410
  if @curpos > 0
368
411
  @curpos -= 1
@@ -376,10 +419,12 @@ module RubyCurses
376
419
  @repaint_footer_required = true # 2010-01-23 22:41
377
420
  end
378
421
  # gives offset of next line, does not move
379
- def next_line
422
+ # @deprecated
423
+ def next_line #:nodoc:
380
424
  @list[@current_index+1]
381
425
  end
382
- def do_relative_row num
426
+ # @deprecated
427
+ def do_relative_row num #:nodoc:
383
428
  yield @list[@current_index+num]
384
429
  end
385
430
 
@@ -387,8 +432,8 @@ module RubyCurses
387
432
  ##+ a window is resized, and destroyed, then this was never called again, so the
388
433
  ##+ border would not be seen in splitpane unless the width coincided exactly with
389
434
  ##+ what is calculated in divider_location.
390
- def paint
391
- # not sure where to put this, once for all or repeat 2010-02-11 15:06 RFED16
435
+ def paint #:nodoc:
436
+
392
437
  my_win = nil
393
438
  if @form
394
439
  my_win = @form.window
@@ -396,39 +441,34 @@ module RubyCurses
396
441
  my_win = @target_window
397
442
  end
398
443
  @graphic = my_win unless @graphic
399
- #$log.warn "neither form not target window given!!! TV paint 368" unless my_win
400
- #raise " #{@name} neither form, nor target window given TV paint " unless my_win
401
- #raise " #{@name} NO GRAPHIC set as yet TV paint " unless @graphic
402
444
  @win_left = my_win.left
403
445
  @win_top = my_win.top
404
446
 
405
447
  print_borders if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
406
448
  rc = row_count
407
- maxlen = @maxlen || @width-2
408
- $log.debug " #{@name} textview repaint width is #{@width}, height is #{@height} , maxlen #{maxlen}/ #{@maxlen}, #{@graphic.name} roff #{@row_offset} coff #{@col_offset}"
449
+ maxlen = @maxlen || @width-@internal_width
450
+ #$log.debug " #{@name} textview repaint width is #{@width}, height is #{@height} , maxlen #{maxlen}/ #{@maxlen}, #{@graphic.name} roff #{@row_offset} coff #{@col_offset}"
409
451
  tm = get_content
410
452
  tr = @toprow
411
453
  acolor = get_color $datacolor
412
454
  h = scrollatrow()
413
455
  r,c = rowcol
414
- @longest_line = @width #maxlen
456
+ @longest_line = @width-@internal_width #maxlen
415
457
  0.upto(h) do |hh|
416
458
  crow = tr+hh
417
459
  if crow < rc
418
460
  #focussed = @current_index == crow ? true : false
419
461
  #selected = is_row_selected crow
420
- content = tm[crow].chomp
421
- content.gsub!(/\t/, ' ') # don't display tab
422
- content.gsub!(/[^[:print:]]/, '') # don't display non print characters
423
- if !content.nil?
424
- if content.length > maxlen # only show maxlen
425
- @longest_line = content.length if content.length > @longest_line
426
- content = content[@pcol..@pcol+maxlen-1]
427
- else
428
- content = content[@pcol..-1]
429
- end
430
- end
431
- @graphic.printstring r+hh, c, "%-*s" % [@width-2,content], acolor, @attr
462
+ content = tm[crow]
463
+ # next call modified string. you may wanna dup the string.
464
+ # rlistbox does
465
+ # scrolling fails if you do not dup, since content gets truncated
466
+ content = content.dup
467
+ sanitize content if @sanitization_required
468
+ truncate content
469
+ @graphic.printstring r+hh, c, "%-*s" % [@width-@internal_width,content], acolor, @attr
470
+
471
+ # highlighting search results.
432
472
  if @search_found_ix == tr+hh
433
473
  if !@find_offset.nil?
434
474
  # handle exceed bounds, and if scrolling
@@ -440,24 +480,53 @@ module RubyCurses
440
480
 
441
481
  else
442
482
  # clear rows
443
- @graphic.printstring r+hh, c, " " * (@width-2), acolor,@attr
483
+ @graphic.printstring r+hh, c, " " * (@width-@internal_width), acolor,@attr
444
484
  end
445
485
  end
446
- show_caret_func
447
- @table_changed = false
486
+ #show_caret_func
487
+ #@table_changed = false
448
488
  @repaint_required = false
449
- @repaint_footer_required = true # 2010-01-23 22:41
489
+ @repaint_footer_required = true
450
490
  @buffer_modified = true # required by form to call buffer_to_screen
451
- @repaint_all = false # added 2010-01-08 18:56 for redrawing everything
491
+ @repaint_all = false
452
492
 
453
493
  # 2010-02-10 22:08 RFED16
454
494
  end
495
+ # takes a block, this way anyone extending this class can just pass a block to do his job
496
+ # This modifies the string
497
+ def sanitize content #:nodoc:
498
+ if content.is_a? String
499
+ content.chomp!
500
+ content.gsub!(/\t/, ' ') # don't display tab
501
+ content.gsub!(/[^[:print:]]/, '') # don't display non print characters
502
+ else
503
+ content
504
+ end
505
+ end
506
+ # returns only the visible portion of string taking into account display length
507
+ # and horizontal scrolling. MODIFIES STRING
508
+ def truncate content #:nodoc:
509
+ _maxlen = @maxlen || @width-@internal_width
510
+ _maxlen = @width-@internal_width if _maxlen > @width-@internal_width # take care of decrease in width
511
+ if !content.nil?
512
+ if content.length > _maxlen # only show maxlen
513
+ @longest_line = content.length if content.length > @longest_line
514
+ #content = content[@pcol..@pcol+maxlen-1]
515
+ content.replace(content[@pcol..@pcol+_maxlen-1] || "")
516
+ else
517
+ if @pcol > 0
518
+ content.replace(content[@pcol..-1] || "")
519
+ end
520
+ end
521
+ end
522
+ content
523
+ end
455
524
  ## this is just a test of prompting user for a string
456
525
  #+ as an alternative to the dialog.
457
- def getstr prompt, maxlen=10
526
+ def getstr prompt, maxlen=10 #:nodoc:
458
527
  tabc = Proc.new {|str| Dir.glob(str +"*") }
459
528
  config={}; config[:tab_completion] = tabc
460
- config[:default] = "defaulT"
529
+ config[:default] = "default"
461
530
  $log.debug " inside getstr before call "
462
531
  ret, str = rbgetstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config)
463
532
  $log.debug " rbgetstr returned #{ret} , #{str} "
@@ -465,7 +534,19 @@ module RubyCurses
465
534
  return str
466
535
  end
467
536
  # this is just a test of the simple "most" menu
468
- def disp_menu
537
+ # How can application add to this, or override
538
+ def disp_menu #:nodoc:
539
+ require 'rbcurse/extras/menutree'
540
+ # we need to put this into data-structure so that i can be manipulated by calling apps
541
+ # This should not be at the widget level, too many types of menus. It should be at the app
542
+ # level only if the user wants his app to use this kind of menu.
543
+
544
+ @menu = RubyCurses::MenuTree.new "Main", { s: :goto_start, r: :scroll_right, l: :scroll_left, m: :submenu }
545
+ @menu.submenu :m, "submenu", {s: :noignorecase, t: :goto_last_position, f: :next3 }
546
+ menu = PromptMenu.new self
547
+ menu.menu_tree @menu
548
+
549
+ =begin
469
550
  menu = PromptMenu.new self
470
551
  menu.add( menu.create_mitem( 's', "Goto start ", "Going to start", Proc.new { goto_start} ))
471
552
  menu.add(menu.create_mitem( 'r', "scroll right", "I have scrolled ", :scroll_right ))
@@ -478,6 +559,7 @@ module RubyCurses
478
559
  menu.add(item)
479
560
  # how do i know what's available. the application or window should know where to place
480
561
  #menu.display @form.window, 23, 1, $datacolor #, menu
562
+ =end
481
563
  menu.display @form.window, $error_message_row, $error_message_col, $datacolor #, menu
482
564
  end
483
565
  ##
@@ -488,6 +570,77 @@ module RubyCurses
488
570
  extend Object.const_get("#{includename}")
489
571
  send("#{requirename}_init") #if respond_to? "#{includename}_init"
490
572
  end
573
+ # on pressing ENTER we send user some info, the calling program
574
+ # would bind :PRESS
575
+ #--
576
+ # FIXME we can create this once and reuse
577
+ #++
578
+ def fire_action_event
579
+ require 'rbcurse/ractionevent'
580
+ aev = TextActionEvent.new self, :PRESS, current_value(), @current_index, @curpos
581
+ fire_handler :PRESS, aev
582
+ end
583
+ # called by listscrollable, used by scrollbar ENTER_ROW
584
+ def on_enter_row arow
585
+ fire_handler :ENTER_ROW, self
586
+ @repaint_required = true
587
+ end
588
+ # added 2010-09-30 18:48 so standard with other components, esp on enter
589
+ def on_enter
590
+ if @list.nil? || @list.size == 0
591
+ Ncurses.beep
592
+ return :UNHANDLED
593
+ end
594
+ on_enter_row @current_index
595
+ set_form_row
596
+ @repaint_required = true
597
+ super
598
+ true
599
+ end
600
+ def pipe_file
601
+ # TODO ask process name from user
602
+ output = pipe_output 'munpack', @list
603
+ if output && !output.empty?
604
+ set_content output
605
+ end
606
+ end
607
+ # returns array of lines after running command on string passed
608
+ # TODO: need to close pipe other's we'll have a process lying
609
+ # around forever.
610
+ def pipe_output (pipeto, str)
611
+ case str
612
+ when String
613
+ #str = str.split "\n"
614
+ # okay
615
+ when Array
616
+ str = str.join "\n"
617
+ end
618
+ #pipeto = '/usr/sbin/sendmail -t'
619
+ #pipeto = %q{mail -s "my title" rahul}
620
+ if pipeto != nil # i was taking pipeto from a hash, so checking
621
+ proc = IO.popen(pipeto, "w+")
622
+ proc.puts str
623
+ proc.close_write
624
+ proc.readlines
625
+ end
626
+ end
627
+ def saveas name=nil, config={}
628
+ unless name
629
+ name = @graphic.ask "File to save as: "
630
+ return if name.nil? || name == ""
631
+ end
632
+ exists = File.exists? name
633
+ if exists # need to prompt
634
+ return unless @graphic.agree("Overwrite existing file? ", true)
635
+ end
636
+ l = getvalue
637
+ File.open(name, "w"){ |f|
638
+ l.each { |line| f.puts line }
639
+ #l.each { |line| f.write line.gsub(/\r/,"\n") }
640
+ }
641
+ @graphic.say "#{name} written."
642
+ end
643
+
491
644
 
492
645
  end # class textview
493
646