rbcurse 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +40 -0
- data/Manifest.txt +4 -1
- data/README.txt +13 -12
- data/examples/rfe.rb +150 -34
- data/examples/rfe_renderer.rb +6 -0
- data/examples/sqlc.rb +419 -0
- data/examples/testd.db +0 -0
- data/examples/testtable.rb +0 -4
- data/examples/testtabp.rb +2 -0
- data/examples/testtodo.rb +73 -23
- data/examples/todocsv.csv +28 -0
- data/lib/rbcurse/defaultlistselectionmodel.rb +14 -0
- data/lib/rbcurse/listcellrenderer.rb +7 -0
- data/lib/rbcurse/listkeys.rb +7 -4
- data/lib/rbcurse/listscrollable.rb +144 -7
- data/lib/rbcurse/listselectable.rb +23 -2
- data/lib/rbcurse/rlistbox.rb +69 -15
- data/lib/rbcurse/rmessagebox.rb +14 -5
- data/lib/rbcurse/rtabbedpane.rb +64 -2
- data/lib/rbcurse/rtable.rb +223 -18
- data/lib/rbcurse/rtextarea.rb +34 -2
- data/lib/rbcurse/rtextview.rb +27 -4
- data/lib/rbcurse/rwidget.rb +9 -3
- data/lib/rbcurse/table/tablecellrenderer.rb +1 -0
- data/lib/rbcurse.rb +1 -1
- metadata +5 -3
- data/lib/rbcurse/rform.rb +0 -845
data/lib/rbcurse/rtable.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* Author: rkumar (arunachalesha)
|
5
5
|
|
6
6
|
|
7
|
-
TODO: NOTE:
|
7
|
+
TODO: NOTE:
|
8
8
|
A few higher level methods check for no data but lower level ones do not.
|
9
9
|
|
10
10
|
--------
|
@@ -78,7 +78,11 @@ module RubyCurses
|
|
78
78
|
@toprow = 0
|
79
79
|
@to_print_borders ||= 1
|
80
80
|
@show_grid ||= 1
|
81
|
+
@_first_column_print = 0 # intro for horiz scrolling 2009-02-14 16:20
|
82
|
+
@_last_column_print = 0 # 2009-02-16 23:57 so we don't tab further etc.
|
83
|
+
# table needs to know what columns are being printed.
|
81
84
|
@curpos = 0
|
85
|
+
@inter_column_spacing = 1
|
82
86
|
# @selected_color ||= 'yellow'
|
83
87
|
# @selected_bgcolor ||= 'black'
|
84
88
|
@table_changed = true
|
@@ -112,6 +116,7 @@ module RubyCurses
|
|
112
116
|
end
|
113
117
|
# added 2009-01-07 13:05 so new scrollable can use
|
114
118
|
def row_count
|
119
|
+
return 0 if @table_model.nil?
|
115
120
|
@table_model.row_count
|
116
121
|
end
|
117
122
|
# added 2009-01-07 13:05 so new scrollable can use
|
@@ -123,17 +128,24 @@ module RubyCurses
|
|
123
128
|
# Sets the data in models
|
124
129
|
# Should replace if these are created. TODO FIXME
|
125
130
|
def set_data data, colnames_array
|
131
|
+
# next 2 added in case set_data called again
|
132
|
+
@table_changed = true
|
133
|
+
@repaint_required = true
|
126
134
|
if data.is_a? Array
|
127
135
|
model = RubyCurses::DefaultTableModel.new data, colnames_array
|
128
136
|
table_model model
|
129
137
|
elsif data.is_a? RubyCurses::TableModel
|
130
138
|
table_model data
|
139
|
+
else
|
140
|
+
raise "set_data: don't know how to handle data: #{data.class.to_s}"
|
131
141
|
end
|
132
142
|
if colnames_array.is_a? Array
|
133
143
|
model = DefaultTableColumnModel.new colnames_array
|
134
144
|
table_column_model model
|
135
145
|
elsif colnames_array.is_a? RubyCurses::TableColumnModel
|
136
146
|
table_column_model colnames_array
|
147
|
+
else
|
148
|
+
raise "set_data: don't know how to handle column data: #{colnames_array.class.to_s}"
|
137
149
|
end
|
138
150
|
create_default_list_selection_model
|
139
151
|
create_table_header
|
@@ -164,8 +176,13 @@ module RubyCurses
|
|
164
176
|
@table_model.bind(:TABLE_MODEL_EVENT){|lde| table_data_changed(lde) }
|
165
177
|
end
|
166
178
|
end
|
167
|
-
|
168
|
-
|
179
|
+
# updated this so no param will return the tcm 2009-02-14 12:31
|
180
|
+
def table_column_model(*val)
|
181
|
+
if val.empty?
|
182
|
+
return @table_column_model
|
183
|
+
end
|
184
|
+
tcm = val[0]
|
185
|
+
raise "data error: table_column_model wrong class" if !tcm.is_a? RubyCurses::TableColumnModel
|
169
186
|
@table_column_model = tcm
|
170
187
|
@table_column_model.bind(:TABLE_COLUMN_MODEL_EVENT) {|e|
|
171
188
|
table_structure_changed e
|
@@ -175,8 +192,9 @@ module RubyCurses
|
|
175
192
|
#@table_header.column_model(tcm) unless @table_header.nil?
|
176
193
|
@table_header.table_column_model=(tcm) unless @table_header.nil?
|
177
194
|
end
|
178
|
-
#
|
195
|
+
# @deprecated, avoid usage
|
179
196
|
def get_table_column_model
|
197
|
+
$log.debug " DEPRECATED. Pls use table_column_model()"
|
180
198
|
@table_column_model
|
181
199
|
end
|
182
200
|
#
|
@@ -381,11 +399,16 @@ module RubyCurses
|
|
381
399
|
end
|
382
400
|
end
|
383
401
|
editor = get_default_cell_editor_for_class cls
|
402
|
+
#$log.debug "EDIT_CELL_AT:1 #{cls} #{editor.component.display_length} = #{@table_column_model.column(col).width}i maxlen #{editor.component.maxlen}"
|
384
403
|
editor.component.display_length = @table_column_model.column(col).width
|
385
|
-
|
404
|
+
# maxlen won't be nil ! This used to work earlier
|
405
|
+
#editor.component.maxlen = editor.component.display_length if editor.component.respond_to? :maxlen and editor.component.maxlen.nil? # 2009-01-18 00:59 XXX don't overwrite if user has set
|
406
|
+
if editor.component.respond_to? :maxlen
|
407
|
+
editor.component.maxlen = @table_column_model.column(col).edit_length || editor.component.display_length
|
408
|
+
end
|
386
409
|
#$log.debug "EDIT_CELL_AT: #{cls} #{editor.component.display_length} = #{@table_column_model.column(col).width}i maxlen #{editor.component.maxlen}"
|
387
410
|
end
|
388
|
-
|
411
|
+
#$log.debug " got an EDITOR #{editor} :: #{editor.component} "
|
389
412
|
# by now we should have something to edit with. We just need to prepare the widgey.
|
390
413
|
prepare_editor editor, row, col, value
|
391
414
|
|
@@ -395,6 +418,14 @@ module RubyCurses
|
|
395
418
|
row = r + (row - @toprow) +1 # @form.row , 1 added for header row!
|
396
419
|
col = c+get_column_offset()
|
397
420
|
editor.prepare_editor self, row, col, value
|
421
|
+
# added on 2009-02-16 23:49
|
422
|
+
# if data is longer than can be displayed then update editors disp len too
|
423
|
+
if (col+editor.component.display_length)>= @col+@width
|
424
|
+
editor.component.display_length = @width-1-col
|
425
|
+
$log.debug "DDDXXX #{editor.component.display_length} = @width-1-col"
|
426
|
+
else
|
427
|
+
$log.debug "EEE if (#{col+editor.component.display_length})> #{@col+@width}"
|
428
|
+
end
|
398
429
|
@cell_editor = editor
|
399
430
|
@repaint_required = true
|
400
431
|
set_form_col
|
@@ -452,6 +483,7 @@ module RubyCurses
|
|
452
483
|
# key handling
|
453
484
|
# make separate methods so callable programmatically
|
454
485
|
def handle_key(ch)
|
486
|
+
return :UNHANDLED if @table_model.nil?
|
455
487
|
@current_index ||= 0
|
456
488
|
@toprow ||= 0
|
457
489
|
h = scrollatrow()
|
@@ -494,6 +526,12 @@ module RubyCurses
|
|
494
526
|
when @KEY_GOTO_BOTTOM
|
495
527
|
editing_stopped if @is_editing # 2009-01-16 16:06
|
496
528
|
goto_bottom
|
529
|
+
when @KEY_SCROLL_RIGHT
|
530
|
+
editing_stopped if @is_editing # dts 2009-02-17 00:35
|
531
|
+
scroll_right
|
532
|
+
when @KEY_SCROLL_LEFT
|
533
|
+
editing_stopped if @is_editing # dts 2009-02-17 00:35
|
534
|
+
scroll_left
|
497
535
|
else
|
498
536
|
# there could be a case of editing here too!
|
499
537
|
ret = process_key ch, self
|
@@ -565,14 +603,16 @@ module RubyCurses
|
|
565
603
|
end
|
566
604
|
def next_column
|
567
605
|
v = @current_column+1
|
568
|
-
if v < @table_column_model.column_count
|
606
|
+
if v < @table_column_model.column_count and v <= @_last_column_print
|
569
607
|
$log.debug " if v < #{@table_column_model.column_count} "
|
570
608
|
current_column v
|
571
609
|
else
|
572
|
-
if @current_index < row_count()-1
|
610
|
+
if @current_index < row_count()-1
|
573
611
|
$log.debug " GOING TO NEXT ROW FROM NEXT COL : #{@current_index} : #{row_count}"
|
574
612
|
@current_column = 0
|
613
|
+
@current_column = @_first_column_print # added 2009-02-17 00:01
|
575
614
|
next_row
|
615
|
+
set_form_col
|
576
616
|
else
|
577
617
|
return :UNHANDLED
|
578
618
|
end
|
@@ -581,11 +621,14 @@ module RubyCurses
|
|
581
621
|
def previous_column
|
582
622
|
v = @current_column-1
|
583
623
|
# returning unhandled so focus can go to prev field auto
|
584
|
-
if v <
|
624
|
+
if v < @_first_column_print and @current_index <= 0
|
585
625
|
return :UNHANDLED
|
586
626
|
end
|
587
|
-
if v <
|
627
|
+
if v < @_first_column_print and @current_index > 0
|
588
628
|
@current_column = @table_column_model.column_count-1
|
629
|
+
@current_column = @_last_column_print # added 2009-02-17 00:01
|
630
|
+
$log.debug " XXXXXX prev col #{@current_column}, las #{@_last_column_print}, fi: #{@_first_column_print}"
|
631
|
+
set_form_col
|
589
632
|
previous_row
|
590
633
|
else
|
591
634
|
current_column @current_column-1
|
@@ -693,7 +736,7 @@ module RubyCurses
|
|
693
736
|
super
|
694
737
|
set_form_row
|
695
738
|
set_form_col # 2009-01-17 01:35
|
696
|
-
on_enter_cell focussed_row(), focussed_col()
|
739
|
+
on_enter_cell focussed_row(), focussed_col() unless focussed_row().nil? or focussed_col().nil?
|
697
740
|
end
|
698
741
|
def on_leave
|
699
742
|
super
|
@@ -713,6 +756,7 @@ module RubyCurses
|
|
713
756
|
end
|
714
757
|
# protected
|
715
758
|
def get_column_offset columnid=@current_column
|
759
|
+
return 0 if @table_column_model.nil?
|
716
760
|
return @table_column_model.column(columnid).column_offset || 0
|
717
761
|
end
|
718
762
|
|
@@ -720,11 +764,16 @@ module RubyCurses
|
|
720
764
|
def repaint
|
721
765
|
return unless @repaint_required
|
722
766
|
print_border @form.window if @to_print_borders == 1 # do this once only, unless everything changes
|
767
|
+
return if @table_model.nil? # added 2009-02-17 12:45
|
768
|
+
@_first_column_print ||= 0
|
723
769
|
cc = @table_model.column_count
|
724
770
|
rc = @table_model.row_count
|
771
|
+
inter_column_padding = " " * @inter_column_spacing
|
772
|
+
@_last_column_print = cc-1
|
725
773
|
tcm = @table_column_model
|
726
774
|
tm = @table_model
|
727
775
|
tr = @toprow
|
776
|
+
_column_scrolling = false
|
728
777
|
acolor = get_color $datacolor
|
729
778
|
h = scrollatrow()
|
730
779
|
r,c = rowcol
|
@@ -734,18 +783,19 @@ module RubyCurses
|
|
734
783
|
# TCM should give modelindex of col which is used to fetch data from TM
|
735
784
|
r += 1 # save for header
|
736
785
|
0.upto(h) do |hh|
|
737
|
-
crow = tr+hh
|
786
|
+
crow = tr+hh # crow is the row
|
738
787
|
if crow < rc
|
739
|
-
offset = 0
|
788
|
+
offset = 0 # offset of column
|
740
789
|
# 0.upto(cc-1) do |colix|
|
790
|
+
focussed = @current_index == crow ? true : false
|
791
|
+
selected = is_row_selected crow
|
741
792
|
# we loop through column_model and fetch data based on model index
|
742
793
|
# FIXED better to call table.get_value_at since we may now
|
743
794
|
# introduce a view - 2009-01-18 18:21
|
744
795
|
tcm.each_with_index do |acolumn, colix|
|
796
|
+
next if colix < @_first_column_print
|
745
797
|
#acolumn = tcm.column(colix)
|
746
798
|
#model_index = acolumn.model_index
|
747
|
-
focussed = @current_index == crow ? true : false
|
748
|
-
selected = is_row_selected crow
|
749
799
|
content = get_value_at(crow, colix) # tables
|
750
800
|
#renderer = get_default_cell_renderer_for_class content.class.to_s
|
751
801
|
renderer = get_cell_renderer(crow, colix)
|
@@ -753,9 +803,33 @@ module RubyCurses
|
|
753
803
|
renderer = get_default_cell_renderer_for_class(content.class.to_s) if renderer.nil?
|
754
804
|
renderer.display_length acolumn.width unless acolumn.nil?
|
755
805
|
end
|
756
|
-
width = renderer.display_length +
|
806
|
+
width = renderer.display_length + @inter_column_spacing
|
757
807
|
#renderer.repaint @form.window, r+hh, c+(colix*11), content, focussed, selected
|
758
808
|
acolumn.column_offset = offset
|
809
|
+
# trying to ensure that no overprinting
|
810
|
+
# $log.debug " c+offset+width > @col+@width #{c+offset+width} > #{@col}+#{@width}"
|
811
|
+
# $log.debug " #{c}+#{offset}+#{width} > @col+@width #{c+offset+width} > #{@col}+#{@width}"
|
812
|
+
if c+offset+width > @col+@width
|
813
|
+
_column_scrolling = true
|
814
|
+
@_last_column_print = colix
|
815
|
+
#$log.debug " TABLE BREAKING SINCE "
|
816
|
+
#$log.debug " if c+offset+width > @col+@width #{c+offset+width} > #{@col}+#{@width}"
|
817
|
+
#$log.debug " if #{c}+#{offset}+#{width} > @col+@width #{c+offset+width} > #{@col}+#{@width}"
|
818
|
+
# experimental to print subset of last
|
819
|
+
space_left = (@width-3)-(offset) # 3 due to boundaries
|
820
|
+
space_left = 0 if space_left < 0
|
821
|
+
if content.length > space_left
|
822
|
+
clen = space_left
|
823
|
+
renderer.display_length clen
|
824
|
+
else
|
825
|
+
clen = -1
|
826
|
+
renderer.display_length space_left # content.length
|
827
|
+
end
|
828
|
+
# print the inter cell padding just in case things mess up while scrolling
|
829
|
+
@form.window.mvprintw r+hh, c+offset-@inter_column_spacing, inter_column_padding
|
830
|
+
renderer.repaint @form.window, r+hh, c+offset, crow, content[0..clen], focussed, selected
|
831
|
+
break
|
832
|
+
end
|
759
833
|
# added crow on 2009-02-11 22:46
|
760
834
|
renderer.repaint @form.window, r+hh, c+(offset), crow, content, focussed, selected
|
761
835
|
offset += width
|
@@ -768,12 +842,33 @@ module RubyCurses
|
|
768
842
|
if @is_editing
|
769
843
|
@cell_editor.component.repaint unless @cell_editor.nil? or @cell_editor.component.form.nil?
|
770
844
|
end
|
845
|
+
_print_more_columns_marker _column_scrolling
|
846
|
+
_print_more_data_marker(rc-1 > tr + h)
|
847
|
+
$log.debug " _print_more_data_marker(#{rc} >= #{tr} + #{h})"
|
771
848
|
@table_changed = false
|
772
849
|
@repaint_required = false
|
773
850
|
end
|
774
851
|
def print_border g
|
775
852
|
return unless @table_changed
|
776
853
|
g.print_border @row, @col, @height, @width, $datacolor
|
854
|
+
return if @table_model.nil?
|
855
|
+
rc = @table_model.row_count
|
856
|
+
h = scrollatrow()
|
857
|
+
_print_more_data_marker (rc>h)
|
858
|
+
end
|
859
|
+
# private
|
860
|
+
def _print_more_data_marker tf
|
861
|
+
marker = tf ? Ncurses::ACS_CKBOARD : Ncurses::ACS_VLINE
|
862
|
+
@form.window.mvwaddch @row+@height-1, @col+@width-1, marker
|
863
|
+
marker = @toprow > 0 ? Ncurses::ACS_CKBOARD : Ncurses::ACS_VLINE
|
864
|
+
@form.window.mvwaddch @row+1, @col+@width-1, marker
|
865
|
+
end
|
866
|
+
def _print_more_columns_marker tf
|
867
|
+
marker = tf ? Ncurses::ACS_CKBOARD : Ncurses::ACS_HLINE
|
868
|
+
@form.window.mvwaddch @row+@height, @col+@width-2, marker
|
869
|
+
# show if columns to left or not
|
870
|
+
marker = @_first_column_print > 0 ? Ncurses::ACS_CKBOARD : Ncurses::ACS_HLINE
|
871
|
+
@form.window.mvwaddch @row+@height, @col+@_first_column_print+1, marker
|
777
872
|
end
|
778
873
|
def print_header
|
779
874
|
return unless @table_changed
|
@@ -782,12 +877,29 @@ module RubyCurses
|
|
782
877
|
tcm = @table_column_model ## could have been overridden, should we use this at all
|
783
878
|
offset = 0
|
784
879
|
header_model.each_with_index do |tc, colix|
|
880
|
+
next if colix < @_first_column_print # added for scrolling rt and left 2009-02-14 17:49
|
785
881
|
acolumn = tcm.column colix
|
786
882
|
renderer = tc.cell_renderer
|
787
883
|
renderer = @table_header.default_renderer if renderer.nil?
|
788
884
|
renderer.display_length acolumn.width unless acolumn.nil?
|
789
885
|
width = renderer.display_length + 1
|
790
886
|
content = tc.header_value
|
887
|
+
if c+offset+width > @col+@width
|
888
|
+
#$log.debug " TABLE: experimental code to NOT print if chance of exceeding table width"
|
889
|
+
# 2009-02-14 14:24 now printing, but truncating data for last column
|
890
|
+
space_left = (@width-3)-(offset)
|
891
|
+
space_left = 0 if space_left < 0
|
892
|
+
if content.length > space_left
|
893
|
+
clen = space_left
|
894
|
+
renderer.display_length clen
|
895
|
+
else
|
896
|
+
clen = -1
|
897
|
+
renderer.display_length space_left
|
898
|
+
end
|
899
|
+
#$log.debug " TABLE BREAKING SINCE sl: #{space_left},#{crow},#{colix}: #{clen} "
|
900
|
+
renderer.repaint @form.window, r, c+(offset), 0, content[0..clen], false, false
|
901
|
+
break
|
902
|
+
end
|
791
903
|
renderer.repaint @form.window, r, c+(offset),0, content, false, false
|
792
904
|
offset += width
|
793
905
|
end
|
@@ -837,6 +949,97 @@ module RubyCurses
|
|
837
949
|
set_focus_on(ix)
|
838
950
|
end
|
839
951
|
end
|
952
|
+
def scroll_right
|
953
|
+
cc = @table_model.column_count
|
954
|
+
if @_first_column_print < cc-1
|
955
|
+
@_first_column_print += 1
|
956
|
+
@current_column = @_first_column_print
|
957
|
+
set_form_col # FIXME not looking too good till key press
|
958
|
+
@repaint_required = true
|
959
|
+
@table_changed = true # so columns are modified
|
960
|
+
end
|
961
|
+
end
|
962
|
+
def scroll_left
|
963
|
+
if @_first_column_print > 0
|
964
|
+
@_first_column_print -= 1
|
965
|
+
@current_column = @_first_column_print
|
966
|
+
set_form_col
|
967
|
+
@repaint_required = true
|
968
|
+
@table_changed = true
|
969
|
+
end
|
970
|
+
end
|
971
|
+
##
|
972
|
+
# Makes an estimate of columns sizes, returning a hash, and storing it as @column_widths
|
973
|
+
# based on checking first 20 rows of data.
|
974
|
+
# This does not try to fit all columns into table, but gives best width, so you
|
975
|
+
# can scroll right to see other columns.
|
976
|
+
# @params - columns is columns returned by database
|
977
|
+
# using the command: @columns, *rows = @db.execute2(command)
|
978
|
+
# @param - datatypes is an array returned by following command to DB
|
979
|
+
# @datatypes = @content[0].types
|
980
|
+
def estimate_column_widths columns, datatypes
|
981
|
+
tablewidth = @width-3
|
982
|
+
colwidths = {}
|
983
|
+
min_column_width = (tablewidth/columns.length) -1
|
984
|
+
$log.debug("min: #{min_column_width}, #{tablewidth}")
|
985
|
+
0.upto(20) do |rowix|
|
986
|
+
break if rowix >= row_count
|
987
|
+
#@content.each_with_index do |row, cix|
|
988
|
+
# break if cix >= 20
|
989
|
+
@table_column_model.each_with_index do |acolumn, ix|
|
990
|
+
col = get_value_at(rowix, ix)
|
991
|
+
colwidths[ix] ||= 0
|
992
|
+
colwidths[ix] = [colwidths[ix], col.length].max
|
993
|
+
end
|
994
|
+
end
|
995
|
+
total = 0
|
996
|
+
colwidths.each_pair do |k,v|
|
997
|
+
name = columns[k.to_i]
|
998
|
+
colwidths[name] = v
|
999
|
+
total += v
|
1000
|
+
end
|
1001
|
+
colwidths["__TOTAL__"] = total
|
1002
|
+
column_widths = colwidths
|
1003
|
+
@max_data_widths = column_widths.dup
|
1004
|
+
|
1005
|
+
columns.each_with_index do | col, i|
|
1006
|
+
if datatypes[i].match(/(real|int)/) != nil
|
1007
|
+
wid = column_widths[i]
|
1008
|
+
# cw = [column_widths[i], [8,min_column_width].min].max
|
1009
|
+
$log.debug("XXX #{wid}. #{columns[i].length}")
|
1010
|
+
cw = [wid, columns[i].length].max
|
1011
|
+
$log.debug("int #{col} #{column_widths[i]}, #{cw}")
|
1012
|
+
elsif datatypes[i].match(/(date)/) != nil
|
1013
|
+
cw = [column_widths[i], [12,min_column_width].min].max
|
1014
|
+
#cw = [12,min_column_width].min
|
1015
|
+
$log.debug("date #{col} #{column_widths[i]}, #{cw}")
|
1016
|
+
else
|
1017
|
+
cw = [column_widths[i], min_column_width].max
|
1018
|
+
if column_widths[i] <= col.length and col.length <= min_column_width
|
1019
|
+
cw = col.length
|
1020
|
+
end
|
1021
|
+
$log.debug("else #{col} #{column_widths[i]}, #{col.length} #{cw}")
|
1022
|
+
end
|
1023
|
+
column_widths[i] = cw
|
1024
|
+
total += cw
|
1025
|
+
end
|
1026
|
+
column_widths["__TOTAL__"] = total
|
1027
|
+
$log.debug("Estimated col widths: #{column_widths.inspect}")
|
1028
|
+
@column_widths = column_widths
|
1029
|
+
return column_widths
|
1030
|
+
end
|
1031
|
+
##
|
1032
|
+
# convenience method
|
1033
|
+
# sets column widths given an array of ints
|
1034
|
+
# You may get such an array from estimate_column_widths
|
1035
|
+
def set_column_widths cw
|
1036
|
+
tcm = @table_column_model
|
1037
|
+
tcm.each_with_index do |col, ix|
|
1038
|
+
col.width cw[ix]
|
1039
|
+
end
|
1040
|
+
table_structure_changed(nil)
|
1041
|
+
end
|
1042
|
+
# ADD METHODS HERE
|
840
1043
|
end # class Table
|
841
1044
|
|
842
1045
|
## TC
|
@@ -863,6 +1066,7 @@ module RubyCurses
|
|
863
1066
|
## added column_offset on 2009-01-12 19:01
|
864
1067
|
attr_accessor :column_offset # where we've place this guy. in case we need to position cursor
|
865
1068
|
attr_accessor :cell_editor
|
1069
|
+
dsl_accessor :edit_length # corresponds to maxlen, if not set, col width will be useda 2009-02-16 21:55
|
866
1070
|
|
867
1071
|
|
868
1072
|
def initialize model_index, identifier, header_value, width, config={}, &block
|
@@ -1161,8 +1365,8 @@ module RubyCurses
|
|
1161
1365
|
|
1162
1366
|
##
|
1163
1367
|
# LSM
|
1164
|
-
#
|
1165
|
-
class
|
1368
|
+
# XXX UNUSED
|
1369
|
+
class OLDDefaultListSelectionModel
|
1166
1370
|
include RubyCurses::EventHandler
|
1167
1371
|
attr_accessor :selection_mode
|
1168
1372
|
attr_reader :anchor_selection_index
|
@@ -1172,6 +1376,7 @@ module RubyCurses
|
|
1172
1376
|
@anchor_selection_index = -1
|
1173
1377
|
@lead_selection_index = -1
|
1174
1378
|
@selection_mode = :MULTIPLE
|
1379
|
+
$log.debug " OLD VERSION OF LIST SELECTION MODEL IN rtable.rb"
|
1175
1380
|
end
|
1176
1381
|
|
1177
1382
|
def clear_selection
|
data/lib/rbcurse/rtextarea.rb
CHANGED
@@ -27,6 +27,8 @@ module RubyCurses
|
|
27
27
|
## a multiline text editing widget
|
28
28
|
# TODO - giving data to user - adding newlines, and withog adding.
|
29
29
|
# - respect newlines for incoming data
|
30
|
+
# we need a set_text method, passing nil or blank clears
|
31
|
+
# current way is not really good. remove_all sucks.
|
30
32
|
#
|
31
33
|
class TextArea < Widget
|
32
34
|
include ListScrollable
|
@@ -58,7 +60,7 @@ module RubyCurses
|
|
58
60
|
# this does result in a blank line if we insert after creating. That's required at
|
59
61
|
# present if we wish to only insert
|
60
62
|
if @list.empty?
|
61
|
-
|
63
|
+
# @list << "\r" # removed this on 2009-02-15 17:25 lets see how it goes
|
62
64
|
end
|
63
65
|
# @scrollatrow = @height-2
|
64
66
|
@content_rows = @list.length
|
@@ -66,6 +68,7 @@ module RubyCurses
|
|
66
68
|
# init_scrollable
|
67
69
|
print_borders
|
68
70
|
@maxlen ||= @width-2
|
71
|
+
install_keys
|
69
72
|
init_vars
|
70
73
|
end
|
71
74
|
def init_vars
|
@@ -90,6 +93,7 @@ module RubyCurses
|
|
90
93
|
end
|
91
94
|
def remove_all
|
92
95
|
@list = []
|
96
|
+
set_modified # added 2009-02-13 22:28 so repaints
|
93
97
|
end
|
94
98
|
##
|
95
99
|
# trying to wrap and insert
|
@@ -259,6 +263,18 @@ module RubyCurses
|
|
259
263
|
when ?\C-e
|
260
264
|
cursor_eol
|
261
265
|
#set_form_col @buffer.length
|
266
|
+
#when @KEY_ASK_FIND_FORWARD
|
267
|
+
# ask_search_forward
|
268
|
+
#when @KEY_ASK_FIND_BACKWARD
|
269
|
+
# ask_search_backward
|
270
|
+
when @KEY_ASK_FIND
|
271
|
+
ask_search
|
272
|
+
when @KEY_FIND_MORE
|
273
|
+
find_more
|
274
|
+
#when @KEY_FIND_NEXT
|
275
|
+
# find_next
|
276
|
+
#when @KEY_FIND_PREV
|
277
|
+
# find_prev
|
262
278
|
else
|
263
279
|
#$log.debug(" textarea ch #{ch}")
|
264
280
|
ret = putc ch
|
@@ -622,6 +638,7 @@ module RubyCurses
|
|
622
638
|
end
|
623
639
|
str
|
624
640
|
end
|
641
|
+
alias :get_text :to_s
|
625
642
|
## ---- for listscrollable ---- ##
|
626
643
|
def scrollatrow
|
627
644
|
@height-2
|
@@ -644,7 +661,7 @@ module RubyCurses
|
|
644
661
|
if crow < rc
|
645
662
|
#focussed = @current_index == crow ? true : false
|
646
663
|
#selected = is_row_selected crow
|
647
|
-
|
664
|
+
content = tm[crow].chomp rescue ""
|
648
665
|
content.gsub!(/\t/, ' ') # don't display tab
|
649
666
|
content.gsub!(/[^[:print:]]/, '') # don't display non print characters
|
650
667
|
if !content.nil?
|
@@ -659,6 +676,11 @@ module RubyCurses
|
|
659
676
|
#renderer.repaint @form.window, r+hh, c+(colix*11), content, focussed, selected
|
660
677
|
#renderer.repaint @form.window, r+hh, c, content, focussed, selected
|
661
678
|
@form.window.printstring r+hh, c, "%-*s" % [@width-2,content], acolor, @attr
|
679
|
+
if @search_found_ix == tr+hh
|
680
|
+
if !@find_offset.nil?
|
681
|
+
@form.window.mvchgat(y=r+hh, x=c+@find_offset, @find_offset1-@find_offset, Ncurses::A_NORMAL, $reversecolor, nil)
|
682
|
+
end
|
683
|
+
end
|
662
684
|
|
663
685
|
else
|
664
686
|
# clear rows
|
@@ -668,6 +690,16 @@ module RubyCurses
|
|
668
690
|
@table_changed = false
|
669
691
|
@repaint_required = false
|
670
692
|
end
|
693
|
+
def ask_search_forward
|
694
|
+
regex = get_string("Enter regex to search", 20, @last_regex||"")
|
695
|
+
ix = _find_next regex, @current_index
|
696
|
+
if ix.nil?
|
697
|
+
alert("No matching data for: #{regex}")
|
698
|
+
else
|
699
|
+
set_focus_on(ix)
|
700
|
+
set_form_col @find_offset
|
701
|
+
end
|
702
|
+
end
|
671
703
|
end # class textarea
|
672
704
|
##
|
673
705
|
end # modul
|
data/lib/rbcurse/rtextview.rb
CHANGED
@@ -59,6 +59,7 @@ module RubyCurses
|
|
59
59
|
#init_scrollable
|
60
60
|
print_borders
|
61
61
|
@maxlen ||= @width-2
|
62
|
+
install_keys
|
62
63
|
init_vars
|
63
64
|
end
|
64
65
|
def init_vars
|
@@ -174,13 +175,13 @@ module RubyCurses
|
|
174
175
|
@buffer = @list[@current_index]
|
175
176
|
end
|
176
177
|
return if @buffer.nil?
|
177
|
-
|
178
|
+
#$log.debug " before: curpos #{@curpos} blen: #{@buffer.length}"
|
178
179
|
if @curpos > @buffer.length
|
179
180
|
addcol((@buffer.length-@curpos)+1)
|
180
181
|
@curpos = @buffer.length
|
181
182
|
set_form_col
|
182
183
|
end
|
183
|
-
|
184
|
+
#$log.debug "TV after loop : curpos #{@curpos} blen: #{@buffer.length}"
|
184
185
|
#pre_key
|
185
186
|
case ch
|
186
187
|
when ?\C-n
|
@@ -216,6 +217,8 @@ module RubyCurses
|
|
216
217
|
when ?\C-e
|
217
218
|
# take care of data that exceeds maxlen by scrolling and placing cursor at end
|
218
219
|
blen = @buffer.rstrip.length
|
220
|
+
set_form_col blen
|
221
|
+
=begin
|
219
222
|
if blen < @maxlen
|
220
223
|
set_form_col blen
|
221
224
|
else
|
@@ -223,8 +226,14 @@ module RubyCurses
|
|
223
226
|
#wrong curpos wiill be reported
|
224
227
|
set_form_col @maxlen-1
|
225
228
|
end
|
229
|
+
=end
|
230
|
+
# search related added on 2009-02-15 21:36
|
231
|
+
when @KEY_ASK_FIND
|
232
|
+
ask_search
|
233
|
+
when @KEY_FIND_MORE
|
234
|
+
find_more
|
226
235
|
else
|
227
|
-
|
236
|
+
#$log.debug("TEXTVIEW XXX ch #{ch}")
|
228
237
|
return :UNHANDLED
|
229
238
|
end
|
230
239
|
#post_key
|
@@ -253,7 +262,13 @@ module RubyCurses
|
|
253
262
|
# set cursor on correct column tview
|
254
263
|
def set_form_col col=@curpos
|
255
264
|
@curpos = col
|
256
|
-
|
265
|
+
#@curpos = @maxlen if @curpos > @maxlen
|
266
|
+
if @curpos > @maxlen
|
267
|
+
@pcol = @curpos - @maxlen
|
268
|
+
@curpos = @maxlen - 1
|
269
|
+
else
|
270
|
+
@pcol = 0
|
271
|
+
end
|
257
272
|
@form.col = @orig_col + @col_offset + @curpos
|
258
273
|
@repaint_required = true
|
259
274
|
end
|
@@ -322,6 +337,14 @@ module RubyCurses
|
|
322
337
|
#renderer.repaint @form.window, r+hh, c+(colix*11), content, focussed, selected
|
323
338
|
#renderer.repaint @form.window, r+hh, c, content, focussed, selected
|
324
339
|
@form.window.printstring r+hh, c, "%-*s" % [@width-2,content], acolor, @attr
|
340
|
+
if @search_found_ix == tr+hh
|
341
|
+
if !@find_offset.nil?
|
342
|
+
# handle exceed bounds, and if scrolling
|
343
|
+
if @find_offset1 < maxlen+@pcol and @find_offset > @pcol
|
344
|
+
@form.window.mvchgat(y=r+hh, x=c+@find_offset-@pcol, @find_offset1-@find_offset, Ncurses::A_NORMAL, $reversecolor, nil)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
325
348
|
|
326
349
|
else
|
327
350
|
# clear rows
|
data/lib/rbcurse/rwidget.rb
CHANGED
@@ -143,9 +143,11 @@ module RubyCurses
|
|
143
143
|
return "btab"
|
144
144
|
when 481
|
145
145
|
return "M-S-tab"
|
146
|
+
when 393..402
|
147
|
+
return "M-F"+ (keycode-392).to_s
|
146
148
|
else
|
147
|
-
others=[?\M--,?\M-+,?\M-=,?\M-',?\M-",?\M-;,?\M-:,?\M-\,, ?\M-.,?\M-<,?\M
|
148
|
-
s_others=%w[M-- M-+ M-= M-' M-" M-; M-: M
|
149
|
+
others=[?\M--,?\M-+,?\M-=,?\M-',?\M-",?\M-;,?\M-:,?\M-\,, ?\M-.,?\M-<,?\M->,?\M-?,?\M-/]
|
150
|
+
s_others=%w[M-- M-+ M-= M-' M-" M-; M-: M-, M-. M-< M-> M-? M-/ ]
|
149
151
|
if others.include? keycode
|
150
152
|
index = others.index keycode
|
151
153
|
return s_others[index]
|
@@ -882,7 +884,7 @@ module RubyCurses
|
|
882
884
|
attr_reader :form
|
883
885
|
attr_reader :handler # event handler
|
884
886
|
attr_reader :type # datatype of field, currently only sets chars_allowed
|
885
|
-
attr_reader :curpos # cursor position in buffer current
|
887
|
+
#attr_reader :curpos # cursor position in buffer current, in WIDGET
|
886
888
|
attr_accessor :datatype # crrently set during set_buffer
|
887
889
|
attr_reader :original_value # value on entering field
|
888
890
|
|
@@ -997,6 +999,9 @@ module RubyCurses
|
|
997
999
|
end
|
998
1000
|
def repaint
|
999
1001
|
# $log.debug("FIELD: #{id}, #{zorder}, #{focusable}")
|
1002
|
+
#return if display_length <= 0 # added 2009-02-17 00:17 sometimes editor comp has 0 and that
|
1003
|
+
# becomes negative below, no because editing still happens
|
1004
|
+
@display_length = 1 if display_length == 0
|
1000
1005
|
printval = getvalue_for_paint().to_s # added 2009-01-06 23:27
|
1001
1006
|
printval = show()*printval.length unless @show.nil?
|
1002
1007
|
if !printval.nil?
|
@@ -1472,6 +1477,7 @@ module RubyCurses
|
|
1472
1477
|
@text_variable.nil? ? @text : @text_variable.get_value(@name)
|
1473
1478
|
end
|
1474
1479
|
|
1480
|
+
# ensure text has been passed or action
|
1475
1481
|
def getvalue_for_paint
|
1476
1482
|
ret = getvalue
|
1477
1483
|
@text_offset = @surround_chars[0].length
|
@@ -51,6 +51,7 @@ module RubyCurses
|
|
51
51
|
lablist << value
|
52
52
|
end
|
53
53
|
len = @display_length || value.length
|
54
|
+
$log.debug "less ZERO #{@display_length} || #{value.length}, ri: #{row_index}" if len < 0
|
54
55
|
acolor = get_color $datacolor
|
55
56
|
#acolor =get_color $datacolor, @color || @parent.color, @bgcolor || @parent.bgcolor #unless @parent.nil?
|
56
57
|
_attr = Ncurses::A_NORMAL
|
data/lib/rbcurse.rb
CHANGED