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
@@ -160,6 +160,7 @@ module RubyCurses
160
160
  @col_offset = 2; @row_offset = 1 # added 2010-01-10 22:54
161
161
  @recreate_buttons = true
162
162
  install_keys
163
+ @_events.push(*[:OPEN, :INSERT, :DELETE])
163
164
  end
164
165
  def install_keys
165
166
  @form.bind_key([?d, ?d]) { ix = highlighted_tab_index; repeatm { remove_tab(ix) } }
@@ -508,9 +509,9 @@ module RubyCurses
508
509
  # We need to convert it so the main form can use it
509
510
  if @current_tab != @form
510
511
  if ret == :UNHANDLED
511
- if ch == 9 #or ch == KEY_DOWN
512
+ if ch == KEY_TAB #or ch == KEY_DOWN
512
513
  ret = :NO_NEXT_FIELD
513
- elsif ch == 353 #or ch == KEY_UP # btab
514
+ elsif ch == KEY_BTAB #or ch == KEY_UP # btab
514
515
  ret = :NO_PREV_FIELD
515
516
  end
516
517
  end
@@ -75,7 +75,6 @@ module RubyCurses
75
75
  end
76
76
  end
77
77
  class TabbedWindow
78
- include DSL
79
78
  include EventHandler
80
79
  dsl_accessor :row, :col
81
80
  dsl_accessor :height, :width
@@ -66,28 +66,43 @@ module RubyCurses
66
66
  attr_reader :editing_col, :editing_row # r and col being edited, set to nil on leave
67
67
  attr_accessor :is_editing # boolean is only true if cell_editing_allowed
68
68
  dsl_accessor :editing_policy # :EDITING_AUTO
69
+ dsl_accessor :size_to_fit # boolean, will size columns upon set data just to fit
70
+ dsl_accessor :estimate_widths # boolean, will size columns upon set data
69
71
 
70
72
  # A table should only be editable if this is true regardless of other variables
71
73
  # In addition, A column to be editable must either have editable as nil or true
72
74
  dsl_accessor :cell_editing_allowed # 2009-01-16 22:55
73
75
 
74
76
  def initialize form = nil, config={}, &block
77
+ _data = config.delete :data
78
+ _columns = config.delete :columns
79
+ @_column_widths = config.delete :column_widths
80
+ # if user leaves width blank but gives us col widths, that means calculate total width
81
+ if @_column_widths && config[:width].nil?
82
+ total = @_column_widths.inject(0) { |total, w| total+=w }
83
+ @width = total+2
84
+ end
85
+ @suppress_borders = false
86
+ @col_offset = @row_offset = 1
87
+
75
88
  super
89
+ @_events.push(*[:TABLE_TRAVERSAL_EVENT,:TABLE_EDITING_EVENT])
76
90
  init_vars
77
91
  install_list_keys
78
92
  install_keys_bindings
79
93
  ## create_buffer needs to move to repaint. widget needs values to use when i creates buffer in repaint.
94
+ if _data && _columns
95
+ set_data _data, _columns
96
+ end
80
97
  end
81
98
 
82
99
  def init_vars
83
- @col_offset = @row_offset = 1
84
100
  @focusable= true
85
101
  @current_index = 0
86
102
  @current_column = 0
87
103
  @oldrow = @oldcol = 0
88
104
  @current_column_offset ||= 0 # added 2009-01-12 19:06 current_column's offset
89
105
  @toprow = 0
90
- @to_print_borders ||= 1
91
106
  @show_grid ||= 1
92
107
  @_first_column_print = 0 # intro for horiz scrolling 2009-02-14 16:20
93
108
  @_last_column_print = 0 # 2009-02-16 23:57 so we don't tab further etc.
@@ -96,6 +111,7 @@ module RubyCurses
96
111
  @inter_column_spacing = 1
97
112
  # @selected_color ||= 'yellow'
98
113
  # @selected_bgcolor ||= 'black'
114
+ @col_offset = @row_offset = 0 if @suppress_borders
99
115
  @table_changed = true
100
116
  @repaint_required = true
101
117
  end
@@ -105,8 +121,8 @@ module RubyCurses
105
121
  # alt-shift-tab prev column
106
122
  #bind_key(?\M-\C-i) { next_column }
107
123
  #bind_key(481) { previous_column }
