rbcurse 1.4.1 → 1.5.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/CHANGELOG +31 -0
  2. data/README.markdown +69 -11
  3. data/VERSION +1 -1
  4. data/lib/rbcurse.rb +5 -5
  5. metadata +10 -198
  6. data/Makefile +0 -21
  7. data/Manifest.txt +0 -91
  8. data/TODO +0 -372
  9. data/TODO2.txt +0 -118
  10. data/examples/README.txt +0 -67
  11. data/examples/abasiclist.rb +0 -33
  12. data/examples/alpmenu.rb +0 -42
  13. data/examples/app.rb +0 -859
  14. data/examples/app.sample +0 -10
  15. data/examples/appdirtree.rb +0 -75
  16. data/examples/appemail.rb +0 -191
  17. data/examples/appemaillb.rb +0 -308
  18. data/examples/appgcompose.rb +0 -315
  19. data/examples/atree.rb +0 -64
  20. data/examples/common/file.rb +0 -40
  21. data/examples/common/rmail.rb +0 -257
  22. data/examples/data.txt +0 -683
  23. data/examples/data/README.markdown +0 -9
  24. data/examples/data/brew.txt +0 -38
  25. data/examples/data/color.2 +0 -37
  26. data/examples/data/gemlist.txt +0 -60
  27. data/examples/data/lotr.txt +0 -12
  28. data/examples/data/ports.txt +0 -136
  29. data/examples/data/tasks.txt +0 -27
  30. data/examples/data/todocsv.csv +0 -28
  31. data/examples/data/unix1.txt +0 -21
  32. data/examples/data/unix2.txt +0 -11
  33. data/examples/dbdemo.rb +0 -495
  34. data/examples/deprecated/appgmail.rb +0 -952
  35. data/examples/deprecated/splitp.rb +0 -56
  36. data/examples/deprecated/testscrolllb.rb +0 -86
  37. data/examples/deprecated/testscrollp.rb +0 -88
  38. data/examples/deprecated/testscrollta.rb +0 -80
  39. data/examples/deprecated/testscrolltable.rb +0 -165
  40. data/examples/deprecated/testsplit.rb +0 -87
  41. data/examples/deprecated/testsplit2.rb +0 -123
  42. data/examples/deprecated/testsplit3.rb +0 -215
  43. data/examples/deprecated/testsplit3_1.rb +0 -244
  44. data/examples/deprecated/testsplit3a.rb +0 -215
  45. data/examples/deprecated/testsplit3b.rb +0 -237
  46. data/examples/deprecated/testsplitta.rb +0 -148
  47. data/examples/deprecated/testsplittv.rb +0 -142
  48. data/examples/deprecated/testsplittvv.rb +0 -144
  49. data/examples/deprecated/testtpane.rb +0 -215
  50. data/examples/deprecated/testtpane2.rb +0 -145
  51. data/examples/deprecated/testtpanetable.rb +0 -203
  52. data/examples/dirtree.rb +0 -88
  53. data/examples/experimental/resultsetdemo.rb +0 -280
  54. data/examples/experimental/testmform.rb +0 -35
  55. data/examples/experimental/testscroller.rb +0 -117
  56. data/examples/experimental/teststackflow.rb +0 -111
  57. data/examples/menu1.rb +0 -112
  58. data/examples/multispl.rb +0 -86
  59. data/examples/newmessagebox.rb +0 -130
  60. data/examples/newtabbedwindow.rb +0 -100
  61. data/examples/newtesttabp.rb +0 -121
  62. data/examples/qdfilechooser.rb +0 -68
  63. data/examples/rfe.rb +0 -1195
  64. data/examples/rfe_renderer.rb +0 -121
  65. data/examples/sqlc.rb +0 -454
  66. data/examples/sqlm.rb +0 -437
  67. data/examples/sqlt.rb +0 -408
  68. data/examples/status.txt +0 -68
  69. data/examples/table1.rb +0 -24
  70. data/examples/term2.rb +0 -84
  71. data/examples/test1.rb +0 -239
  72. data/examples/test2.rb +0 -674
  73. data/examples/testapp.rb +0 -44
  74. data/examples/testapp2.rb +0 -58
  75. data/examples/testchars.rb +0 -137
  76. data/examples/testcombo.rb +0 -91
  77. data/examples/testkeypress.rb +0 -66
  78. data/examples/testlistbox.rb +0 -113
  79. data/examples/testmenu.rb +0 -101
  80. data/examples/testmulticomp.rb +0 -70
  81. data/examples/testmulticontainer.rb +0 -94
  82. data/examples/testmultispl.rb +0 -199
  83. data/examples/testree.rb +0 -106
  84. data/examples/testtable.rb +0 -263
  85. data/examples/testtabp.rb +0 -107
  86. data/examples/testtodo.rb +0 -584
  87. data/examples/testvimsplit.rb +0 -112
  88. data/examples/testwsshortcuts.rb +0 -64
  89. data/examples/testwsshortcuts2.rb +0 -126
  90. data/examples/todo.db +0 -0
  91. data/examples/todo.yml +0 -191
  92. data/examples/viewtodo.rb +0 -574
  93. data/lib/rbcurse/action.rb +0 -40
  94. data/lib/rbcurse/app.rb +0 -1374
  95. data/lib/rbcurse/applicationheader.rb +0 -102
  96. data/lib/rbcurse/celleditor.rb +0 -112
  97. data/lib/rbcurse/checkboxcellrenderer.rb +0 -57
  98. data/lib/rbcurse/colormap.rb +0 -159
  99. data/lib/rbcurse/comboboxcellrenderer.rb +0 -30
  100. data/lib/rbcurse/common/ansiparser.rb +0 -117
  101. data/lib/rbcurse/common/appmethods.rb +0 -112
  102. data/lib/rbcurse/common/basestack.rb +0 -407
  103. data/lib/rbcurse/common/bordertitle.rb +0 -41
  104. data/lib/rbcurse/common/chunk.rb +0 -177
  105. data/lib/rbcurse/common/colorparser.rb +0 -71
  106. data/lib/rbcurse/common/keydefs.rb +0 -30
  107. data/lib/rbcurse/common/widgetshortcuts.rb +0 -302
  108. data/lib/rbcurse/defaultlistselectionmodel.rb +0 -79
  109. data/lib/rbcurse/deprecated/README.markdown +0 -12
  110. data/lib/rbcurse/deprecated/rscrollpane.rb +0 -512
  111. data/lib/rbcurse/deprecated/rsplitpane.rb +0 -894
  112. data/lib/rbcurse/deprecated/rsplitpane2.rb +0 -1009
  113. data/lib/rbcurse/deprecated/rviewport.rb +0 -204
  114. data/lib/rbcurse/experimental/README.markdown +0 -14
  115. data/lib/rbcurse/experimental/resultsettextview.rb +0 -585
  116. data/lib/rbcurse/experimental/stackflow.rb +0 -478
  117. data/lib/rbcurse/extras/bottomline.rb +0 -1850
  118. data/lib/rbcurse/extras/box.rb +0 -58
  119. data/lib/rbcurse/extras/directorylist.rb +0 -467
  120. data/lib/rbcurse/extras/directorytree.rb +0 -69
  121. data/lib/rbcurse/extras/divider.rb +0 -310
  122. data/lib/rbcurse/extras/focusmanager.rb +0 -31
  123. data/lib/rbcurse/extras/horizlist.rb +0 -203
  124. data/lib/rbcurse/extras/listselectable.rb +0 -264
  125. data/lib/rbcurse/extras/masterdetail.rb +0 -166
  126. data/lib/rbcurse/extras/menutree.rb +0 -63
  127. data/lib/rbcurse/extras/multiform.rb +0 -330
  128. data/lib/rbcurse/extras/multilinelabel.rb +0 -142
  129. data/lib/rbcurse/extras/newmessagebox.rb +0 -328
  130. data/lib/rbcurse/extras/newtabbedpane.rb +0 -612
  131. data/lib/rbcurse/extras/newtabbedwindow.rb +0 -68
  132. data/lib/rbcurse/extras/padreader.rb +0 -189
  133. data/lib/rbcurse/extras/rcomboedit.rb +0 -256
  134. data/lib/rbcurse/extras/resultsetbrowser.rb +0 -281
  135. data/lib/rbcurse/extras/rlink.rb +0 -27
  136. data/lib/rbcurse/extras/rmenulink.rb +0 -21
  137. data/lib/rbcurse/extras/scrollbar.rb +0 -143
  138. data/lib/rbcurse/extras/statusline.rb +0 -94
  139. data/lib/rbcurse/extras/stdscrwindow.rb +0 -309
  140. data/lib/rbcurse/extras/tableextended.rb +0 -40
  141. data/lib/rbcurse/extras/tabular.rb +0 -264
  142. data/lib/rbcurse/extras/tabularwidget.rb +0 -1150
  143. data/lib/rbcurse/extras/textpad.rb +0 -516
  144. data/lib/rbcurse/extras/viewer.rb +0 -136
  145. data/lib/rbcurse/io.rb +0 -850
  146. data/lib/rbcurse/keylabelprinter.rb +0 -178
  147. data/lib/rbcurse/listcellrenderer.rb +0 -140
  148. data/lib/rbcurse/listeditable.rb +0 -310
  149. data/lib/rbcurse/listkeys.rb +0 -37
  150. data/lib/rbcurse/listscrollable.rb +0 -564
  151. data/lib/rbcurse/listselectable.rb +0 -142
  152. data/lib/rbcurse/mapper.rb +0 -130
  153. data/lib/rbcurse/orderedhash.rb +0 -77
  154. data/lib/rbcurse/ractionevent.rb +0 -67
  155. data/lib/rbcurse/rbasiclistbox.rb +0 -768
  156. data/lib/rbcurse/rchangeevent.rb +0 -27
  157. data/lib/rbcurse/rcombo.rb +0 -238
  158. data/lib/rbcurse/rcommandwindow.rb +0 -587
  159. data/lib/rbcurse/rcontainer.rb +0 -415
  160. data/lib/rbcurse/rdialogs.rb +0 -451
  161. data/lib/rbcurse/rinputdataevent.rb +0 -47
  162. data/lib/rbcurse/rlistbox.rb +0 -1196
  163. data/lib/rbcurse/rmenu.rb +0 -939
  164. data/lib/rbcurse/rmessagebox.rb +0 -348
  165. data/lib/rbcurse/rmulticontainer.rb +0 -304
  166. data/lib/rbcurse/rmultisplit.rb +0 -722
  167. data/lib/rbcurse/rmultitextview.rb +0 -306
  168. data/lib/rbcurse/rpopupmenu.rb +0 -755
  169. data/lib/rbcurse/rprogress.rb +0 -118
  170. data/lib/rbcurse/rscrollform.rb +0 -418
  171. data/lib/rbcurse/rtabbedpane.rb +0 -1158
  172. data/lib/rbcurse/rtabbedwindow.rb +0 -167
  173. data/lib/rbcurse/rtable.rb +0 -1718
  174. data/lib/rbcurse/rtextarea.rb +0 -920
  175. data/lib/rbcurse/rtextview.rb +0 -761
  176. data/lib/rbcurse/rtree.rb +0 -780
  177. data/lib/rbcurse/rvimsplit.rb +0 -763
  178. data/lib/rbcurse/rwidget.rb +0 -2915
  179. data/lib/rbcurse/scrollable.rb +0 -301
  180. data/lib/rbcurse/table/tablecellrenderer.rb +0 -86
  181. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -98
  182. data/lib/rbcurse/tree/treecellrenderer.rb +0 -150
  183. data/lib/rbcurse/tree/treemodel.rb +0 -428
  184. data/lib/rbcurse/undomanager.rb +0 -188
  185. data/lib/rbcurse/vieditable.rb +0 -144
  186. data/lib/ver/keyboard.rb +0 -150
  187. data/lib/ver/keyboard2.rb +0 -170
  188. data/lib/ver/ncurses.rb +0 -218
  189. data/lib/ver/panel.rb +0 -162
  190. data/lib/ver/rpad.rb +0 -375
  191. data/lib/ver/window.rb +0 -882
  192. data/test/test_rbcurse.rb +0 -0
