rbcurse 1.3.0 → 1.4.0
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 +33 -0
- data/README.markdown +7 -1
- data/TODO2.txt +21 -15
- data/VERSION +1 -1
- data/examples/abasiclist.rb +2 -2
- data/examples/alpmenu.rb +1 -1
- data/examples/app.rb +0 -1
- data/examples/appdirtree.rb +4 -2
- data/examples/appemail.rb +7 -3
- data/examples/appemaillb.rb +1 -1
- data/examples/appgcompose.rb +2 -2
- data/examples/appgmail.rb +1 -1
- data/examples/appmethods.rb +20 -2
- data/examples/atree.rb +9 -1
- data/examples/dbdemo.rb +460 -0
- data/examples/dirtree.rb +1 -1
- data/examples/menu1.rb +37 -5
- data/examples/multispl.rb +1 -1
- data/examples/rfe.rb +9 -2
- data/examples/splitp.rb +1 -1
- data/examples/sqlc.rb +6 -10
- data/examples/sqlm.rb +2 -20
- data/examples/sqlt.rb +408 -0
- data/examples/term2.rb +1 -1
- data/examples/test2.rb +169 -97
- data/examples/testapp.rb +1 -1
- data/examples/testapp2.rb +1 -1
- data/examples/testkeypress.rb +4 -2
- data/examples/testtable.rb +6 -0
- data/examples/testtpane.rb +35 -23
- data/examples/testvimsplit.rb +3 -2
- data/lib/rbcurse.rb +1 -1
- data/lib/rbcurse/action.rb +8 -0
- data/lib/rbcurse/app.rb +39 -23
- data/lib/rbcurse/extras/bottomline.rb +101 -13
- data/lib/rbcurse/extras/directorylist.rb +14 -5
- data/lib/rbcurse/extras/divider.rb +1 -1
- data/lib/rbcurse/extras/listselectable.rb +42 -8
- data/lib/rbcurse/extras/masterdetail.rb +2 -2
- data/lib/rbcurse/extras/scrollbar.rb +11 -2
- data/lib/rbcurse/extras/statusline.rb +56 -0
- data/lib/rbcurse/extras/stdscrwindow.rb +11 -0
- data/lib/rbcurse/extras/tabular.rb +2 -1
- data/lib/rbcurse/extras/tabularwidget.rb +60 -17
- data/lib/rbcurse/extras/viewer.rb +16 -4
- data/lib/rbcurse/keylabelprinter.rb +34 -4
- data/lib/rbcurse/listeditable.rb +5 -1
- data/lib/rbcurse/listkeys.rb +1 -1
- data/lib/rbcurse/listscrollable.rb +15 -8
- data/lib/rbcurse/rbasiclistbox.rb +44 -23
- data/lib/rbcurse/rcommandwindow.rb +8 -14
- data/lib/rbcurse/rdialogs.rb +187 -2
- data/lib/rbcurse/rlistbox.rb +38 -19
- data/lib/rbcurse/rmenu.rb +313 -93
- data/lib/rbcurse/rmessagebox.rb +3 -2
- data/lib/rbcurse/rmulticontainer.rb +5 -3
- data/lib/rbcurse/rmultisplit.rb +2 -11
- data/lib/rbcurse/rmultitextview.rb +4 -5
- data/lib/rbcurse/rtabbedpane.rb +223 -69
- data/lib/rbcurse/rtable.rb +6 -10
- data/lib/rbcurse/rtextarea.rb +57 -36
- data/lib/rbcurse/rtextview.rb +12 -15
- data/lib/rbcurse/rtree.rb +79 -22
- data/lib/rbcurse/rvimsplit.rb +16 -25
- data/lib/rbcurse/rwidget.rb +376 -523
- data/lib/rbcurse/tree/treecellrenderer.rb +24 -11
- data/lib/rbcurse/tree/treemodel.rb +1 -1
- data/lib/ver/window.rb +130 -66
- metadata +5 -3
- data/examples/term.rb +0 -48
data/lib/rbcurse/rtable.rb
CHANGED
@@ -18,6 +18,7 @@
|
|
18
18
|
currently it moves to next row. (examples/sqlc.rb) - DONE
|
19
19
|
|
20
20
|
* 2010-01-18 19:54 - BUFFERING related changes.
|
21
|
+
* 2011-09-30 - removed all buffer related stuff
|
21
22
|
--------
|
22
23
|
* Date: 2008-12-27 21:33
|
23
24
|
* License:
|
@@ -91,7 +92,6 @@ module RubyCurses
|
|
91
92
|
init_vars
|
92
93
|
install_list_keys
|
93
94
|
install_keys_bindings
|
94
|
-
## create_buffer needs to move to repaint. widget needs values to use when i creates buffer in repaint.
|
95
95
|
if _data && _columns
|
96
96
|
set_data _data, _columns
|
97
97
|
end
|
@@ -145,7 +145,8 @@ module RubyCurses
|
|
145
145
|
def focussed_row
|
146
146
|
#raise "No data in table" if row_count < 1
|
147
147
|
return nil if row_count < 1
|
148
|
-
@current_index
|
148
|
+
return @current_index if @current_index < row_count
|
149
|
+
@current_index = row_count-1
|
149
150
|
end
|
150
151
|
def focussed_col
|
151
152
|
return nil if row_count < 1
|
@@ -251,7 +252,7 @@ module RubyCurses
|
|
251
252
|
end
|
252
253
|
# @deprecated, avoid usage
|
253
254
|
def get_table_column_model
|
254
|
-
$log.
|
255
|
+
$log.warn " DEPRECATED. Pls use table_column_model()"
|
255
256
|
@table_column_model
|
256
257
|
end
|
257
258
|
#
|
@@ -338,6 +339,7 @@ module RubyCurses
|
|
338
339
|
#--- row and column methods of Table ---#
|
339
340
|
# must not give wrong results when columns switched!
|
340
341
|
def get_value_at row, col
|
342
|
+
return nil if row.nil? || col.nil? # 2011-09-29
|
341
343
|
model_index = @table_column_model.column(col).model_index
|
342
344
|
@table_model.get_value_at row, model_index
|
343
345
|
end
|
@@ -487,10 +489,6 @@ module RubyCurses
|
|
487
489
|
@repaint_required = true
|
488
490
|
# copied from rlistbox, so that editors write on parent's graphic, otherwise
|
489
491
|
# their screen updates get overwritten by parent. 2010-01-19 20:17
|
490
|
-
if @should_create_buffer
|
491
|
-
$log.debug "LB #{@name} overriding editors comp with GRAPHIC #{@graphic} "
|
492
|
-
editor.component.override_graphic(@graphic) # 2010-01-05 00:36 TRYING OUT BUFFERED
|
493
|
-
end
|
494
492
|
set_form_col
|
495
493
|
end
|
496
494
|
## Its too late to call components on_leave here
|
@@ -881,7 +879,6 @@ module RubyCurses
|
|
881
879
|
|
882
880
|
|
883
881
|
def repaint
|
884
|
-
safe_create_buffer # moved here 2010-02-19 09:53 RFED16
|
885
882
|
return unless @repaint_required
|
886
883
|
my_win = @form ? @form.window : @target_window
|
887
884
|
@graphic = my_win unless @graphic
|
@@ -980,8 +977,7 @@ module RubyCurses
|
|
980
977
|
$log.debug " _print_more_data_marker(#{rc} >= #{tr} + #{h})"
|
981
978
|
@table_changed = false
|
982
979
|
@repaint_required = false
|
983
|
-
|
984
|
-
buffer_to_window # RFED16 2010-02-19 09:55
|
980
|
+
#@buffer_modified = true # 2011-09-30 CLEANUP
|
985
981
|
end
|
986
982
|
# NEW to correct overflow
|
987
983
|
# 2009-10-05 21:34
|
data/lib/rbcurse/rtextarea.rb
CHANGED
@@ -37,14 +37,15 @@ module RubyCurses
|
|
37
37
|
# work correctly.
|
38
38
|
class TextArea < Widget
|
39
39
|
include ListScrollable
|
40
|
+
# NOTE: common editing functions moved to listeditable
|
40
41
|
include ListEditable
|
41
42
|
dsl_accessor :title
|
42
43
|
dsl_accessor :title_attrib # bold, reverse, normal
|
43
|
-
dsl_accessor :footer_attrib
|
44
|
-
dsl_accessor :list
|
45
|
-
dsl_accessor :maxlen
|
44
|
+
dsl_accessor :footer_attrib # bold, reverse, normal added 2009-12-26 18:25 was this missing or delib
|
45
|
+
dsl_accessor :list # the array of data to be sent by user
|
46
|
+
dsl_accessor :maxlen # max display length of a row/line
|
46
47
|
attr_reader :toprow
|
47
|
-
dsl_accessor :auto_scroll
|
48
|
+
dsl_accessor :auto_scroll # boolean, keeps view at end as data is inserted.
|
48
49
|
dsl_accessor :print_footer
|
49
50
|
dsl_accessor :editable # allow editing
|
50
51
|
dsl_accessor :suppress_borders # added 2010-02-12 12:21 values true or false
|
@@ -59,6 +60,8 @@ module RubyCurses
|
|
59
60
|
@list = []
|
60
61
|
@suppress_borders = false
|
61
62
|
@row_offset = @col_offset = 1 # for cursor display on first entry, so not positioned on border
|
63
|
+
@_events ||= []
|
64
|
+
@_events.push :CHANGE
|
62
65
|
super
|
63
66
|
@orig_col = @col
|
64
67
|
# this does result in a blank line if we insert after creating. That's required at
|
@@ -69,7 +72,6 @@ module RubyCurses
|
|
69
72
|
@content_rows = @list.length
|
70
73
|
@win = @graphic # 2009-12-26 14:54 BUFFERED replace form.window with graphic
|
71
74
|
# 2010-01-10 19:35 compute locally if not set
|
72
|
-
@_events.push :CHANGE
|
73
75
|
install_keys
|
74
76
|
init_vars
|
75
77
|
end
|
@@ -176,12 +178,15 @@ module RubyCurses
|
|
176
178
|
# private
|
177
179
|
def print_borders
|
178
180
|
window = @graphic # 2009-12-26 14:54 BUFFERED
|
179
|
-
|
181
|
+
@color_pair = get_color($datacolor) # 2011-09-28 V1.3.1
|
182
|
+
bordercolor = @border_color || @color_pair
|
183
|
+
borderatt = @border_attrib || Ncurses::A_NORMAL
|
184
|
+
#color = $datacolor
|
180
185
|
#window.print_border @row, @col, @height, @width, color
|
181
186
|
## NOTE: If it bombs in next line, either no form passed
|
182
187
|
##+ or you using this embedded and need to set should_create_buffer true when
|
183
188
|
##+ creating. See examples/testscrollta.rb.
|
184
|
-
window.print_border @row, @col, @height-1, @width,
|
189
|
+
window.print_border @row, @col, @height-1, @width, bordercolor, borderatt
|
185
190
|
print_title
|
186
191
|
=begin
|
187
192
|
hline = "+%s+" % [ "-"*(width-((1)*2)) ]
|
@@ -199,11 +204,12 @@ module RubyCurses
|
|
199
204
|
def print_title
|
200
205
|
# truncate title if longer than width
|
201
206
|
return unless @title
|
207
|
+
@color_pair ||= get_color($datacolor)
|
202
208
|
_title = @title
|
203
209
|
if @title.length > @width - 2
|
204
210
|
_title = @title[0..@width-2]
|
205
211
|
end
|
206
|
-
@graphic.printstring( @row, @col+(@width-_title.length)/2, _title,
|
212
|
+
@graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil?
|
207
213
|
end
|
208
214
|
# text_area print footer
|
209
215
|
def print_foot
|
@@ -212,28 +218,44 @@ module RubyCurses
|
|
212
218
|
#$log.debug " print_foot calling printstring with #{@row} + #{@height} -1, #{@col}+2"
|
213
219
|
# changed 2010-01-02 19:31 BUFFERED we were exceeding 1
|
214
220
|
#@graphic.printstring( @row + @height, @col+2, footer, $datacolor, @footer_attrib)
|
215
|
-
@graphic.printstring( @row + @height-1, @col+2, footer, $datacolor, @footer_attrib)
|
221
|
+
@graphic.printstring( @row + @height-1, @col+2, footer, @color_pair || $datacolor, @footer_attrib)
|
216
222
|
@repaint_footer_required = false
|
217
223
|
end
|
218
224
|
### FOR scrollable ###
|
219
225
|
def get_content
|
220
226
|
@list
|
221
227
|
end
|
228
|
+
#
|
229
|
+
# sets content of textarea. I don't know why this was not existing all this while
|
230
|
+
# Name to be consistent with textview. Okay, this does not wrap the words, we assume
|
231
|
+
# its short enough. FIXME. Avoid using currently till i firm this.
|
232
|
+
# NOTE: does not wrap, and does not trigger events
|
233
|
+
# Added on 2011-10-10
|
234
|
+
# @since 1.4.0
|
235
|
+
# @param [String, Array] String is an existing filename, Array is content to be replaced
|
236
|
+
def set_content lines
|
237
|
+
case lines
|
238
|
+
when String
|
239
|
+
if File.exists? lines
|
240
|
+
lines = File.open(lines,"r").readlines
|
241
|
+
else
|
242
|
+
raise "set_content String param should be a filename"
|
243
|
+
end
|
244
|
+
when Array
|
245
|
+
else
|
246
|
+
raise "Don't know how to handle data in set_content: #{lines.class} "
|
247
|
+
end
|
248
|
+
@list.replace lines
|
249
|
+
@repaint_required = true
|
250
|
+
end
|
222
251
|
def get_window
|
223
252
|
@graphic
|
224
253
|
end
|
225
254
|
### FOR scrollable ###
|
226
255
|
def repaint # textarea
|
227
|
-
if @screen_buffer.nil? and @should_create_buffer
|
228
|
-
safe_create_buffer
|
229
|
-
@screen_buffer.name = "Pad::TXTA_PAD_#{@name}"
|
230
|
-
$log.debug " textarea creates pad #{@screen_buffer} #{@name}"
|
231
|
-
end
|
232
|
-
|
233
256
|
#return unless @repaint_required # 2010-02-12 19:08 TRYING - won't let footer print if only col move
|
234
257
|
paint if @repaint_required
|
235
258
|
print_foot if @print_footer && !@suppress_borders && (@repaint_footer_required || @repaint_required)
|
236
|
-
buffer_to_window # 2010-02-12 14:54 RFED16
|
237
259
|
end
|
238
260
|
def getvalue
|
239
261
|
@list
|
@@ -243,8 +265,10 @@ module RubyCurses
|
|
243
265
|
return if @keys_mapped
|
244
266
|
bind_key(Ncurses::KEY_LEFT){ cursor_backward }
|
245
267
|
bind_key(Ncurses::KEY_RIGHT){ cursor_forward }
|
246
|
-
bind_key(Ncurses::KEY_UP){ up }
|
247
|
-
|
268
|
+
bind_key(Ncurses::KEY_UP){ ret = up; get_window.ungetch(KEY_BTAB) if ret == :NO_PREVIOUS_ROW }
|
269
|
+
# the next was irritating if user wanted to add a row ! 2011-10-10
|
270
|
+
#bind_key(Ncurses::KEY_DOWN){ ret = down ; get_window.ungetch(KEY_TAB) if ret == :NO_NEXT_ROW }
|
271
|
+
bind_key(Ncurses::KEY_DOWN){ ret = down ; }
|
248
272
|
bind_key(?\C-a){ cursor_bol }
|
249
273
|
bind_key(?\C-e){ cursor_eol }
|
250
274
|
bind_key(?\C-n) { scroll_forward }
|
@@ -293,10 +317,6 @@ module RubyCurses
|
|
293
317
|
case ch
|
294
318
|
when KEY_ENTER, 10, KEY_RETURN
|
295
319
|
insert_break
|
296
|
-
#when KEY_LEFT
|
297
|
-
#cursor_backward
|
298
|
-
#when KEY_RIGHT
|
299
|
-
#cursor_forward
|
300
320
|
when Ncurses.KEY_BACKSPACE, Ncurses.KEY_BSPACE
|
301
321
|
if @editable # checking here means that i can programmatically bypass!!
|
302
322
|
delete_prev_char
|
@@ -322,19 +342,9 @@ module RubyCurses
|
|
322
342
|
#@multiplier = (@multiplier == 0 ? 4 : @multiplier *= 4)
|
323
343
|
#return 0
|
324
344
|
when ?\C-_.getbyte(0) # changed from C-u so i can use C-u for multipliers
|
325
|
-
|
326
|
-
@undo_handler.undo
|
327
|
-
else
|
328
|
-
undo_delete
|
329
|
-
end
|
345
|
+
undo
|
330
346
|
when ?\C-r.getbyte(0) # redo if UndoHandler installed
|
331
|
-
|
332
|
-
@undo_handler.redo
|
333
|
-
#when ?\C-a.getbyte(0)
|
334
|
-
#cursor_bol
|
335
|
-
#when ?\C-e.getbyte(0)
|
336
|
-
#cursor_eol
|
337
|
-
|
347
|
+
text_redo # won't accept name redo
|
338
348
|
#when @KEY_ASK_FIND_FORWARD
|
339
349
|
# ask_search_forward
|
340
350
|
#when @KEY_ASK_FIND_BACKWARD
|
@@ -793,7 +803,7 @@ module RubyCurses
|
|
793
803
|
def cursor_eol
|
794
804
|
_maxlen = @maxlen || @width - @internal_width
|
795
805
|
$log.error "ERROR !!! bufferlen gt _maxlen #{@buffer.length}, #{_maxlen}" if @buffer.length > _maxlen
|
796
|
-
set_form_col current_line().chomp().length()-
|
806
|
+
set_form_col current_line().chomp().length() #-1 needs to be one ahead 2011-10-10 TRYING OUT XXX
|
797
807
|
end
|
798
808
|
def cursor_bol
|
799
809
|
set_form_col 0
|
@@ -838,6 +848,7 @@ module RubyCurses
|
|
838
848
|
$log.debug " #{@name} textarea repaint width is #{@width}, height is #{@height} , maxlen #{_maxlen}/ #{@maxlen}, #{@graphic.name} "
|
839
849
|
tm = get_content
|
840
850
|
tr = @toprow
|
851
|
+
raise "textarea height not specified" unless @height
|
841
852
|
acolor = get_color $datacolor
|
842
853
|
h = scrollatrow()
|
843
854
|
r,c = rowcol
|
@@ -881,7 +892,6 @@ module RubyCurses
|
|
881
892
|
@table_changed = false
|
882
893
|
@repaint_required = false
|
883
894
|
@repaint_footer_required = true # 2010-01-23 22:41
|
884
|
-
@buffer_modified = true # required by form to call buffer_to_screen
|
885
895
|
@repaint_all = false # added 2010-01-14 for redrawing everything
|
886
896
|
end
|
887
897
|
def ask_search_forward
|
@@ -894,6 +904,17 @@ module RubyCurses
|
|
894
904
|
set_form_col @find_offset
|
895
905
|
end
|
896
906
|
end
|
907
|
+
def undo
|
908
|
+
if @undo_handler
|
909
|
+
@undo_handler.undo
|
910
|
+
else
|
911
|
+
undo_delete
|
912
|
+
end
|
913
|
+
end
|
914
|
+
def text_redo
|
915
|
+
return unless @undo_handler
|
916
|
+
@undo_handler.redo
|
917
|
+
end
|
897
918
|
end # class textarea
|
898
919
|
##
|
899
920
|
end # modul
|
data/lib/rbcurse/rtextview.rb
CHANGED
@@ -180,7 +180,9 @@ module RubyCurses
|
|
180
180
|
|
181
181
|
$log.debug " #{@name} print_borders, #{@graphic.name} "
|
182
182
|
|
183
|
-
|
183
|
+
@color_pair = get_color($datacolor) # added 2011-09-28 as in rlistbox
|
184
|
+
# bordercolor = @border_color || $datacolor # changed 2011 dts
|
185
|
+
bordercolor = @border_color || @color_pair # 2011-09-28 V1.3.1
|
184
186
|
borderatt = @border_attrib || Ncurses::A_NORMAL
|
185
187
|
@graphic.print_border @row, @col, @height-1, @width, bordercolor, borderatt
|
186
188
|
print_title
|
@@ -188,20 +190,21 @@ module RubyCurses
|
|
188
190
|
def print_title #:nodoc:
|
189
191
|
return unless @title
|
190
192
|
raise "textview needs width" unless @width
|
191
|
-
@color_pair ||= get_color($datacolor) # should we not use this ??? XXX
|
193
|
+
@color_pair ||= get_color($datacolor) # should we not use this ??? XXX
|
192
194
|
#$log.debug " print_title #{@row}, #{@col}, #{@width} "
|
193
195
|
# check title.length and truncate if exceeds width
|
194
196
|
_title = @title
|
195
197
|
if @title.length > @width - 2
|
196
198
|
_title = @title[0..@width-2]
|
197
199
|
end
|
198
|
-
@graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless @title.nil?
|
200
|
+
# @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless @title.nil? # changed 2011 dts
|
201
|
+
@graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil?
|
199
202
|
end
|
200
203
|
def print_foot #:nodoc:
|
201
204
|
@footer_attrib ||= Ncurses::A_REVERSE
|
202
205
|
footer = "R: #{@current_index+1}, C: #{@curpos+@pcol}, #{@list.length} lines "
|
203
206
|
#$log.debug " print_foot calling printstring with #{@row} + #{@height} -1, #{@col}+2"
|
204
|
-
@graphic.printstring( @row + @height -1 , @col+2, footer, $datacolor, @footer_attrib)
|
207
|
+
@graphic.printstring( @row + @height -1 , @col+2, footer, @color_pair || $datacolor, @footer_attrib)
|
205
208
|
@repaint_footer_required = false # 2010-01-23 22:55
|
206
209
|
end
|
207
210
|
### FOR scrollable ###
|
@@ -213,17 +216,12 @@ module RubyCurses
|
|
213
216
|
end
|
214
217
|
|
215
218
|
def repaint # textview :nodoc:
|
216
|
-
|
217
|
-
safe_create_buffer
|
218
|
-
@screen_buffer.name = "Pad::TV_PAD_#{@name}" unless @screen_buffer.nil?
|
219
|
-
$log.debug " textview creates pad #{@screen_buffer} #{@name}"
|
220
|
-
end
|
219
|
+
$log.debug "TEXTVIEW repaint r c #{@row}, #{@col} "
|
221
220
|
|
222
221
|
#return unless @repaint_required # 2010-02-12 19:08 TRYING - won't let footer print for col move
|
223
222
|
paint if @repaint_required
|
224
223
|
# raise "TV 175 graphic nil " unless @graphic
|
225
224
|
print_foot if @print_footer && !@suppress_borders && @repaint_footer_required
|
226
|
-
buffer_to_window
|
227
225
|
end
|
228
226
|
def getvalue
|
229
227
|
@list
|
@@ -259,10 +257,12 @@ module RubyCurses
|
|
259
257
|
when KEY_UP, ?k.getbyte(0)
|
260
258
|
#select_prev_row
|
261
259
|
ret = up
|
260
|
+
get_window.ungetch(KEY_BTAB) if ret == :NO_PREVIOUS_ROW
|
262
261
|
check_curpos
|
263
262
|
|
264
263
|
when KEY_DOWN, ?j.getbyte(0)
|
265
264
|
ret = down
|
265
|
+
get_window.ungetch(KEY_TAB) if ret == :NO_NEXT_ROW
|
266
266
|
check_curpos
|
267
267
|
when KEY_LEFT, ?h.getbyte(0)
|
268
268
|
cursor_backward
|
@@ -320,10 +320,9 @@ module RubyCurses
|
|
320
320
|
begin
|
321
321
|
ret = process_key ch, self
|
322
322
|
rescue => err
|
323
|
-
$error_message = err
|
324
|
-
@form.window.print_error_message
|
325
323
|
$log.error " TEXTVIEW ERROR #{err} "
|
326
324
|
$log.debug(err.backtrace.join("\n"))
|
325
|
+
alert err.to_s
|
327
326
|
end
|
328
327
|
return :UNHANDLED if ret == :UNHANDLED
|
329
328
|
end
|
@@ -487,10 +486,8 @@ module RubyCurses
|
|
487
486
|
#@table_changed = false
|
488
487
|
@repaint_required = false
|
489
488
|
@repaint_footer_required = true
|
490
|
-
@buffer_modified = true # required by form to call buffer_to_screen
|
491
489
|
@repaint_all = false
|
492
490
|
|
493
|
-
# 2010-02-10 22:08 RFED16
|
494
491
|
end
|
495
492
|
# takes a block, this way anyone extending this class can just pass a block to do his job
|
496
493
|
# This modifies the string
|
@@ -499,7 +496,7 @@ module RubyCurses
|
|
499
496
|
content.chomp!
|
500
497
|
# trying out since gsub giving #<ArgumentError: invalid byte sequence in UTF-8> 2011-09-11
|
501
498
|
content = content.encode("ASCII-8BIT", :invalid => :replace, :undef => :replace, :replace => "?")
|
502
|
-
content.gsub!(
|
499
|
+
content.gsub!(/[\t\n\r]/, ' ') # don't display tab
|
503
500
|
content.gsub!(/[^[:print:]]/, '') # don't display non print characters
|
504
501
|
else
|
505
502
|
content
|
data/lib/rbcurse/rtree.rb
CHANGED
@@ -49,12 +49,14 @@ module RubyCurses
|
|
49
49
|
dsl_property :row_selected_symbol # 2009-01-12 12:01 changed from selector to selected
|
50
50
|
dsl_property :row_unselected_symbol # added 2009-01-12 12:00
|
51
51
|
dsl_property :left_margin
|
52
|
+
dsl_accessor :sanitization_required # 2011-10-6
|
52
53
|
#dsl_accessor :valign # popup related
|
53
54
|
#
|
54
55
|
# will pressing a single key move to first matching row. setting it to false lets us use vim keys
|
55
56
|
attr_accessor :one_key_selection # will pressing a single key move to first matching row
|
56
57
|
# index of row selected, relates to internal representation, not tree. @see selected_row
|
57
58
|
attr_reader :selected_index # index of row that is selected. this relates to representation
|
59
|
+
attr_reader :treemodel # returns treemodel for further actions 2011-10-2
|
58
60
|
|
59
61
|
def initialize form, config={}, &block
|
60
62
|
@focusable = true
|
@@ -75,12 +77,16 @@ module RubyCurses
|
|
75
77
|
super
|
76
78
|
#@selection_mode ||= :single # default is multiple, anything else given becomes single
|
77
79
|
@win = @graphic # 2010-01-04 12:36 BUFFERED replace form.window with graphic
|
80
|
+
@sanitization_required = true
|
81
|
+
@longest_line = 0
|
78
82
|
|
79
83
|
|
80
84
|
@win_left = 0
|
81
85
|
@win_top = 0
|
82
86
|
@_events.push(*[:ENTER_ROW, :LEAVE_ROW, :TREE_COLLAPSED_EVENT, :TREE_EXPANDED_EVENT, :TREE_SELECTION_EVENT, :TREE_WILL_COLLAPSE_EVENT, :TREE_WILL_EXPAND_EVENT])
|
83
87
|
|
88
|
+
|
89
|
+
bind(:PROPERTY_CHANGE){|e| @cell_renderer = nil } # will be recreated if anything changes 2011-09-28 V1.3.1
|
84
90
|
init_vars
|
85
91
|
|
86
92
|
#if !@list.selected_index.nil?
|
@@ -114,11 +120,15 @@ module RubyCurses
|
|
114
120
|
bind_key(KEY_RETURN) { toggle_expanded_state() }
|
115
121
|
bind_key(?o) { toggle_expanded_state() }
|
116
122
|
bind_key(?f){ ask_selection_for_char() }
|
117
|
-
bind_key(?\M-v){ @one_key_selection =
|
123
|
+
bind_key(?\M-v){ @one_key_selection = !@one_key_selection }
|
118
124
|
bind_key(KEY_DOWN){ next_row() }
|
119
125
|
bind_key(KEY_UP){ previous_row() }
|
120
126
|
bind_key(?O){ expand_children() }
|
121
127
|
bind_key(?X){ collapse_children() }
|
128
|
+
bind_key(?>, :scroll_right)
|
129
|
+
bind_key(?<, :scroll_left)
|
130
|
+
bind_key(?\M-l, :scroll_right)
|
131
|
+
bind_key(?\M-h, :scroll_left)
|
122
132
|
# TODO
|
123
133
|
bind_key(?x){ collapse_parent() }
|
124
134
|
bind_key(?p){ goto_parent() }
|
@@ -156,15 +166,28 @@ module RubyCurses
|
|
156
166
|
return @height - 3
|
157
167
|
end
|
158
168
|
end
|
159
|
-
#
|
160
|
-
|
169
|
+
#
|
170
|
+
# Sets the given node as root and returns treemodel.
|
171
|
+
# Returns root if no argument given.
|
172
|
+
# Now we return root if already set
|
173
|
+
# Made node nillable so we can return root.
|
174
|
+
#
|
175
|
+
# @raise ArgumentError if setting a root after its set
|
176
|
+
# or passing nil if its not been set.
|
177
|
+
def root node=nil, asks_allow_children=false, &block
|
178
|
+
if @treemodel
|
179
|
+
return @treemodel.root unless node
|
180
|
+
raise ArgumentError, "Root already set"
|
181
|
+
end
|
182
|
+
|
161
183
|
raise ArgumentError, "root: node cannot be nil" unless node
|
162
184
|
@treemodel = RubyCurses::DefaultTreeModel.new(node, asks_allow_children, &block)
|
163
185
|
end
|
186
|
+
|
164
187
|
# pass data to create this tree model
|
165
188
|
# used to be list
|
166
189
|
def data alist=nil
|
167
|
-
|
190
|
+
|
168
191
|
# if nothing passed, print an empty root, rather than crashing
|
169
192
|
alist = [] if alist.nil?
|
170
193
|
@data = alist # data given by user
|
@@ -253,7 +276,9 @@ module RubyCurses
|
|
253
276
|
window = @graphic # 2010-01-04 12:37 BUFFERED
|
254
277
|
startcol = @col
|
255
278
|
startrow = @row
|
256
|
-
|
279
|
+
@color_pair = get_color($datacolor)
|
280
|
+
# bordercolor = @border_color || $datacolor # changed 2011 dts
|
281
|
+
bordercolor = @border_color || @color_pair # 2011-09-28 V1.3.1
|
257
282
|
borderatt = @border_attrib || Ncurses::A_NORMAL
|
258
283
|
|
259
284
|
window.print_border startrow, startcol, height, width, bordercolor, borderatt
|
@@ -265,7 +290,7 @@ module RubyCurses
|
|
265
290
|
if @title.length > @width - 2
|
266
291
|
_title = @title[0..@width-2]
|
267
292
|
end
|
268
|
-
@color_pair
|
293
|
+
@color_pair ||= get_color($datacolor)
|
269
294
|
@graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil?
|
270
295
|
end
|
271
296
|
### START FOR scrollable ###
|
@@ -417,12 +442,11 @@ module RubyCurses
|
|
417
442
|
# a section of it.
|
418
443
|
# FIXME: tree may not be clearing till end see appdirtree after divider movement
|
419
444
|
def repaint
|
420
|
-
safe_create_buffer # 2010-01-04 12:36 BUFFERED moved here 2010-01-05 18:07
|
421
445
|
return unless @repaint_required
|
422
|
-
|
446
|
+
|
423
447
|
my_win = @form ? @form.window : @target_window
|
424
448
|
@graphic = my_win unless @graphic
|
425
|
-
|
449
|
+
|
426
450
|
raise " #{@name} neither form, nor target window given TV paint " unless my_win
|
427
451
|
raise " #{@name} NO GRAPHIC set as yet TV paint " unless @graphic
|
428
452
|
@win_left = my_win.left
|
@@ -431,6 +455,7 @@ module RubyCurses
|
|
431
455
|
$log.debug "rtree repaint #{@name} graphic #{@graphic}"
|
432
456
|
print_borders unless @suppress_borders # do this once only, unless everything changes
|
433
457
|
maxlen = @maxlen || @width-@internal_width
|
458
|
+
maxlen -= @left_margin # 2011-10-6
|
434
459
|
tm = _list()
|
435
460
|
select_default_values
|
436
461
|
rc = row_count
|
@@ -438,6 +463,7 @@ module RubyCurses
|
|
438
463
|
acolor = get_color $datacolor
|
439
464
|
h = scrollatrow()
|
440
465
|
r,c = rowcol
|
466
|
+
@longest_line = @width #maxlen
|
441
467
|
0.upto(h) do |hh|
|
442
468
|
crow = tr+hh
|
443
469
|
if crow < rc
|
@@ -452,24 +478,19 @@ module RubyCurses
|
|
452
478
|
node = content
|
453
479
|
object = content
|
454
480
|
leaf = node.is_leaf?
|
481
|
+
# content passed is rejected by treecellrenderer 2011-10-6
|
455
482
|
content = node.user_object.to_s # may need to trim or truncate
|
456
483
|
expanded = row_expanded? crow
|
457
484
|
elsif content.is_a? String
|
458
|
-
|
459
|
-
|
460
|
-
content.gsub!(/\t/, ' ') # don't display tab
|
461
|
-
content.gsub!(/[^[:print:]]/, '') # don't display non print characters
|
462
|
-
if !content.nil?
|
463
|
-
if content.length > maxlen # only show maxlen
|
464
|
-
content = content[@pcol..@pcol+maxlen-1]
|
465
|
-
else
|
466
|
-
content = content[@pcol..-1]
|
467
|
-
end
|
468
|
-
end
|
485
|
+
$log.warn "Removed this entire block since i don't think it was used XXX "
|
486
|
+
# this block does not set object XXX
|
469
487
|
else
|
470
488
|
raise "repaint what is the class #{content.class} "
|
471
489
|
content = content.to_s
|
472
490
|
end
|
491
|
+
# this is redundant since data is taken by renderer directly
|
492
|
+
#sanitize content if @sanitization_required
|
493
|
+
#truncate value
|
473
494
|
## set the selector symbol if requested
|
474
495
|
selection_symbol = ''
|
475
496
|
if @show_selector
|
@@ -480,10 +501,13 @@ module RubyCurses
|
|
480
501
|
end
|
481
502
|
@graphic.printstring r+hh, c, selection_symbol, acolor,@attr
|
482
503
|
end
|
504
|
+
|
483
505
|
renderer = cell_renderer()
|
484
506
|
renderer.display_length(@width-@internal_width-@left_margin) # just in case resizing of listbox
|
507
|
+
renderer.pcol = @pcol
|
485
508
|
#renderer.repaint @graphic, r+hh, c+@left_margin, crow, content, _focussed, selected
|
486
509
|
renderer.repaint @graphic, r+hh, c+@left_margin, crow, object, content, leaf, focus_type, selected, expanded
|
510
|
+
@longest_line = renderer.actual_length if renderer.actual_length > @longest_line
|
487
511
|
else
|
488
512
|
# clear rows
|
489
513
|
@graphic.printstring r+hh, c, " " * (@width-@internal_width), acolor,@attr
|
@@ -491,9 +515,8 @@ module RubyCurses
|
|
491
515
|
end
|
492
516
|
@table_changed = false
|
493
517
|
@repaint_required = false
|
494
|
-
@buffer_modified = true # required by form to call buffer_to_screen BUFFERED
|
495
|
-
buffer_to_window # RFED16 2010-02-17 23:16
|
496
518
|
end
|
519
|
+
|
497
520
|
def list_data_changed
|
498
521
|
if row_count == 0 # added on 2009-02-02 17:13 so cursor not hanging on last row which could be empty
|
499
522
|
init_vars
|
@@ -707,6 +730,39 @@ module RubyCurses
|
|
707
730
|
end
|
708
731
|
end
|
709
732
|
end
|
733
|
+
|
734
|
+
#
|
735
|
+
# To retrieve the node corresponding to a path specified as an array or string
|
736
|
+
# Do not mention the root.
|
737
|
+
# e.g. "ruby/1.9.2/io/console"
|
738
|
+
# or %w[ ruby 1.9.3 io console ]
|
739
|
+
# @since 1.4.0 2011-10-2
|
740
|
+
def get_node_for_path(user_path)
|
741
|
+
case user_path
|
742
|
+
when String
|
743
|
+
user_path = user_path.split "/"
|
744
|
+
when Array
|
745
|
+
else
|
746
|
+
raise ArgumentError, "Should be Array or String delimited with /"
|
747
|
+
end
|
748
|
+
$log.debug "TREE #{user_path} " if $log.debug?
|
749
|
+
root = @treemodel.root
|
750
|
+
found = nil
|
751
|
+
user_path.each { |e|
|
752
|
+
success = false
|
753
|
+
root.children.each { |c|
|
754
|
+
if c.user_object == e
|
755
|
+
found = c
|
756
|
+
success = true
|
757
|
+
root = c
|
758
|
+
break
|
759
|
+
end
|
760
|
+
}
|
761
|
+
return false unless success
|
762
|
+
|
763
|
+
}
|
764
|
+
return found
|
765
|
+
end
|
710
766
|
private
|
711
767
|
# please do not rely on this yet, name could change
|
712
768
|
def _structure_changed tf=true
|
@@ -716,6 +772,7 @@ module RubyCurses
|
|
716
772
|
end
|
717
773
|
|
718
774
|
|
775
|
+
|
719
776
|
# ADD HERE
|
720
777
|
end # class tree
|
721
778
|
|