108
- bind_key(9) { next_column }
109
- bind_key(353) { previous_column }
124
+ bind_key(KEY_TAB) { next_column }
125
+ bind_key(KEY_BTAB) { previous_column }
110
126
  bind_key(KEY_RIGHT) { next_column }
111
127
  bind_key(KEY_LEFT) { previous_column }
112
128
  bind_key(@KEY_ASK_FIND_FORWARD) { ask_search_forward }
@@ -142,8 +158,11 @@ module RubyCurses
142
158
  end
143
159
  # added 2009-01-07 13:05 so new scrollable can use
144
160
  def scrollatrow
145
- #@height -3
146
- @height -4 # we forgot to remove 1 from height in border.
161
+ if @suppress_borders # NOT TESTED XXX
162
+ @height - 2 # we forgot to remove 1 from height in border.
163
+ else
164
+ @height - 4 # we forgot to remove 1 from height in border.
165
+ end
147
166
  end
148
167
 
149
168
  #
@@ -153,6 +172,8 @@ module RubyCurses
153
172
  # next 2 added in case set_data called again
154
173
  @table_changed = true
155
174
  @repaint_required = true
175
+ data ||= [[]]
176
+ colnames_array ||= [""]
156
177
  if data.is_a? Array
157
178
  model = RubyCurses::DefaultTableModel.new data, colnames_array
158
179
  table_model model
@@ -171,6 +192,19 @@ module RubyCurses
171
192
  end
172
193
  create_default_list_selection_model
173
194
  create_table_header
195
+ # added 2010-09-09 19:57 if user provides col widths in hash, or size_to_fit
196
+ $log.debug " XXX @size_to_fit: #{@size_to_fit} "
197
+ if @_column_widths
198
+ $log.debug "XXXX inside set column widths "
199
+ set_column_widths @_column_widths
200
+ elsif @estimate_widths
201
+ $log.debug "XXXX inside estimate column widths "
202
+ cw = estimate_column_widths data
203
+ set_column_widths cw
204
+ elsif @size_to_fit
205
+ $log.debug " XXX inside @size_to_fit: #{@size_to_fit} "
206
+ size_columns_to_fit
207
+ end
174
208
  end
175
209
  def set_model tm, tcm=nil, lsm=nil
176
210
  table_model tm
@@ -632,7 +666,6 @@ module RubyCurses
632
666
  $multiplier = 0
633
667
  bounds_check
634
668
  end
635
- #def next_row
636
669
  # goto next row
637
670
  # added multipler 2010-05-12 20:51
638
671
  def next_row num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
@@ -640,7 +673,6 @@ module RubyCurses
640
673
  @oldrow = @current_index
641
674
  # don't go on if rc 2009-01-16 19:55 XXX
642
675
  if @current_index < rc
643
- #@current_index += 1
644
676
  @current_index += 1*num if @current_index < rc
645
677
  bounds_check
646
678
  end
@@ -746,7 +778,7 @@ module RubyCurses
746
778
  def bounds_check
747
779
  h = scrollatrow()
748
780
  rc = row_count
749
- #$log.debug " PRE CURR:#{@current_index}, TR: #{@toprow} RC: #{rc} H:#{h}"
781
+
750
782
  @current_index = 0 if @current_index < 0 # not lt 0
751
783
  @current_index = rc-1 if @current_index >= rc # not gt rowcount
752
784
  @toprow = rc-h-1 if rc > h and @toprow > rc - h - 1 # toprow shows full page if possible
@@ -757,14 +789,14 @@ module RubyCurses
757
789
  # curr has gone above table, move toprow up
758
790
  @toprow = @current_index
759
791
  end
760
- #$log.debug " POST CURR:#{@current_index}, TR: #{@toprow} RC: #{rc} H:#{h}"
792
+
761
793
  if @oldrow != @current_index
762
794
  #$log.debug "going to call on leave and on enter"
763
795
  on_leave_row @oldrow #if respond_to? :on_leave_row # to be defined by widget that has included this
764
796
  on_enter_row @current_index #if respond_to? :on_enter_row # to be defined by widget that has included this
765
797
  end
766
798
  set_form_row
767
- @oldrow = @current_index # added 2009-01-16 19:43 XXX
799
+ @oldrow = @current_index
768
800
  @repaint_required = true
769
801
  end
770
802
  def on_leave_row arow
