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
@@ -53,7 +53,6 @@ module RubyCurses
|
|
53
53
|
print_footer pf
|
54
54
|
footer_attrib fa
|
55
55
|
end
|
56
|
-
textview.set_content content #, :WRAP_WORD
|
57
56
|
|
58
57
|
t = textview
|
59
58
|
t.bind_key('<'){ f = t.form.window; c = f.left - 1; f.hide; f.mvwin(f.top, c); f.show;
|
@@ -69,25 +68,30 @@ module RubyCurses
|
|
69
68
|
f.reset_layout([f.height, f.width, c, f.left]); f.show;
|
70
69
|
}
|
71
70
|
# yielding textview so you may further configure or bind keys or events
|
71
|
+
begin
|
72
|
+
textview.set_content content #, :WRAP_WORD
|
72
73
|
yield textview if block_given? # tentative
|
73
74
|
v_form.repaint
|
74
75
|
v_window.wrefresh
|
75
76
|
Ncurses::Panel.update_panels
|
76
|
-
|
77
|
+
# allow closing using q and Ctrl-q in addition to any key specified
|
78
|
+
# user should not need to specify key, since that becomes inconsistent across usages
|
77
79
|
while((ch = v_window.getchar()) != ?\C-q.getbyte(0) )
|
78
|
-
break if ch == config[:close_key]
|
80
|
+
break if ch == config[:close_key] || ch == ?q.ord
|
79
81
|
# if you've asked for RETURN then i also check for 10 and 13
|
80
82
|
break if (ch == 10 || ch == 13) && config[:close_key] == KEY_RETURN
|
81
83
|
v_form.handle_key ch
|
82
84
|
v_form.repaint
|
83
85
|
end
|
86
|
+
rescue => err
|
87
|
+
alert err.to_s
|
84
88
|
ensure
|
85
89
|
v_window.destroy if !v_window.nil?
|
86
90
|
end
|
87
91
|
end
|
88
92
|
private
|
89
93
|
def self._get_contents fp
|
90
|
-
return
|
94
|
+
return "File #{fp} not readable" unless File.readable? fp
|
91
95
|
return Dir.new(fp).entries if File.directory? fp
|
92
96
|
case File.extname(fp)
|
93
97
|
when '.tgz','.gz'
|
@@ -96,6 +100,14 @@ module RubyCurses
|
|
96
100
|
when '.zip'
|
97
101
|
cmd = "unzip -l #{fp}"
|
98
102
|
content = %x[#{cmd}]
|
103
|
+
when '.jar', '.gem'
|
104
|
+
cmd = "tar -tvf #{fp}"
|
105
|
+
content = %x[#{cmd}]
|
106
|
+
when '.png', '.out','.jpg', '.gif','.pdf'
|
107
|
+
content = "File #{fp} not displayable"
|
108
|
+
when '.sqlite'
|
109
|
+
cmd = "sqlite3 #{fp} 'select name from sqlite_master;'"
|
110
|
+
content = %x[#{cmd}]
|
99
111
|
else
|
100
112
|
content = File.open(fp,"r").readlines
|
101
113
|
end
|
@@ -2,12 +2,37 @@ require 'rbcurse/rwidget'
|
|
2
2
|
#include Ncurses # FFI 2011-09-8
|
3
3
|
include RubyCurses
|
4
4
|
module RubyCurses
|
5
|
+
#
|
6
|
+
# This paints labels for various keys at the bottom of the screen, in 2 rows.
|
7
|
+
# This is based on alpines last 2 rows. Modes are supported so that the
|
8
|
+
# labels change as you enter a widget.
|
9
|
+
# For an example, see dbdemo.rb or rfe.rb
|
10
|
+
# NOTE: applications using 'App' use a shortcut "dock" to create this.
|
11
|
+
#
|
12
|
+
# The most minimal keylabel to print one label in first row, and none in second is:
|
13
|
+
# [["F1", "Help"], nil]
|
14
|
+
# To print 2 labels, one over the other:
|
15
|
+
# [["F1", "Help"], ["F10", "Quit"]]
|
16
|
+
#
|
5
17
|
class KeyLabelPrinter < Widget
|
6
18
|
attr_reader :key_labels
|
19
|
+
# the current mode (labels are based on mode, changing the mode, changes the labels
|
20
|
+
# displayed)
|
7
21
|
dsl_property :mode
|
22
|
+
# set the color of the labels, overriding the defaults
|
23
|
+
dsl_accessor :footer_color_pair
|
24
|
+
# set the color of the mnemonic, overriding the defaults
|
25
|
+
dsl_accessor :footer_mnemonic_color_pair
|
8
26
|
|
9
27
|
def initialize form, key_labels, config={}, &block
|
10
28
|
|
29
|
+
case key_labels
|
30
|
+
when Hash
|
31
|
+
raise "KeyLabelPrinter: KeyLabels cannot be a hash, Array of key labels required. Perhaps you did not pass labels"
|
32
|
+
when Array
|
33
|
+
else
|
34
|
+
raise "KeyLabelPrinter: Array of key labels required. Perhaps you did not pass labels"
|
35
|
+
end
|
11
36
|
super form, config, &block
|
12
37
|
@mode ||= :normal
|
13
38
|
#@key_labels = key_labels
|
@@ -16,14 +41,14 @@ module RubyCurses
|
|
16
41
|
@editable = false
|
17
42
|
@focusable = false
|
18
43
|
@cols ||= Ncurses.COLS-1
|
19
|
-
@row ||= Ncurses.LINES-
|
44
|
+
@row ||= Ncurses.LINES-2
|
20
45
|
@col ||= 0
|
21
46
|
@repaint_required = true
|
22
47
|
@footer_color_pair ||= $bottomcolor
|
23
48
|
@footer_mnemonic_color_pair ||= $reversecolor #2
|
24
49
|
end
|
25
50
|
def key_labels mode=@mode
|
26
|
-
@key_hash[mode]
|
51
|
+
@key_hash[mode]
|
27
52
|
end
|
28
53
|
# returns the keys as printed. these may or may not help
|
29
54
|
# in validation depedign on what you passed as zeroth index
|
@@ -46,16 +71,21 @@ module RubyCurses
|
|
46
71
|
def repaint
|
47
72
|
return unless @repaint_required
|
48
73
|
r,c = rowcol
|
49
|
-
|
74
|
+
arr = key_labels()
|
75
|
+
print_key_labels(arr, mode=@mode)
|
50
76
|
@repaint_required = false
|
51
77
|
end
|
78
|
+
# ?? does not use mode, i think key_labels is unused. a hash is now used 2011-10-11 XXX FIXME
|
79
|
+
# WARNING, i have not tested this after changing it.
|
52
80
|
def append_key_label key, label, mode=@mode
|
53
|
-
|
81
|
+
#@key_labels << [key, label] if !@key_labels.include? [key, label]
|
82
|
+
@key_hash[mode] << [key, label] if !@key_hash[mode].include? [key, label]
|
54
83
|
@repaint_required = true
|
55
84
|
end
|
56
85
|
def print_key_labels(arr = key_labels(), mode=@mode)
|
57
86
|
#return if !@show_key_labels # XXX
|
58
87
|
@win ||= @form.window
|
88
|
+
$log.debug "XXX: PKL #{arr.length}, #{arr}"
|
59
89
|
@padding = @cols / (arr.length/2)
|
60
90
|
posx = 0
|
61
91
|
even = []
|
data/lib/rbcurse/listeditable.rb
CHANGED
@@ -142,9 +142,11 @@ module ListEditable
|
|
142
142
|
# user requested this kill to be appened to last kill, so it can be yanked as one
|
143
143
|
#$kill_ring.last << list
|
144
144
|
last = $kill_ring.pop
|
145
|
+
$log.debug "YANK: addto : last= #{last} , list= #{list} "
|
145
146
|
case list
|
146
147
|
when Array
|
147
|
-
list.insert 0, last
|
148
|
+
#list.insert 0, last
|
149
|
+
list.insert 0, *last # 2011-10-10 changed as it was wrong in textarea
|
148
150
|
$kill_ring << list
|
149
151
|
when String
|
150
152
|
$kill_ring << [last, list]
|
@@ -154,6 +156,7 @@ module ListEditable
|
|
154
156
|
end
|
155
157
|
$kill_ring_pointer = $kill_ring.size
|
156
158
|
$append_next_kill = false
|
159
|
+
$log.debug "YANK: kill_ring: #{$kill_ring} "
|
157
160
|
end
|
158
161
|
|
159
162
|
# pastes recent (last) entry of kill_ring.
|
@@ -163,6 +166,7 @@ module ListEditable
|
|
163
166
|
return -1 if !@editable
|
164
167
|
return if $kill_ring.empty?
|
165
168
|
row = $kill_ring.last
|
169
|
+
$log.debug "YANK: row #{row} "
|
166
170
|
index = where
|
167
171
|
case row
|
168
172
|
when Array
|
data/lib/rbcurse/listkeys.rb
CHANGED
@@ -4,7 +4,7 @@ module RubyCurses
|
|
4
4
|
# That was possible earlier, but now that i am binding the key at construction time
|
5
5
|
# any changes to the vars after construction won't have an effect.
|
6
6
|
def install_list_keys
|
7
|
-
|
7
|
+
#@KEY_ROW_SELECTOR ||= ?\C-x.getbyte(0) # need to changed from C-x since used for actions # changed 2011 dts
|
8
8
|
@KEY_ROW_SELECTOR ||= 0 # need to changed from C-x since used for actions
|
9
9
|
@KEY_BLOCK_SELECTOR ||= ?\M-x.getbyte(0) # need to change since M-x used for commands
|
10
10
|
@KEY_GOTO_TOP ||= ?\M-0.getbyte(0)
|
@@ -12,7 +12,7 @@ module ListScrollable
|
|
12
12
|
attr_accessor :show_caret # 2010-01-23 23:06 our own fake insertion point
|
13
13
|
def previous_row num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
|
14
14
|
#return :UNHANDLED if @current_index == 0 # EVIL
|
15
|
-
return
|
15
|
+
return :NO_PREVIOUS_ROW if @current_index == 0
|
16
16
|
@oldrow = @current_index
|
17
17
|
# NOTE that putting a multiplier inside, prevents an event from being triggered for each row's
|
18
18
|
# on leave and on enter
|
@@ -29,7 +29,7 @@ module ListScrollable
|
|
29
29
|
# next field. however, in long lists when user scrolls the sudden jumping to next is very annoying.
|
30
30
|
# In combos, if focus was on last row, the combo closed which is not accceptable.
|
31
31
|
#return :UNHANDLED if @current_index == rc-1 # EVIL !!!
|
32
|
-
return
|
32
|
+
return :NO_NEXT_ROW if @current_index == rc-1 # changed 2011-10-5 so process can do something
|
33
33
|
@oldrow = @current_index
|
34
34
|
@current_index += 1*num if @current_index < rc
|
35
35
|
bounds_check
|
@@ -160,7 +160,7 @@ module ListScrollable
|
|
160
160
|
def scroll_right
|
161
161
|
$log.debug " inside scroll_right "
|
162
162
|
hscrollcols = $multiplier > 0 ? $multiplier : @width/2
|
163
|
-
$log.debug " scroll_right mult:#{$multiplier} , hscrollcols #{hscrollcols}, w: #{@width} ll:#{@longest_line} "
|
163
|
+
$log.debug " scroll_right mult:#{$multiplier} , hscrollcols #{hscrollcols}, pcol #{@pcol} w: #{@width} ll:#{@longest_line} "
|
164
164
|
#blen = @buffer.rstrip.length
|
165
165
|
blen = @longest_line
|
166
166
|
@pcol += hscrollcols if @pcol + @width < blen
|
@@ -292,7 +292,11 @@ module ListScrollable
|
|
292
292
|
@search_start_ix = start
|
293
293
|
regex = Regexp.new(regex, Regexp::IGNORECASE) if @search_case
|
294
294
|
start.upto(fend) do |ix|
|
295
|
-
|
295
|
+
row1 = @list[ix].to_s
|
296
|
+
|
297
|
+
# 2011-09-29 crashing on a character F3 in log file
|
298
|
+
row = row1.encode("ASCII-8BIT", :invalid => :replace, :undef => :replace, :replace => "?")
|
299
|
+
|
296
300
|
m=row.match(regex)
|
297
301
|
if !m.nil?
|
298
302
|
@find_offset = m.offset(0)[0]
|
@@ -473,13 +477,16 @@ module ListScrollable
|
|
473
477
|
end
|
474
478
|
# returns only the visible portion of string taking into account display length
|
475
479
|
# and horizontal scrolling. MODIFIES STRING
|
480
|
+
# NOTE truncate does not take into account left_margin that some widgets might use
|
476
481
|
def truncate content #:nodoc:
|
477
|
-
maxlen = @maxlen || @width-2
|
482
|
+
#maxlen = @maxlen || @width-2
|
483
|
+
_maxlen = @maxlen || @width-@internal_width
|
484
|
+
_maxlen = @width-@internal_width if _maxlen > @width-@internal_width
|
478
485
|
if !content.nil?
|
479
|
-
if content.length >
|
486
|
+
if content.length > _maxlen # only show maxlen
|
480
487
|
@longest_line = content.length if content.length > @longest_line
|
481
|
-
#content = content[@pcol..@pcol+
|
482
|
-
content.replace content[@pcol..@pcol+
|
488
|
+
#content = content[@pcol..@pcol+_maxlen-1]
|
489
|
+
content.replace content[@pcol..@pcol+_maxlen-1]
|
483
490
|
else
|
484
491
|
# can this be avoided if pcol is 0 XXX
|
485
492
|
content.replace content[@pcol..-1] if @pcol > 0
|
@@ -16,7 +16,6 @@ require 'rbcurse/listcellrenderer'
|
|
16
16
|
require 'forwardable'
|
17
17
|
|
18
18
|
|
19
|
-
#include Ncurses # FFI 2011-09-8
|
20
19
|
module RubyCurses
|
21
20
|
extend self
|
22
21
|
##
|
@@ -34,9 +33,9 @@ module RubyCurses
|
|
34
33
|
class BasicListbox < Widget
|
35
34
|
|
36
35
|
require 'rbcurse/listscrollable'
|
37
|
-
|
38
|
-
#require 'rbcurse/defaultlistselectionmodel'
|
36
|
+
require 'rbcurse/extras/listselectable' # added 2011-10-8
|
39
37
|
include ListScrollable
|
38
|
+
include NewListSelectable # added 2011-10-8
|
40
39
|
extend Forwardable
|
41
40
|
dsl_accessor :height
|
42
41
|
dsl_accessor :title
|
@@ -94,8 +93,6 @@ module RubyCurses
|
|
94
93
|
@_events.push(*[:ENTER_ROW, :LEAVE_ROW, :LIST_SELECTION_EVENT, :PRESS])
|
95
94
|
@selection_mode ||= :multiple # default is multiple, anything else given becomes single
|
96
95
|
@win = @graphic # 2010-01-04 12:36 BUFFERED replace form.window with graphic
|
97
|
-
# moving down to repaint so that scrollpane can set should_buffered
|
98
|
-
# added 2010-02-17 23:05 RFED16 so we don't need a form.
|
99
96
|
@win_left = 0
|
100
97
|
@win_top = 0
|
101
98
|
|
@@ -140,6 +137,7 @@ module RubyCurses
|
|
140
137
|
bind_key(32){ toggle_row_selection() }
|
141
138
|
bind_key(10){ fire_action_event }
|
142
139
|
bind_key(13){ fire_action_event }
|
140
|
+
list_bindings
|
143
141
|
@keys_mapped = true
|
144
142
|
|
145
143
|
end
|
@@ -185,12 +183,16 @@ module RubyCurses
|
|
185
183
|
else
|
186
184
|
raise ArgumentError, "Listbox list(): do not know how to handle #{alist.class} "
|
187
185
|
end
|
188
|
-
|
189
|
-
|
190
|
-
#@list_selection_model.selection_mode = @tmp_selection_mode if @tmp_selection_mode
|
186
|
+
clear_selection
|
187
|
+
|
191
188
|
@repaint_required = true
|
192
189
|
@list
|
193
190
|
end
|
191
|
+
# conv method to insert data, trying to keep names same across along with Tabular, TextView,
|
192
|
+
# TextArea and listbox. Don;t use this till i am certain.
|
193
|
+
def data=(val)
|
194
|
+
list(val)
|
195
|
+
end
|
194
196
|
# get element at
|
195
197
|
# @param [Fixnum] index for element
|
196
198
|
# @return [Object] element
|
@@ -375,6 +377,7 @@ module RubyCurses
|
|
375
377
|
Ncurses.beep
|
376
378
|
return :UNHANDLED
|
377
379
|
end
|
380
|
+
super # forgot this 2011-10-9 that's why events not firign
|
378
381
|
on_enter_row @current_index
|
379
382
|
set_form_row # added 2009-01-11 23:41
|
380
383
|
true
|
@@ -404,7 +407,6 @@ module RubyCurses
|
|
404
407
|
# processing. also, it pans the data horizontally giving the renderer
|
405
408
|
# a section of it.
|
406
409
|
def repaint #:nodoc:
|
407
|
-
#safe_create_buffer # 2010-01-04 12:36 BUFFERED moved here 2010-01-05 18:07
|
408
410
|
return unless @repaint_required
|
409
411
|
# not sure where to put this, once for all or repeat 2010-02-17 23:07 RFED16
|
410
412
|
my_win = @form ? @form.window : @target_window
|
@@ -467,8 +469,6 @@ module RubyCurses
|
|
467
469
|
end # rc == 0
|
468
470
|
#@table_changed = false
|
469
471
|
@repaint_required = false
|
470
|
-
#@buffer_modified = true # required by form to call buffer_to_screen BUFFERED
|
471
|
-
#buffer_to_window # RFED16 2010-02-17 23:16
|
472
472
|
end
|
473
473
|
# the idea here is to allow users who subclass Listbox to easily override parts of the cumbersome repaint
|
474
474
|
# method. This assumes your List has some data, but you print a lot more. Now you don't need to
|
@@ -484,7 +484,7 @@ module RubyCurses
|
|
484
484
|
value.to_s if value
|
485
485
|
end
|
486
486
|
end
|
487
|
-
# takes a block, this way anyone extending this
|
487
|
+
# takes a block, this way anyone extending this klass can just pass a block to do his job
|
488
488
|
# This modifies the string
|
489
489
|
def sanitize content #:nodoc:
|
490
490
|
if content.is_a? String
|
@@ -531,8 +531,6 @@ module RubyCurses
|
|
531
531
|
def set_form_col col1=0 #:nodoc:
|
532
532
|
@cols_panned ||= 0
|
533
533
|
# editable listboxes will involve changing cursor and the form issue
|
534
|
-
## added win_col on 2010-01-04 23:28 for embedded forms BUFFERED TRYING OUT
|
535
|
-
#win_col=@form.window.left
|
536
534
|
win_col = 0
|
537
535
|
col2 = win_col + @col + @col_offset + col1 + @cols_panned + @left_margin
|
538
536
|
$log.debug " set_form_col in rlistbox #{@col}+ left_margin #{@left_margin} ( #{col2} ) "
|
@@ -543,17 +541,25 @@ module RubyCurses
|
|
543
541
|
|
544
542
|
# change selection of current row on pressing space bar
|
545
543
|
# If mode is multiple, then other selections are cleared and this is added
|
546
|
-
|
544
|
+
# NOTE: 2011-10-8 allow multiple select on spacebar. Using C-Space was quite unfriendly
|
545
|
+
# although it will still work
|
546
|
+
def OLDtoggle_row_selection crow=@current_index
|
547
547
|
@repaint_required = true
|
548
|
+
row = crow
|
548
549
|
case @selection_mode
|
549
550
|
when :multiple
|
550
|
-
|
551
|
-
|
551
|
+
add_to_selection
|
552
|
+
#clear_selection
|
553
|
+
#@selected_indices[0] = crow #@current_index
|
552
554
|
else
|
553
555
|
if @selected_index == crow #@current_index
|
554
556
|
@selected_index = nil
|
557
|
+
lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
|
558
|
+
fire_handler :LIST_SELECTION_EVENT, lse
|
555
559
|
else
|
556
560
|
@selected_index = crow #@current_index
|
561
|
+
lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
|
562
|
+
fire_handler :LIST_SELECTION_EVENT, lse
|
557
563
|
end
|
558
564
|
end
|
559
565
|
end
|
@@ -562,24 +568,29 @@ module RubyCurses
|
|
562
568
|
# add an item to selection, if selection mode is multiple
|
563
569
|
# if item already selected, it is deselected, else selected
|
564
570
|
# typically bound to Ctrl-Space
|
565
|
-
def
|
571
|
+
def OLDadd_to_selection
|
572
|
+
crow = @current_index
|
566
573
|
case @selection_mode
|
567
574
|
when :multiple
|
568
575
|
if @selected_indices.include? @current_index
|
569
576
|
@selected_indices.delete @current_index
|
577
|
+
lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
|
578
|
+
fire_handler :LIST_SELECTION_EVENT, lse
|
570
579
|
else
|
571
580
|
@selected_indices << @current_index
|
581
|
+
lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
|
582
|
+
fire_handler :LIST_SELECTION_EVENT, lse
|
572
583
|
end
|
573
584
|
else
|
574
585
|
end
|
575
586
|
@repaint_required = true
|
576
587
|
end
|
577
588
|
# clears selected indices
|
578
|
-
def
|
589
|
+
def OLDclear_selection
|
579
590
|
@selected_indices = []
|
580
591
|
@repaint_required = true
|
581
592
|
end
|
582
|
-
def
|
593
|
+
def OLDis_row_selected crow=@current_index
|
583
594
|
case @selection_mode
|
584
595
|
when :multiple
|
585
596
|
@selected_indices.include? crow
|
@@ -602,6 +613,19 @@ module RubyCurses
|
|
602
613
|
@current_index = row
|
603
614
|
@repaint_required = true # fire list_select XXX
|
604
615
|
end
|
616
|
+
# Returns selected indices
|
617
|
+
# Indices are often required since the renderer may modify the values displayed
|
618
|
+
#
|
619
|
+
def get_selected_indices; @selected_indices; end
|
620
|
+
|
621
|
+
# Returns selected values
|
622
|
+
#
|
623
|
+
def get_selected_values
|
624
|
+
selected = []
|
625
|
+
@selected_indices.each { |i| selected << @list[i] }
|
626
|
+
return selected
|
627
|
+
end
|
628
|
+
alias :selected_values :get_selected_values
|
605
629
|
|
606
630
|
|
607
631
|
|
@@ -648,9 +672,6 @@ module RubyCurses
|
|
648
672
|
@attrs[:focussed] = $row_focussed_attr
|
649
673
|
|
650
674
|
end
|
651
|
-
def getvalue
|
652
|
-
@text
|
653
|
-
end
|
654
675
|
##
|
655
676
|
# sets @color_pair and @attr
|
656
677
|
def select_colors focussed, selected
|
@@ -26,7 +26,6 @@ module RubyCurses
|
|
26
26
|
dsl_accessor :height, :width, :top, :left # 2009-01-06 00:05 after removing meth missing
|
27
27
|
|
28
28
|
def initialize form=nil, aconfig={}, &block
|
29
|
-
#@form = form
|
30
29
|
@config = aconfig
|
31
30
|
@config.each_pair { |k,v| instance_variable_set("@#{k}",v) }
|
32
31
|
instance_eval &block if block_given?
|
@@ -44,15 +43,6 @@ module RubyCurses
|
|
44
43
|
@bottomline.name = "rcommandwindow's bl"
|
45
44
|
extend Forwardable
|
46
45
|
def_delegators :@bottomline, :ask, :say, :agree, :choose #, :display_text_interactive
|
47
|
-
#if @form.nil?
|
48
|
-
#@form = RubyCurses::Form.new @window
|
49
|
-
#else
|
50
|
-
#@form.window = @window
|
51
|
-
#end
|
52
|
-
#acolor = get_color $reversecolor
|
53
|
-
#color = get_color $datacolor
|
54
|
-
#@window.printstring 0,0,"hello there", $normalcolor, 'normal'
|
55
|
-
#@window.bkgd(Ncurses.COLOR_PAIR(acolor));
|
56
46
|
if @box == :border
|
57
47
|
@window.box 0,0
|
58
48
|
elsif @box
|
@@ -66,9 +56,7 @@ module RubyCurses
|
|
66
56
|
@window.wrefresh
|
67
57
|
@panel = @window.panel
|
68
58
|
Ncurses::Panel.update_panels
|
69
|
-
#@form.repaint
|
70
59
|
@window.wrefresh
|
71
|
-
#handle_keys
|
72
60
|
@row_offset = 0
|
73
61
|
if @box
|
74
62
|
@row_offset = 1
|
@@ -127,7 +115,6 @@ module RubyCurses
|
|
127
115
|
when 0
|
128
116
|
@start = 0
|
129
117
|
end
|
130
|
-
#@form.repaint
|
131
118
|
Ncurses::Panel.update_panels();
|
132
119
|
Ncurses.doupdate();
|
133
120
|
@window.wrefresh
|
@@ -166,7 +153,7 @@ module RubyCurses
|
|
166
153
|
# do not go more than 3 columns and do not print more than window TODO FIXME
|
167
154
|
def display_menu list, options={}
|
168
155
|
indexing = options[:indexing]
|
169
|
-
max_cols = 3
|
156
|
+
max_cols = 3 # maximum no of columns, we will reduce based on data size
|
170
157
|
l_succ = "`"
|
171
158
|
act_height = @height
|
172
159
|
if @box
|
@@ -194,6 +181,13 @@ module RubyCurses
|
|
194
181
|
h = act_height
|
195
182
|
cols = (lh*1.0 / h).ceil
|
196
183
|
cols = max_cols if cols > max_cols
|
184
|
+
# sometimes elements are large like directory paths, so check size
|
185
|
+
datasize = list.first.length
|
186
|
+
if datasize > @width/3 # keep safety margin since checking only first row
|
187
|
+
cols = 1
|
188
|
+
elsif datasize > @width/2
|
189
|
+
cols = [2,cols].min
|
190
|
+
end
|
197
191
|
adv = (@width/cols).to_i
|
198
192
|
colct = 0
|
199
193
|
col = 1
|