@@ -1,58 +0,0 @@
1
- # ------------------------------------------------------------ #
2
- # File: box.rb
3
- # Description: draws a box around some group of items
4
- # Author: rkumar http://github.com/rkumar/rbcurse/
5
- # Date: 06.11.11 - 18:22
6
- # Last update: 06.11.11 - 19:53
7
- # ------------------------------------------------------------ #
8
- #
9
- require 'rbcurse'
10
- require 'rbcurse/common/bordertitle'
11
- include RubyCurses
12
- #include RubyCurses::BorderTitle
13
-
14
- # @example
15
- #
16
- # At a later stage, we will integrate this with lists and tables, so it will happen automatically.
17
- #
18
- # @since 1.4.1 UNTESTED
19
- module RubyCurses
20
- class Box < Widget
21
-
22
- include BorderTitle
23
-
24
- # margin for placing widgets inside
25
- # This is not used inside here, but is used by stacks.
26
- # @see widgetshortcuts.rb
27
- dsl_accessor :margin_left, :margin_top
28
-
29
- def initialize form, config={}, &block
30
-
31
- bordertitle_init
32
- super
33
- @window = form.window if @form
34
- @editable = false
35
- @focusable = false
36
- #@height += 1 # for that silly -1 that happens
37
- @repaint_required = true
38
- end
39
-
40
- ##
41
- # repaint the scrollbar
42
- def repaint
43
- return unless @repaint_required
44
- bc = $datacolor
45
- bordercolor = @border_color || bc
46
- borderatt = @border_attrib || Ncurses::A_NORMAL
47
- @window.print_border row, col, height, width, bordercolor, borderatt
48
- #print_borders
49
- print_title
50
- @repaint_required = false
51
- end
52
- ##
53
- ##
54
- # ADD HERE
55
- end
56
- end
57
- if __FILE__ == $PROGRAM_NAME
58
- end
@@ -1,467 +0,0 @@
1
- require 'rbcurse'
2
- require 'fileutils'
3
- require 'rbcurse/rlistbox'
4
- require 'rbcurse/vieditable'
5
- require 'rbcurse/undomanager'
6
- ##
7
- # Created on : Wed Sep 22 22:30:13 IST 2010
8
- # (c) rkumar (arunachalesha)
9
- #
10
- module RubyCurses
11
- # Display a directory listing, allowing user to drill down on pressing Enter
12
- # on a directory, or sort when pressing enter on header row.
13
- class DirectoryList < Listbox
14
-
15
- include ViEditable
16
-
17
- def initialize form, config={}, &block
18
- @hide_dot_files = false
19
- @hide_others = false
20
- @curpos = 0
21
- super
22
-
23
- #@current_path ||= Dir.getwd # setting it causes selection not to fire if same one
24
- # is selected first
25
- @_header_array = [ "Attr", "Size", "Modified" , "Name" , "<Order_by_Extension>" ]
26
- @_header = " %s %8s %19s %s %s " % @_header_array
27
- end
28
- def init_vars
29
- # which rows are not data, thus don't fire, or give error
30
- @_non_data_indices = []
31
- @_header_row_index = 0
32
- @_first_data_index = 1
33
- @one_key_selection = false # this allows us to map keys to methods
34
- vieditable_init_listbox
35
- undom = SimpleUndo.new self
36
- bind_key(?\M-h, :scroll_left)
37
- bind_key(?\M-l, :scroll_right)
38
- bind_key(KEY_RIGHT, :cursor_forward)
39
- bind_key(KEY_LEFT, :cursor_backward)
40
- bind_key(?$, :end_of_line)
41
- bind_key(?\C-e, :end_of_line)
42
- bind_key(?\C-a, :start_of_line)
43
- bind_key(?a, :select_all)
44
- bind_key(?*, :invert_selection)
45
- bind_key(?u, :clear_selection)
46
- bind_key(?+, :ask_select)
47
- bind_key(?-, :ask_unselect)
48
- bind_key(?I) { @hide_dot_files = !@hide_dot_files; prune_entries; }
49
- #bind_key(?v, :view_current) # does not respond to ??? XXX
50
- bind_key(?v) {view_current}
51
- super
52
- end
53
- # changing the current path, refreshes files
54
- def current_path(*val)
55
- if val.empty?
56
- return @current_path
57
- else
58
- raise ArgumentError, "current_path should be a directory:#{val[0]}." unless File.directory? val[0]
59
- oldvalue = @current_path
60
- if oldvalue != val[0]
61
- @current_path = val[0]
62
- populate @current_path
63
- fire_property_change(:current_path, oldvalue, @current_path)
64
- end
65
- end
66
- self
67
- end
68
- # populate the list with file names
69
- # @param [String, Array] string is the path name to populate with
70
- # Array is a list of files
71
- def populate path
72
- case path
73
- when String
74
- @current_path = path
75
- @entries = Dir.new(path).entries
76
- @entries.delete(".")
77
- # isn;t it a bit late here. it needs to happen to what's already there
78
- @entries.delete_if {|x| x =~ /^\./} if @hide_dot_files
79
- @entries.delete_if {|x| x =~ /\.bak$/ || x=~/\.swp$/} if @hide_others
80
- when Array
81
- path = @current_path
82
- # we've been passed @entries so we don't need to put it again ??? XXX
83
- end
84
- # TODO K M etc
85
- list @entries
86
- @list.insert 0, @_header
87
- @title = @current_path
88
- @current_index = @_first_data_index
89
- set_form_row if @form
90
- end
91
- # called by parent's repaint
92
- def convert_value_to_text file, crow
93
- if @short
94
- file
95
- else
96
- if crow == @_header_row_index
97
- return file
98
- else
99
- # OUCH i don't know if its a header !!
100
- fullname = File.join(@current_path, file)
101
- fname = file
102
- stat = File::Stat.new fullname
103
- time = stat.mtime.to_s[0..18]
104
- attr = stat.directory? ? "d" : "-"
105
- attr << (stat.writable? ? "w" : "-")
106
- attr << (stat.readable? ? "r" : "-")
107
- attr << (stat.executable? ? "x" : "-")
108
- fname << "/" if stat.directory? && fname[-1] != "/"
109
- value = " %s %8d %s %s" % [attr, stat.size, time, fname]
110
- return value
111
- end
112
- end
113
- end
114
-
115
- def ___create_default_cell_renderer
116
- cell_renderer( RubyCurses::DirectoryListCellRenderer.new "", {:color=>@color, :bgcolor=>@bgcolor, :parent => self, :display_length=> @width-2-@left_margin})
117
- end
118
- def _get_word_under_cursor line=@_header, pos=@curpos
119
- finish = line.index(" ", pos)
120
- start = line.rindex(" ",pos)
121
- finish = -1 if finish.nil?
122
- start = 0 if start.nil?
123
- return line[start..finish]
124
- end
125
- # sorts entries by various parameters.
126
- # Not optimal since it creates file stat objects each time rather than cacheing, but this is a demo of widgets
127
- # not a real directory lister!
128
- def sort_by key, reverse=false
129
- # remove parent before sorting, keep at top
130
- first = @entries.delete_at(0) if @entries[0]==".."
131
- #key ||= @sort_key
132
- sort_keys = { 'Name' => :name, 'Modified' => :mtime, "Size" => :size, "<Order_by_Extension>" => :ext, 'Attr' => :attr, "Accessed" => :atime }
133
- key = sort_keys[key] if sort_keys.has_key? key
134
- #if key == @sort_key
135
- #reverse = true
136
- #end
137
- cdir=@current_path+"/"
138
- case key
139
- when :size
140
- @entries.sort! {|x,y| xs = File.stat(cdir+x); ys = File.stat(cdir+y);
141
- if reverse
142
- xs.size <=> ys.size
143
- else
144
- ys.size <=> xs.size
145
- end
146
- }
147
- when :mtime
148
- @entries.sort! {|x,y| xs = File.stat(cdir+x); ys = File.stat(cdir+y);
149
- if reverse
150
- xs.mtime <=> ys.mtime
151
- else
152
- ys.mtime <=> xs.mtime
153
- end
154
- }
155
- when :atime
156
- @entries.sort! {|x,y| xs = File.stat(cdir+x); ys = File.stat(cdir+y);
157
- if reverse
158
- xs.atime <=> ys.atime
159
- else
160
- ys.atime <=> xs.atime
161
- end
162
- }
163
- when :name
164
- @entries.sort! {|x,y| x <=> y
165
- if reverse
166
- x <=> y
167
- else
168
- y <=> x
169
- end
170
- }
171
- when :ext
172
- @entries.sort! {|x,y|
173
- if reverse
174
- File.extname(cdir+x) <=> File.extname(cdir+y)
175
- else
176
- File.extname(cdir+y) <=> File.extname(cdir+x)
177
- end
178
- }
179
- when :attr
180
- @entries.sort! {|x,y| xs = File.stat(cdir+x); ys = File.stat(cdir+y);
181
- x = xs.directory? ? "d" : "D"
182
- y = ys.directory? ? "d" : "D"
183
- if reverse
184
- x <=> y
185
- else
186
- y <=> x
187
- end
188
- }
189
- end
190
- @sort_key = key
191
- @entries.insert 0, first unless first.nil? # keep parent on top
192
- populate @entries
193
- end
194
- GIGA_SIZE = 1073741824.0
195
- MEGA_SIZE = 1048576.0
196
- KILO_SIZE = 1024.0
197
-
198
- # Return the file size with a readable style.
199
- def readable_file_size(size, precision)
200
- case
201
- #when size == 1 : "1 B"
202
- when size < KILO_SIZE then "%d B" % size
203
- when size < MEGA_SIZE then "%.#{precision}f K" % (size / KILO_SIZE)
204
- when size < GIGA_SIZE then "%.#{precision}f M" % (size / MEGA_SIZE)
205
- else "%.#{precision}f G" % (size / GIGA_SIZE)
206
- end
207
- end
208
- def date_format t
209
- t.strftime "%Y/%m/%d"
210
- end
211
-
212
- # on pressing Enter, execute this action.
213
- # Here we take the current file and if its a directory, we step into it.
214
- def fire_action_event
215
- if @_non_data_indices.include? @current_index
216
- Ncurses.error
217
- return
218
- end
219
- $log.debug "inside fire_action_event of directorylist #{@current_index} #{toprow} "
220
- if @_header_row_index == @current_index
221
- # user hit enter on the header row. we determine column and sort.
222
- header = _get_word_under_cursor
223
- #@reverse = false
224
- if header == @_last_header_sorted
225
- @reverse = !@reverse # clicking 2 times won't reverse again
226
- else
227
- @reverse = false
228
- end
229
- sort_by header.strip, @reverse
230
- # this next line will keep the cursor on header after sorting
231
- # earlier cursor would appear in header but selection would be data row
232
- @current_index = @_header_row_index # FFI 2011-09-16 keeping cursor synched with selection
233
- @_last_header_sorted = header
234
- set_form_row
235
- return
236
- end
237
- value = current_value
238
- value = value.split.last
239
- if value == ".."
240
- _path = File.dirname(@current_path)
241
- else
242
- _path = File.join(@current_path, value)
243
- end
244
- if File.directory? _path
245
- populate _path
246
- end
247
- $log.debug "after fire_action_event of directorylist #{@current_index} #{toprow} "
248
-
249
- super
250
- end
251
- def addcol num
252
- #@repaint_required = true
253
- @repaint_footer_required = true # 2010-01-23 22:41
254
- if @form
255
- @form.addcol num
256
- else
257
- @parent_component.form.addcol num
258
- end
259
- end
260
- # set cursor column position
261
- # if i set col1 to @curpos, i can move around left right if key mapped
262
- def set_form_col col1=@curpos
263
- col1 ||= 0
264
- @cols_panned ||= 0 # RFED16 2010-02-17 23:40
265
- win_col = 0 # 2010-02-17 23:19 RFED16
266
- col2 = win_col + @col + @col_offset + col1 + @cols_panned + @left_margin
267
- setrowcol nil, col2 # 2010-02-17 23:19 RFED16
268
- end
269
- def start_of_line
270
- @repaint_required = true if @pcol > 0 # tried other things but did not work
271
- set_form_col 0
272
- @pcol = 0
273
- end
274
- # this does not work, since the value in list is not the printed value
275
- def end_of_line
276
- blen = current_value.rstrip.length
277
- set_form_col blen
278
- end
279
-
280
- def cursor_backward
281
- repeatm {
282
- if @curpos > 0
283
- @curpos -= 1
284
- set_form_col
285
- #addcol -1
286
- elsif @pcol > 0
287
- @pcol -= 1
288
- end
289
- }
290
- #@repaint_required = true
291
- @repaint_footer_required = true # 2010-01-23 22:41
292
- end
293
-
294
-
295
- def cursor_forward
296
- @curpos ||= 0
297
- maxlen = @maxlen || @width-2
298
- repeatm {
299
- if @curpos < @width and @curpos < maxlen-1 # else it will do out of box
300
- @curpos += 1
301
- addcol 1
302
- else
303
- #@pcol += 1 if @pcol <= @buffer.length
304
- # buffer not eixstent FIXME
305
- end
306
- }
307
- set_form_col
308
- #@repaint_required = true
309
- @repaint_footer_required = true # 2010-01-23 22:41
310
- end
311
- def [](index)
312
- @entries[index]
313
- end
314
-
315
- @private
316
- def longest_line=(l)
317
- @longest_line = l
318
- end
319
- def longest_line
320
- @longest_line
321
- end
322
- # modify a file name.
323
- # call using 'C'
324
- def edit_line lineno=@current_index
325
- line = @list[lineno]
326
- fullname = File.join(@current_path, line)
327
- prompt = "Rename file [#{line}] to: "
328
- maxlen = 80
329
- config={};
330
- oldline = line.dup
331
- config[:default] = line
332
- ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
333
- $log.debug " rbgetstr returned #{ret} , #{str} "
334
- return if ret != 0
335
- @list[lineno].replace(str)
336
- FileUtils.mv fullname, File.join(@current_path, str)
337
- fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline)
338
- fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
339
- @repaint_required = true
340
- end
341
- def ask_select
342
- prompt = "Select Files: "
343
- maxlen = 80
344
- config={}
345
- config[:default] = @file_pattern if @file_pattern
346
- ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
347
- return if ret != 0
348
- @file_pattern = str
349
- # 2011-09-19 doesn't work if pwd changed
350
- if Dir.pwd != @current_path
351
- Dir.chdir @current_path
352
- end
353
- values = Dir.glob(str)
354
- $log.debug "ask select dir.glob got #{values} "
355
- select_values values unless values.empty?
356
- @repaint_required = true
357
- end
358
- def ask_unselect
359
- prompt = "Unselect Files: "
360
- maxlen = 80
361
- config={}
362
- config[:default] = @file_pattern if @file_pattern
363
- ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
364
- return if ret != 0
365
- @file_pattern = str
366
- if Dir.pwd != @current_path
367
- Dir.chdir @current_path
368
- end
369
- values = Dir.glob(str)
370
- unselect_values values unless values.empty?
371
- @repaint_required = true
372
- end
373
- def select_all
374
- # don't select header row
375
- add_row_selection_interval 1, row_count()
376
- end
377
- def invert_selection
378
- 1.upto(row_count()){|i| toggle_row_selection i }
379
- end
380
- # selects all rows with the values given, leaving existing selections
381
- # intact
382
- def select_values values
383
- return unless values
384
- values.each do |val|
385
- row = @list.index val
386
- add_row_selection_interval row, row unless row.nil?
387
- end
388
- end
389
- # unselects all rows with the values given, leaving all other rows intact
390
- def unselect_values values
391
- return unless values
392
- values.each do |val|
393
- row = @list.index val
394
- remove_row_selection_interval row, row unless row.nil?
395
- end
396
- end
397
- private
398
- # was meant to filter rows, but no point. since we can't undo the delete
399
- # so we just call populate again. this method could get axed
400
- def prune_entries
401
- #@entries.delete_if {|x| x =~ /^\./} if @hide_dot_files
402
- #@entries.delete_if {|x| x =~ /\.bak$/ || x=~/\.swp$/} if @hide_others
403
- populate @current_path
404
- set_form_row
405
- end
406
- def view_current
407
- file = self.current_value
408
- require 'rbcurse/extras/viewer.rb'
409
- RubyCurses::Viewer.view("#{current_path}/#{file}", :close_key => KEY_RETURN, :title => "<Enter> to close, M-l M-h to scroll")
410
- end
411
- # ADD HERE
412
- ##
413
- end # class
414
-
415
- ##
416
- # A cell renderer should not changed the length of a line otherwise scrolling etc goes for a toss.
417
- # The calling repaint method does trimming.
418
- #
419
- # A cell renderer can do small modifications, or color changing to data.
420
- # Here we should color directories or bak files or hidden files, swap files etc differently
421
- # Should this class do the trimming of data, else its hard to figure out what the extension
422
- # is if its trimeed out. But then it would have to handle the panning too.
423
- require 'rbcurse/listcellrenderer'
424
- class DirectoryListCellRenderer < ListCellRenderer
425
- #def initialize text="", config={}, &block
426
- #super
427
- #end
428
- # sets @color_pair and @attr
429
-
430
- ##
431
- # paint a list box cell
432
- # 2010-09-02 15:38 changed focussed to take true, false and :SOFT_FOCUS
433
- # SOFT_FOCUS means the form focus is no longer on this field, but this row
434
- # was focussed when use was last on this field. This row will take focus
435
- # when field is focussed again
436
- #
437
- # @param [Buffer] window or buffer object used for printing
438
- # @param [Fixnum] row
439
- # @param [Fixnum] column
440
- # @param [Fixnum] actual index into data, some lists may have actual data elsewhere and
441
- # display data separate. e.g. rfe_renderer (directory listing)
442
- # @param [String] text to print in cell
443
- # @param [Boolean, :SOFT_FOCUS] cell focussed, not focussed, cell focussed but field is not focussed
444
- # @param [Boolean] cell selected or not
445
- def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false
446
-
447
- prepare_default_colors focussed, selected
448
- if row_index == 0
449
- #nvalue = " %s %8s %19s %s %s " % value.split(",")
450
- graphic.printstring r, c, "%-s" % value, @color_pair,@attr
451
- else
452
- $log.debug " CELL XXX GTETING #{row_index} ,#{value}"
453
-
454
-
455
- # ensure we do not exceed
456
- if !@display_length.nil?
457
- if value.length > @display_length
458
- value = value[0..@display_length-1]
459
- end
460
- end
461
- len = @display_length || value.length
462
- graphic.printstring r, c, "%-*s" % [len, value], @color_pair,@attr
463
- end
464
- end
465
- end
466
- end # module
467
- # set filetype=ruby