@@ -858,7 +890,7 @@ module RubyCurses
858
890
  @win_left = my_win.left # unused remove TODO
859
891
  @win_top = my_win.top
860
892
 
861
- print_border @graphic if @to_print_borders == 1 # do this once only, unless everything changes
893
+ print_border @graphic if !@suppress_borders # do this once only, unless everything changes
862
894
  return if @table_model.nil? # added 2009-02-17 12:45
863
895
  @_first_column_print ||= 0
864
896
  cc = @table_model.column_count
@@ -1104,9 +1136,26 @@ module RubyCurses
1104
1136
  # using the command: @columns, *rows = @db.execute2(command)
1105
1137
  # @param - datatypes is an array returned by following command to DB
1106
1138
  # @datatypes = @content[0].types
1107
- def estimate_column_widths columns, datatypes
1139
+ def estimate_column_widths columns, datatypes=nil
1108
1140
  tablewidth = @width-3
1109
1141
  colwidths = {}
1142
+ unless datatypes
1143
+ datatypes = []
1144
+ row = columns[0]
1145
+ $log.debug " XXX row: #{row} "
1146
+
1147
+ row.each do |c|
1148
+ $log.debug " XXX c: #{c} "
1149
+ case c
1150
+ when Fixnum, Integer
1151
+ datatypes << "int"
1152
+ when Date, Time
1153
+ datatypes << "date"
1154
+ else
1155
+ datatypes << "varchar"
1156
+ end
1157
+ end
1158
+ end
1110
1159
  min_column_width = (tablewidth/columns.length) -1
1111
1160
  $log.debug("min: #{min_column_width}, #{tablewidth}")
1112
1161
  0.upto(20) do |rowix|
@@ -1116,7 +1165,7 @@ module RubyCurses
1116
1165
  @table_column_model.each_with_index do |acolumn, ix|
1117
1166
  col = get_value_at(rowix, ix)
1118
1167
  colwidths[ix] ||= 0
1119
- colwidths[ix] = [colwidths[ix], col.length].max
1168
+ colwidths[ix] = [colwidths[ix], col.to_s.length].max
1120
1169
  end
1121
1170
  end
1122
1171
  total = 0
@@ -1133,7 +1182,9 @@ module RubyCurses
1133
1182
  column_widths = colwidths
1134
1183
  @max_data_widths = column_widths.dup
1135
1184
 
1185
+ $log.debug "XXXX datatypes #{datatypes} "
1136
1186
  columns.each_with_index do | col, i|
1187
+ break if datatypes[i].nil?
1137
1188
  if datatypes[i].match(/(real|int)/) != nil
1138
1189
  wid = column_widths[i]
1139
1190
  # cw = [column_widths[i], [8,min_column_width].min].max
@@ -1164,6 +1215,7 @@ module RubyCurses
1164
1215
  # sets column widths given an array of ints
1165
1216
  # You may get such an array from estimate_column_widths
1166
1217
  def set_column_widths cw
1218
+ raise "Cannot call set_column_widths till table set" unless @table_column_model
1167
1219
  tcm = @table_column_model
1168
1220
  tcm.each_with_index do |col, ix|
1169
1221
  col.width cw[ix]
@@ -1182,6 +1234,7 @@ module RubyCurses
1182
1234
  def accomodate_delta delta
1183
1235
  tcm = @table_column_model
1184
1236
  cc = tcm.column_count
1237
+ return if cc == 0
1185
1238
  average = (delta/cc).ceil
1186
1239
  total = 0
1187
1240
  tcm.each do |col|
@@ -1245,6 +1298,7 @@ module RubyCurses
1245
1298
  @header_value = header_value
1246
1299
  @config={}
1247
1300
  instance_eval &block if block_given?
1301
+ @_events = [:PROPERTY_CHANGE]
1248
1302
  end
1249
1303
  def fire_property_change(text, oldval, newval)
1250
1304
  #$log.debug "TC: def fire_property_change(#{text}, #{oldval}, #{newval})"
@@ -1307,6 +1361,7 @@ module RubyCurses
1307
1361
  ##cols.each_with_index {|c, index| @columns << TableColumn.new(index, c, c, 10) }
1308
1362
  cols.each_with_index {|c, index| add_column(TableColumn.new(index, c, c, 10)) }
1309
1363
  @selected_columns = []
1364
+ @_events = [:TABLE_COLUMN_MODEL_EVENT, :PROPERTY_CHANGE]
1310
1365
  end
1311
1366
  def column ix
1312
1367
  raise "Invalid arg #{ix}" if ix < 0 or ix > (@columns.length() -1)
@@ -1419,6 +1474,7 @@ module RubyCurses
1419
1474
  def initialize data, colnames_array
1420
1475
  @data = data
1421
1476
  @column_identifiers = colnames_array
1477
+ @_events = [:TABLE_MODEL_EVENT, :PROPERTY_CHANGE]
1422
1478
  end
1423
1479
  def column_count
1424
1480
  # 2010-01-12 19:35 changed count to size since size is supported in 1.8.6 also
@@ -1469,11 +1525,30 @@ module RubyCurses
1469
1525
  return ret
1470
1526
  end
1471
1527
  def delete_at row
1472
- ret = @data.delete_at row
1528
+ if !$multiplier or $multiplier == 0
1529
+ @delete_buffer = @data.delete_at row
1530
+ else
1531
+ @delete_buffer = @data.slice!(row, $multiplier)
1532
+ end
1533
+ $multiplier = 0
1534
+ #ret = @data.delete_at row
1473
1535
  # create tablemodelevent and fire_table_changed for all listeners
1474
- tme = TableModelEvent.new(row, row,:ALL_COLUMNS, self, :DELETE)
1536
+ # we don;t pass buffer to event as in listeditable. how to undo later?
1537
+ tme = TableModelEvent.new(row, row+@delete_buffer.length,:ALL_COLUMNS, self, :DELETE)
1475
1538
  fire_handler :TABLE_MODEL_EVENT, tme
1476
- return ret
1539
+ return @delete_buffer
1540
+ end
1541
+ # a quick method to undo deletes onto given row. More like paste
1542
+ def undo where
1543
+ return unless @delete_buffer
1544
+ case @delete_buffer[0]
1545
+ when Array
1546
+ @delete_buffer.each do |r|
1547
+ insert where, r
1548
+ end
1549
+ else
1550
+ insert where, @delete_buffer
1551
+ end
1477
1552
  end
1478
1553
  ##
1479
1554
  # added 2009-01-17 21:36
@@ -1546,53 +1621,6 @@ module RubyCurses
1546
1621
  end # class DTC
1547
1622
 
1548
1623
  ##
1549
- # LSM
1550
- # XXX UNUSED
1551
- class OLDDefaultListSelectionModel
1552
- include RubyCurses::EventHandler
1553
- attr_accessor :selection_mode
1554
- attr_reader :anchor_selection_index
1555
- attr_reader :lead_selection_index
1556
- def initialize
1557
- @selected_indices=[]
1558
- @anchor_selection_index = -1
1559
- @lead_selection_index = -1
1560
- @selection_mode = :MULTIPLE
1561
- $log.debug " OLD VERSION OF LIST SELECTION MODEL IN rtable.rb"
1562
- end
1563
-
1564
- def clear_selection
1565
- @selected_indices=[]
1566
- end
1567
- def is_selected_index ix
1568
- @selected_indices.include? ix
1569
- end
1570
- def get_max_selection_index
1571
- @selected_indices[-1]
1572
- end
1573
- def get_min_selection_index
1574
- @selected_indices[0]
1575
- end
1576
- def get_selected_rows
1577
- @selected_indices
1578
- end
1579
- ## TODO should go in sorted, and no dupes
1580
- def add_selection_interval ix0, ix1
1581
- @anchor_selection_index = ix0
1582
- @lead_selection_index = ix1
1583
- ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i }
1584
- end
1585
- def remove_selection_interval ix0, ix1
1586
- @anchor_selection_index = ix0
1587
- @lead_selection_index = ix1
1588
- @selected_indices.delete_if {|x| x >= ix0 and x <= ix1}
1589
- end
1590
- def insert_index_interval ix0, len
1591
- @anchor_selection_index = ix0
1592
- @lead_selection_index = ix0+len
1593
- add_selection_interval @anchor_selection_index, @lead_selection_index
1594
- end
1595
- end # class DefaultListSelectionModel
1596
1624
  ##
1597
1625
  # Class that manages Table's Header
1598
1626
  # are we not taking events such as column added, removed ?
@@ -57,22 +57,19 @@ module RubyCurses
57
57
  @col = 0
58
58
  @curpos = 0
59
59
  @list = []
60
- super
60
+ @suppress_borders = false
61
61
  @row_offset = @col_offset = 1 # for cursor display on first entry, so not positioned on border
62
+ super
62
63
  @orig_col = @col
63
64
  # this does result in a blank line if we insert after creating. That's required at
64
65
  # present if we wish to only insert
65
66
  if @list.empty?
66
67
  # @list << "\r" # removed this on 2009-02-15 17:25 lets see how it goes
67
68
  end
68
- # @scrollatrow = @height-2
69
69
  @content_rows = @list.length
70
- #@win = @form.window
71
70
  @win = @graphic # 2009-12-26 14:54 BUFFERED replace form.window with graphic
72
- # init_scrollable
73
- #print_borders
74
71
  # 2010-01-10 19:35 compute locally if not set
75
- #@maxlen ||= @width-2
72
+ @_events.push :CHANGE
76
73
  install_keys
77
74
  init_vars
78
75
  end
@@ -82,18 +79,19 @@ module RubyCurses
82
79
  @toprow = @current_index = @pcol = 0
83
80
  @repaint_all=true
84
81
  ## 2010-02-12 12:20 RFED16 taking care if no border requested
85
- @suppress_borders ||= false
86
82
  @row_offset = @col_offset = 0 if @suppress_borders == true
87
83
  # added 2010-02-11 15:11 RFED16 so we don't need a form.
88
84
  @win_left = 0
89
85
  @win_top = 0
90
86
  @longest_line = 0
87
+ # if borders used, reduce 2 from width else 0
88
+ @internal_width = 2
89
+ @internal_width = 2 if @suppress_borders
91
90
  bind_key(?\M-w, :kill_ring_save)
92
91
  bind_key(?\C-y, :yank)
93
92
  bind_key(?\M-y, :yank_pop)
94
93
  bind_key(?\M-\C-w, :append_next_kill)
95
- bind_key(?\M-d, :delete_word)
96
- bind_key(?\M-f, :forward_word)
94
+ map_keys
97
95
  end
98
96
  def rowcol
99
97
  # $log.debug "textarea rowcol : #{@row+@row_offset+@winrow}, #{@col+@col_offset}"
@@ -107,7 +105,7 @@ module RubyCurses
107
105
  end
108
106
  # private
109
107
  def wrap_text(txt, col = @maxlen)
110
- col ||= @width - 2
108
+ col ||= @width - @internal_width
111
109
  #$log.debug "inside wrap text for :#{txt}"
112
110
  txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
113
111
  "\\1\\3\n")
@@ -115,7 +113,7 @@ module RubyCurses
115
113
  ##
116
114
  # trying to wrap and insert
117
115
  def insert off0, data
118
- _maxlen = @maxlen || @width - 2
116
+ _maxlen = @maxlen || @width - @internal_width
119
117
  if data.length > _maxlen
120
118
  data = wrap_text data
121
119
  # $log.debug "after wrap text done :#{data}"
@@ -135,7 +133,7 @@ module RubyCurses
135
133
  # Typically a line is sent in. We wrap and put a hard return at end.
136
134
  def << data
137
135
  # if width if nil, either set it, or add this to a container that sets it before calling this method
138
- _maxlen = @maxlen || @width - 2
136
+ _maxlen = @maxlen || @width - @internal_width
139
137
  if data.length > _maxlen
140
138
  #$log.debug "wrapped append for #{data}"
141
139
  data = wrap_text data
@@ -199,7 +197,13 @@ module RubyCurses
199
197
  end
200
198
  # private
201
199
  def print_title
202
- @graphic.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil?
200
+ # truncate title if longer than width
201
+ return unless @title
202
+ _title = @title
203
+ if @title.length > @width - 2
204
+ _title = @title[0..@width-2]
205
+ end
206
+ @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless @title.nil?
203
207
  end
204
208
  # text_area print footer
205
209
  def print_foot
@@ -228,14 +232,40 @@ module RubyCurses
228
232
 
229
233
  #return unless @repaint_required # 2010-02-12 19:08 TRYING - won't let footer print if only col move
230
234
  paint if @repaint_required
231
- print_foot if @print_footer && (@repaint_footer_required || @repaint_required)
235
+ print_foot if @print_footer && !@suppress_borders && (@repaint_footer_required || @repaint_required)
232
236
  buffer_to_window # 2010-02-12 14:54 RFED16
233
237
  end
234
238
  def getvalue
235
239
  @list
236
240
  end
241
+
242
+ def map_keys
243
+ return if @keys_mapped
244
+ bind_key(KEY_LEFT){ cursor_backward }
245
+ bind_key(KEY_RIGHT){ cursor_forward }
246
+ bind_key(KEY_UP){ up }
247
+ bind_key(KEY_DOWN){ down }
248
+ bind_key(?\C-a){ cursor_bol }
249
+ bind_key(?\C-e){ cursor_eol }
250
+ bind_key(?\C-n) { scroll_forward }
251
+ bind_key(?\C-p) { scroll_backward }
252
+ bind_key(?\C-[) { goto_start }
253
+ bind_key(?\C-]) { goto_end }
254
+
255
+ bind_key(KEY_BACKSPACE){ delete_prev_char if @editable }
256
+ bind_key(KEY_BSPACE){ delete_prev_char if @editable}
257
+ bind_key(?\M-d, :delete_word)
258
+ bind_key(?\M-f, :forward_word)
259
+
260
+ #bind_key(127){ delete_prev_char }
261
+ bind_key(330){ delete_curr_char if @editable }
262
+ #bind_key(?\C-k){ delete_eol }
263
+ #bind_key(?\C-_){ undo_delete_eol }
264
+ #bind_key(27){ set_buffer @original_value }
265
+ @keys_mapped = true
266
+ end
267
+
237
268
  # textarea
238
-
239
269
  def handle_key ch
240
270
  @current_key = ch # I need some funcs to know what key they were mapped to
241
271
  @buffer = @list[@current_index]
@@ -251,40 +281,27 @@ module RubyCurses
251
281
  # in sqlc on pressing Clear.
252
282
  # if buffer is nil and user wants to enter something -- added UNHANDLED
253
283
  return :UNHANDLED if @buffer.nil?
254
- $log.debug "TA: before: curpos #{@curpos} blen: #{@buffer.length}"
284
+ #$log.debug "TA: before: curpos #{@curpos} blen: #{@buffer.length}"
255
285
  # on any line if the cursor is ahead of buffer length, ensure its on last position
256
286
  # what if the buffer is somehow gt maxlen ??
257
287
  if @curpos > @buffer.length
258
288
  addcol(@buffer.length-@curpos)+1
259
289
  @curpos = @buffer.length
260
290
  end
261
- $log.debug "TA: after : curpos #{@curpos} blen: #{@buffer.length}, w: #{@width} max #{@maxlen}"
262
- #pre_key
291
+ #$log.debug "TA: after : curpos #{@curpos} blen: #{@buffer.length}, w: #{@width} max #{@maxlen}"
292
+
263
293
  case ch
264
- when ?\C-n.getbyte(0)
265
- scroll_forward
266
- when ?\C-p.getbyte(0)
267
- scroll_backward
268
- when ?\C-[.getbyte(0)
269
- goto_start #cursor_start of buffer
270
- when ?\C-].getbyte(0)
271
- goto_end # cursor_end of buffer
272
- when KEY_UP
273
- #select_prev_row
274
- ret = up
275
- when KEY_DOWN
276
- ret = down
277
- when KEY_ENTER, 10, 13
294
+ when KEY_ENTER, 10, KEY_RETURN
278
295
  insert_break
279
- when KEY_LEFT
280
- cursor_backward
281
- when KEY_RIGHT
282
- cursor_forward
283
- when KEY_BACKSPACE, 127
296
+ #when KEY_LEFT
297
+ #cursor_backward
298
+ #when KEY_RIGHT
299
+ #cursor_forward
300
+ when KEY_BACKSPACE, KEY_BSPACE
284
301
  if @editable # checking here means that i can programmatically bypass!!
285
302
  delete_prev_char
286
303
  end
287
- when 330, ?\C-d.getbyte(0) # delete char
304
+ when KEY_DELETE, ?\C-d.getbyte(0) # delete char
288
305
  if @editable
289
306
  delete_curr_char
290
307
  end
@@ -293,7 +310,7 @@ module RubyCurses
293
310
  # Earlier behavior was based on alpine which leaves a blank line
294
311
  if @editable
295
312
  #if @buffer == ""
296
- if @buffer.chomp == "" or @curpos == 0
313
+ if @buffer.chomp == "" || @curpos == 0
297
314
  delete_line
298
315
  else
299
316
  delete_eol
@@ -313,11 +330,11 @@ module RubyCurses
313
330
  when ?\C-r.getbyte(0) # redo if UndoHandler installed
314
331
  return unless @undo_handler
315
332
  @undo_handler.redo
316
- when ?\C-a.getbyte(0)
317
- cursor_bol
318
- when ?\C-e.getbyte(0)
319
- cursor_eol
320
- #set_form_col @buffer.length
333
+ #when ?\C-a.getbyte(0)
334
+ #cursor_bol
335
+ #when ?\C-e.getbyte(0)
336
+ #cursor_eol
337
+
321
338
  #when @KEY_ASK_FIND_FORWARD
322
339
  # ask_search_forward
323
340
  #when @KEY_ASK_FIND_BACKWARD
@@ -336,7 +353,7 @@ module RubyCurses
336
353
  if ret == :UNHANDLED
337
354
  # check for bindings, these cannot override above keys since placed at end
338
355
  ret = process_key ch, self
339
- $log.debug "TA process_key #{ch} got ret #{ret} in #{@name} "
356
+ #$log.debug "TA process_key #{ch} got ret #{ret} in #{@name} "
340
357
  return :UNHANDLED if ret == :UNHANDLED
341
358
  end
342
359
  end
@@ -491,7 +508,7 @@ module RubyCurses
491
508
  up
492
509
  return
493
510
  end
494
- _maxlen = @maxlen || @width - 2
511
+ _maxlen = @maxlen || @width - @internal_width
495
512
  space_left = _maxlen - prevlen
496
513
  # prev line is full exit
497
514
  return if space_left == 0
@@ -567,7 +584,7 @@ module RubyCurses
567
584
  up
568
585
  return
569
586
  end
570
- _maxlen = @maxlen || @width - 2
587
+ _maxlen = @maxlen || @width - @internal_width
571
588
  space_left = _maxlen - prev.length
572
589
  # BUG. carry full words up, or if no space then bring down last word of prev lien and join with first
573
590
  carry_up = words_in_length @buffer, space_left #@buffer[0..space_left] # XXX
@@ -619,14 +636,18 @@ module RubyCurses
619
636
  # I have modified it to push all words that are exceeding maxlen.
620
637
  # This was needed for if i push 10 chars to next line, and the last word is less then the line will
621
638
  # exceed. So i must push as many words as exceed length.
639
+ # 2010-09-07 22:31 this must not return nil, or previous will crash. This happens if no space in line.
622
640
  def push_last_word lineno=@current_index
623
- _maxlen = @maxlen || @width - 2
641
+ _maxlen = @maxlen || @width - @internal_width
624
642
  #lastspace = @buffer.rindex(" ")
625
643
  #lastspace = @list[lineno].rindex(/ \w/)
626
644
  line = @list[lineno]
627
645
  line = @list[lineno][0.._maxlen+1] if line.length > _maxlen
628
646
  lastspace = line.rindex(/ \w/)
629
647
  $log.debug " PUSH:2 #{lastspace},#{line},"
648
+ # fix to ensure something returned 2010-09-07 22:40
649
+ lastspace = _maxlen-1 unless lastspace # added 2010-09-07 22:29 XXXX
650
+
630
651
  if !lastspace.nil?
631
652
  lastchars = @list[lineno][lastspace+1..-1]
632
653
  @list[lineno] = @list[lineno][0..lastspace]
@@ -653,7 +674,7 @@ module RubyCurses
653
674
  # this attempts to recursively insert into a row, seeing that any stuff exceeding is pushed down further.
654
675
  # Yes, it should check for a para end and insert. Currently it could add to next para.
655
676
  def insert_wrap lineno, pos, lastchars
656
- _maxlen = @maxlen || @width - 2
677
+ _maxlen = @maxlen || @width - @internal_width
657
678
  @list[lineno].insert pos, lastchars
658
679
  len = @list[lineno].length
659
680
  if len > _maxlen
@@ -663,7 +684,7 @@ module RubyCurses
663
684
  ##
664
685
  # add one char. careful, i shoved a string in yesterday.
665
686
  def putch char
666
- _maxlen = @maxlen || @width - 2
687
+ _maxlen = @maxlen || @width - @internal_width
667
688
  @buffer ||= @list[@current_index]
668
689
  return -1 if !@editable #or @buffer.length >= _maxlen
669
690
  #if @chars_allowed != nil # remove useless functionality
@@ -715,7 +736,16 @@ module RubyCurses
715
736
 
716
737
  def putc c
717
738
  if c >= 32 and c <= 126
718
- ret = putch c.chr
739
+ begin
740
+ ret = putch c.chr
741
+ rescue => ex
742
+ # this does not prevent entry, it prevents updating
743
+ # often comes here if error in event block, not our fault
744
+ Ncurses.beep
745
+ $log.debug " ERROR IN PUTCH RTEXTAREA "
746
+ $log.debug( ex) if ex
747
+ $log.debug(ex.backtrace.join("\n")) if ex
748
+ end
719
749
  if ret == 0
720
750
  # addcol 1
721
751
  set_modified
@@ -735,7 +765,7 @@ module RubyCurses
735
765
  def move_chars_up
736
766
  oldprow = @current_index
737
767
  oldcurpos = @curpos
738
- _maxlen = @maxlen || @width - 2
768
+ _maxlen = @maxlen || @width - @internal_width
739
769
  space_left = _maxlen - @buffer.length
740
770
  can_move = [space_left, next_line.length].min
741
771
  carry_up = @list[@current_index+1].slice!(0, can_move)
@@ -761,7 +791,7 @@ module RubyCurses
761
791
  @form.modified = true if tf and !@form.nil?
762
792
  end
763
793
  def cursor_eol
764
- _maxlen = @maxlen || @width - 2
794
+ _maxlen = @maxlen || @width - @internal_width
765
795
  $log.error "ERROR !!! bufferlen gt _maxlen #{@buffer.length}, #{_maxlen}" if @buffer.length > _maxlen
766
796
  set_form_col current_line().chomp().length()-1
767
797
  end
@@ -787,7 +817,11 @@ module RubyCurses
787
817
  #alias :get_text :to_s
788
818
  ## ---- for listscrollable ---- ##
789
819
  def scrollatrow
790
- @height-3 # 2010-01-02 19:28 BUFFERED
820
+ if @suppress_borders
821
+ @height - 1
822
+ else
823
+ @height - 3
824
+ end
791
825
  end
792
826
  def row_count
793
827
  @list.size
@@ -800,7 +834,7 @@ module RubyCurses
800
834
  @win_top = my_win.top
801
835
  print_borders if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
802
836
  rc = row_count
803
- _maxlen = @maxlen || @width-2 # TODO fix in other branches remove ||=
837
+ _maxlen = @maxlen || @width-@internal_width # TODO fix in other branches remove ||=
804
838
  $log.debug " #{@name} textarea repaint width is #{@width}, height is #{@height} , maxlen #{_maxlen}/ #{@maxlen}, #{@graphic.name} "
805
839
  tm = get_content
806
840
  tr = @toprow
@@ -829,7 +863,7 @@ module RubyCurses
829
863
  #renderer = cell_renderer()
830
864
  #renderer.repaint @form.window, r+hh, c+(colix*11), content, focussed, selected
831
865
  #renderer.repaint @form.window, r+hh, c, content, focussed, selected
832
- @graphic.printstring r+hh, c, "%-*s" % [@width-2,content], acolor, @attr
866
+ @graphic.printstring r+hh, c, "%-*s" % [@width-@internal_width,content], acolor, @attr
833
867
  if @search_found_ix == tr+hh
834
868
  if !@find_offset.nil?
835
869
  @graphic.mvchgat(y=r+hh, x=c+@find_offset, @find_offset1-@find_offset, Ncurses::A_NORMAL, $reversecolor, nil)
@@ -839,7 +873,7 @@ module RubyCurses
839
873
  else
840
874
  # clear rows
841
875
  # TODO the spaces string can be stored once outside loop
842
- @graphic.printstring r+hh, c, " " * (@width-2), acolor,@attr
876
+ @graphic.printstring r+hh, c, " " * (@width-@internal_width), acolor,@attr
843
877
  end
844
878
  end
845
879
  show_caret_func