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,69 +0,0 @@
1
- require 'rbcurse/rtree'
2
- #require 'forwardable'
3
- # we can extend from Tree but lets just try forwarding
4
- module RubyCurses
5
- # this class shows a tree of directories. Pressing ENTER expands or collapses
6
- # the node. Pressing ENTER selects a node.
7
- # Should we give options for displaying filenames also ? TODO
8
- class DirectoryTree < Tree
9
- attr_reader :selected_path
10
- #@t = tree :data => model, :height => ht, :border_attrib => borderattrib, :suppress_borders => true
11
- def _directories wd
12
- d = Dir.new(wd)
13
- ent = d.entries.reject{|e| !File.directory? File.join(wd,e)}
14
- ent.delete(".");ent.delete("..")
15
- return ent
16
- end
17
-
18
- def init_vars
19
- super
20
-
21
- one_key_selection = false
22
- bind :TREE_WILL_EXPAND_EVENT do |node|
23
- will_expand_action node
24
- end
25
-
26
- bind :TREE_SELECTION_EVENT do |ev|
27
- selection_event ev
28
- end
29
- end # init_v
30
-
31
- # populate this node with child directories
32
- # this gives user application a chance to override or extend this action
33
- def will_expand_action node
34
- path = File.join(*node.user_object_path)
35
- dirs = _directories path
36
- ch = node.children
37
- # add only children that may not be there
38
- ch.each do |e|
39
- o = e.user_object
40
- if dirs.include? o
41
- dirs.delete o
42
- else
43
- # delete this child since its no longer present TODO
44
- end
45
- end
46
- node.add dirs
47
- path_expanded path
48
- end
49
- # notify applications of path expanded so they may do any
50
- # related action
51
- # # NOTE: this is not the cleanest way, since you will need objects from your app
52
- # scope here. User will have to add objects into the config hash after object creation
53
- # and access them here. (See appdirtree.rb in examples)
54
- def path_expanded path
55
- end
56
- def selection_event ev
57
- if ev.state == :SELECTED
58
- node = ev.node
59
- path = File.join(*node.user_object_path)
60
- @selected_path = path
61
- selected_path_changed path
62
- end
63
- end
64
- # inform applications that path has changed
65
- # gives the user application a place to effect changes elsewhere in app
66
- def selected_path_changed path
67
- end
68
- end # class
69
- end
@@ -1,310 +0,0 @@
1
- require 'rbcurse/app'
2
- #include Ncurses # FFI 2011-09-8
3
- include RubyCurses
4
-
5
- # TODO : We can consider making it independent of objects, or allow for a margin so it does not write
6
- # over the object. Then it will be always visible.
7
- # TODO: if lists and tables, can without borders actually adjust then putting this independent
8
- # would make even more sense, since it won't eat an extra line.
9
- #
10
- # @example
11
- # lb = list_box ....
12
- # rb = Divider.new @form, :parent => lb, :side => :right
13
- #
14
- # At a later stage, we will integrate this with lists and tables, so it will happen automatically.
15
- #
16
- # @since 1.2.0
17
- module RubyCurses
18
- class DragEvent < Struct.new(:source, :type); end
19
-
20
- # This is a horizontal or vertical bar (like a scrollbar), at present attached to a
21
- # widget that is focusable, and allows user to press arrow keys.
22
- # It highlights on focus, the caller can expand and contract components in a container
23
- # or even screen, based on arrow movements. This allows for a visual resizing of components.
24
- # @example
25
- # lb = list_box ....
26
- # rb = Divider.new @form, :parent => lb, :side => :right
27
- #
28
- # NOTE: since this can be deactivated, containers need to check focusable before passing
29
- # focus in
30
- # 2010-10-07 23:56 made focusable false by default. Add divider to
31
- # FocusManager when creating, so F3 can be used to set focusable
32
- # See rvimsplit.rb for example
33
-
34
- class Divider < Widget
35
- # row to start, same as listbox, required.
36
- dsl_property :row
37
- # column to start, same as listbox, required.
38
- dsl_property :col
39
- # how many rows is this (should be same as listboxes height, required.
40
- dsl_property :length
41
- # vertical or horizontal currently only VERTICAL
42
- dsl_property :side
43
- # initialize based on parent's values
44
- dsl_property :parent
45
- # which row is focussed, current_index of listbox, required.
46
- # how many total rows of data does the list have, same as @list.length, required.
47
- dsl_accessor :next_component # 'next' bombing in dsl_accessor 2011-10-2 PLS CHANGE ELSEWHERE
48
-
49
- # TODO: if parent passed, we shold bind to ON_ENTER and get current_index, so no extra work is required.
50
-
51
- def initialize form, config={}, &block
52
-
53
- # setting default first or else Widget will place its BW default
54
- #@color, @bgcolor = ColorMap.get_colors_for_pair $bottomcolor
55
- super
56
- @height = 1
57
- @color_pair = get_color $datacolor, @color, @bgcolor
58
- @scroll_pair = get_color $bottomcolor, :green, :white
59
- #@window = form.window
60
- @editable = false
61
- # you can set to true upon creation, or use F3 on vimsplit to
62
- # toggle focusable
63
- @focusable = false
64
- @repaint_required = true
65
- @_events.push(:DRAG_EVENT)
66
- map_keys
67
- unless @parent
68
- raise ArgumentError, "row col and length should be provided" if !@row || !@col || !@length
69
- end
70
- #if @parent
71
- #@parent.bind :ENTER_ROW do |p|
72
- ## parent must implement row_count, and have a @current_index
73
- #raise StandardError, "Parent must implement row_count" unless p.respond_to? :row_count
74
- #self.current_index = p.current_index
75
- #@repaint_required = true #requred otherwise at end when same value sent, prop handler
76
- ## will not be fired (due to optimization).
77
- #end
78
- #end
79
- end
80
- def map_keys
81
- if !defined? $deactivate_dividers
82
- $deactivate_dividers = false
83
- end
84
- # deactivate only this bar
85
- bind_key(?f) {@focusable=false; }
86
- # deactivate all bars, i've had nuff!
87
- bind_key(?F) {deactivate_all(true)}
88
- end
89
-
90
- ##
91
- # repaint the scrollbar
92
- # Taking the data from parent as late as possible in case parent resized, or
93
- # moved around by a container.
94
- # NOTE: sometimes if this is inside another object, the divider repaints but then
95
- # is wiped out when that objects print_border is called. So such an obkect (e.g.
96
- # vimsplit) should call repaint after its has done its own repaint. that does mean
97
- # the repaint happens twice during movement
98
- def repaint
99
- woffset = 2
100
- coffset = 1
101
- if @parent
102
- woffset = 0 if @parent.suppress_borders
103
- @border_attrib ||= @parent.border_attrib
104
- case @side
105
- when :right
106
- @row = @parent.row+1
107
- @col = @parent.col + @parent.width - 0
108
- @length = @parent.height - woffset
109
- when :left
110
- @row = @parent.row+1
111
- @col = @parent.col+0 #+ @parent.width - 1
112
- @length = @parent.height - woffset
113
- when :top
114
- @row = @parent.row+0
115
- @col = @parent.col + @parent.col_offset #+ @parent.width - 1
116
- @length = @parent.width - woffset
117
- when :bottom
118
- @row = @parent.row+@parent.height-0 #1
119
- @col = @parent.col+@parent.col_offset #+ @parent.width - 1
120
- @length = @parent.width - woffset
121
- end
122
- else
123
- # row, col and length should be passed
124
- end
125
- my_win = @form ? @form.window : @target_window
126
- @graphic = my_win unless @graphic
127
- raise "graphic is nil in divider, perhaps form was nil when creating" unless @graphic
128
- return unless @repaint_required
129
-
130
- # first print a right side vertical line
131
- #bc = $bottomcolor # dark blue
132
- bc = $datacolor
133
- bordercolor = @border_color || bc
134
- borderatt = @border_attrib || Ncurses::A_REVERSE
135
- if @focussed
136
- bordercolor = $promptcolor || bordercolor
137
- end
138
-
139
- borderatt = convert_attrib_to_sym(borderatt) if borderatt.is_a? Symbol
140
-
141
- @graphic.attron(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
142
- $log.debug " XXX DIVIDER #{@row} #{@col} #{@length} "
143
- case @side
144
- when :right, :left
145
- @graphic.mvvline(@row, @col, 1, @length)
146
- when :top, :bottom
147
- @graphic.mvhline(@row, @col, 1, @length)
148
- end
149
- @graphic.attroff(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
150
- _paint_marker
151
- #alert "divider repaint at #{row} #{col} "
152
-
153
- @repaint_required = false
154
- end
155
- def convert_attrib_to_sym attr
156
- case attr
157
- when 'reverse'
158
- Ncurses::A_REVERSE
159
- when 'bold'
160
- Ncurses::A_BOLD
161
- when 'normal'
162
- Ncurses::A_NORMAL
163
- when 'blink'
164
- Ncurses::A_BLINK
165
- when 'underline'
166
- Ncurses::A_UNDERLINE
167
- else
168
- Ncurses::A_REVERSE
169
- end
170
- end
171
- # deactivate all dividers
172
- # The application has to provide a key or button to activate all
173
- # or just this one.
174
- def deactivate_all tf=true
175
- $deactivate_dividers = tf
176
- @focusable = !tf
177
- end
178
- def handle_key ch
179
- # all dividers have been deactivated
180
- if $deactivate_dividers || !@focusable
181
- @focusable = false
182
- return :UNHANDLED
183
- end
184
- case @side
185
- when :right, :left
186
- case ch
187
- when KEY_RIGHT
188
- fire_handler :DRAG_EVENT, DragEvent.new(self, ch)
189
- when KEY_LEFT
190
- fire_handler :DRAG_EVENT, DragEvent.new(self, ch)
191
- else
192
- ret = process_key ch, self
193
- return ret if ret == :UNHANDLED
194
- end
195
- set_form_col
196
- when :top, :bottom
197
- case ch
198
- when KEY_UP
199
- fire_handler :DRAG_EVENT, DragEvent.new(self, ch)
200
- when KEY_DOWN
201
- fire_handler :DRAG_EVENT, DragEvent.new(self, ch)
202
- else
203
- ret = process_key ch, self
204
- return ret if ret == :UNHANDLED
205
- end
206
- set_form_col
207
- else
208
- end
209
- @repaint_required = true
210
- return 0
211
- end
212
- def on_enter
213
- if $deactivate_dividers || !@focusable
214
- @focusable = false
215
- return :UNHANDLED
216
- end
217
- # since it is over border of component, we need to repaint
218
- @focussed = true
219
- @repaint_required = true
220
- repaint
221
- end
222
- def on_leave
223
- @focussed = false
224
- @repaint_required = true
225
- repaint
226
- # TODO: we should review this since its not over the parent any longer
227
- if @parent
228
- # since it is over border of component, we need to clear
229
- @parent.repaint_required
230
- # if we don't paint now, parent paints over other possible dividers
231
- @parent.repaint
232
- end
233
- end
234
- def set_form_row
235
- return unless @focusable
236
- r,c = rowcol
237
- setrowcol r, c
238
- end
239
- # set the cursor on first point of bar
240
- def set_form_col
241
- return unless @focusable
242
- # need to set it to first point, otherwise it could be off the widget
243
- r,c = rowcol
244
- setrowcol r, c
245
- end
246
- # is this a vertical divider
247
- def v?
248
- @side == :top || @side == :bottom
249
- end
250
- # is this a horizontal divider
251
- def h?
252
- @side == :right || @side == :left
253
- end
254
- private
255
- def _paint_marker #:nodoc:
256
- r,c = rowcol
257
- if @focussed
258
- @graphic.mvwaddch r,c, Ncurses::ACS_DIAMOND
259
- if v?
260
- @graphic.mvwaddch r,c+1, Ncurses::ACS_UARROW
261
- @graphic.mvwaddch r,c+2, Ncurses::ACS_DARROW
262
- else
263
- @graphic.mvwaddch r+1,c, Ncurses::ACS_LARROW
264
- @graphic.mvwaddch r+2,c, Ncurses::ACS_RARROW
265
- end
266
- else
267
- #@graphic.mvwaddch r,c, Ncurses::ACS_CKBOARD
268
- end
269
- end
270
- ##
271
- ##
272
- # ADD HERE
273
- end # class
274
- end # module
275
- if __FILE__ == $PROGRAM_NAME
276
- App.new do
277
- r = 5
278
- len = 20
279
- list = []
280
- 0.upto(100) { |v| list << "#{v} scrollable data" }
281
- lb = list_box "A list", :list => list, :row => 2, :col => 2
282
- #sb = Scrollbar.new @form, :row => r, :col => 20, :length => len, :list_length => 50, :current_index => 0
283
- rb = Divider.new @form, :parent => lb, :side => :right
284
- rb.bind :DRAG_EVENT do |e|
285
- message "got an event #{e.type} "
286
- case e.type
287
- when KEY_RIGHT
288
- lb.width += 1
289
- when KEY_LEFT
290
- lb.width -= 1
291
- end
292
- lb.repaint_required
293
- end
294
- rb1 = Divider.new @form, :parent => lb, :side => :bottom
295
- rb.focusable(true)
296
- rb1.focusable(true)
297
- rb1.bind :DRAG_EVENT do |e|
298
- message " 2 got an event #{e.type} "
299
- end
300
- #hline :width => 20, :row => len+r
301
- #keypress do |ch|
302
- #case ch
303
- #when :down
304
- #sb.current_index += 1
305
- #when :up
306
- #sb.current_index -= 1
307
- #end
308
- #end
309
- end
310
- end
@@ -1,31 +0,0 @@
1
- # Allow some objects to take focus when a certain key is pressed.
2
- # This is for objects like scrollbars and grabbars. We don't want these always
3
- # getting focus, only sometimes when we want to resize panes.
4
- # This will not only be included by Form but by containers such as Vimsplit
5
- # or MasterDetail.
6
- # Usage: the idea is that when you create grabbars, you would add them to the FocusManager
7
- # Thus they would remain non-focusable on creation. When hte user presses (say F3) then
8
- # make_focusable is called, or toggle_focusable. Now user can press TAB and access
9
- # these bars. When he is done he can toggle again.
10
- # TODO: we might add a Circular class here so user can traverse only these objects
11
- module RubyCurses
12
- module FocusManager
13
- extend self
14
- attr_reader :focusables
15
- # add a component to this list so it can be made focusable later
16
- def add component
17
- @focusables ||= []
18
- @focusables << component
19
- self
20
- end
21
- def make_focusable bool=true
22
- @focusing = bool
23
- @focusables.each { |e| e.focusable(bool) }
24
- end
25
- def toggle_focusable
26
- return unless @focusables
27
- alert "FocusManager Making #{@focusables.length} objects #{!@focusing} "
28
- make_focusable !@focusing
29
- end
30
- end
31
- end
@@ -1,203 +0,0 @@
1
- require 'rbcurse'
2
-
3
- # This is a horizontal scroller, to scroll a list of options much like
4
- # vim often does on the statusline. I'd like to use it for scrolling
5
- # menus or buttons like on TabbedPanes to avoid another Form.
6
-
7
- # You may bind to the ENTER_ROW event to chagne some data elsewhere,
8
- # or the PRESS event. In this case, PRESS will refer to pressing the
9
- # space bar or ENTER. There is <em>no</em> LIST_SELECTION event for that.
10
-
11
-
12
-
13
- module RubyCurses
14
-
15
- # Horizontal list scrolling and selection.
16
- #
17
- # == Example
18
- # require 'rbcurse/extras/horizlist'
19
- # require 'fileutils'
20
- # l = HorizList.new @form, :row => 5, :col => 5, :width => 80
21
- # list = Dir.glob("*")
22
- # l.list(list)
23
-
24
- class HorizList < Widget
25
-
26
- def initialize form, config={}, &block
27
- super
28
- @_events.push(*[:ENTER_ROW, :LEAVE_ROW, :PRESS])
29
- @focusable = true
30
- init_vars
31
- @list = []
32
- @toprow = 0
33
-
34
- # last printed index
35
- @last_index = 0
36
-
37
- # item on which cursor is
38
- @current_index = 0
39
- end
40
- def init_vars
41
- end
42
- # alias :text :getvalue # NEXT VERSION
43
-
44
- def map_keys
45
- @keys_mapped = true
46
- bind_keys([KEY_RIGHT, ?l, ?.], :next_item)
47
- bind_keys([KEY_LEFT, ?h,?,], :previous_item)
48
- bind_keys([10,13,32]){ fire_action_event }
49
- bind_keys([?\M-l,?>, KEY_DOWN], :scroll_right)
50
- bind_keys([?\M-h,?<, KEY_UP], :scroll_left)
51
- end
52
- def list(strings)
53
- @list = strings
54
- end
55
- def add item
56
- @list << item
57
- end
58
- def repaint
59
- return unless @repaint_required
60
- @window ||= @form.window
61
- $log.debug "XXX:HORIZ REPAINT Ci #{@current_index}, TR #{@toprow} "
62
- $status_message.value = " #{@current_index}, TR #{@toprow} "
63
- @window.printstring @row, @col, " "* @width, @color_pair || $reversecolor
64
- c = @col + 1
65
- t = @toprow
66
- @list.each_with_index { |e, i|
67
- next if i < t # sucks for large lists
68
- break if c + e.length >= @width + @col
69
- att = @attrib || FFI::NCurses::A_NORMAL
70
- if i == @current_index
71
- att = FFI::NCurses::A_REVERSE if i == @current_index
72
- acolor = @focussed_color_pair || get_color($datacolor,'green', 'white')
73
- else
74
- acolor = @color_pair
75
- end
76
- @window.printstring @row, c, e, acolor || $reversecolor, att
77
- c += e.length + 2
78
- @last_index = i
79
- break if c >= @width + @col
80
- }
81
- @repaint_required = false
82
- end
83
- def handle_key ch
84
- map_keys unless @keys_mapped
85
- ret = process_key ch, self
86
- @multiplier = 0
87
- return :UNHANDLED if ret == :UNHANDLED
88
- end
89
- def previous_item num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
90
-
91
- return :NO_PREVIOUS_ROW if @current_index == 0
92
- @old_toprow = @toprow
93
- @oldrow = @current_index
94
- @current_index -= num
95
- @current_index = 0 if @current_index < 0
96
- bounds_check
97
- $multiplier = 0
98
- if @current_index < @toprow
99
- @toprow = @current_index
100
- end
101
- @toprow = 0 if @toprow < 0
102
- @repaint_required = true
103
- end
104
- def next_item num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
105
- rc = row_count
106
- return :NO_NEXT_ROW if @current_index == rc-1 # changed 2011-10-5 so process can do something
107
- @old_toprow = @toprow
108
- @oldrow = @current_index
109
- @current_index += num
110
- @current_index = rc - 1 if @current_index >= rc
111
- @toprow = @current_index if @current_index > @last_index
112
- bounds_check
113
- $multiplier = 0
114
- @repaint_required = true
115
- end
116
- def scroll_right
117
- rc = row_count
118
- return :NO_NEXT_ROW if @current_index == rc-1 # changed 2011-10-5 so process can do something
119
- @old_toprow = @toprow
120
- @oldrow = @current_index
121
-
122
- @current_index = @last_index + 1
123
-
124
- @current_index = rc - 1 if @current_index >= rc
125
- @toprow = @current_index if @current_index > @last_index
126
- bounds_check
127
- $multiplier = 0
128
- @repaint_required = true
129
- end
130
- def scroll_left
131
- return :NO_PREVIOUS_ROW if @current_index == 0
132
- @old_toprow = @toprow
133
- @oldrow = @current_index
134
- @current_index = @toprow - 4
135
- @current_index = 0 if @current_index < 0
136
- bounds_check
137
- $multiplier = 0
138
- if @current_index < @toprow
139
- @toprow = @current_index
140
- end
141
- @toprow = 0 if @toprow < 0
142
- @repaint_required = true
143
- end
144
- def row_count; @list.size; end
145
- def bounds_check
146
- @row_changed = false
147
- if @oldrow != @current_index
148
- on_leave_row @oldrow if respond_to? :on_leave_row # to be defined by widget that has included this
149
- on_enter_row @current_index if respond_to? :on_enter_row # to be defined by widget that has included this
150
- set_form_row
151
- @row_changed = true
152
- end
153
- if @old_toprow != @toprow # only if scrolling has happened should we repaint
154
- @repaint_required = true
155
- @widget_scrolled = true
156
- end
157
- end
158
- def on_enter
159
- if @list.nil? || @list.size == 0
160
- Ncurses.beep
161
- return :UNHANDLED
162
- end
163
- super
164
- on_enter_row @current_index
165
- set_form_row
166
- true
167
- end
168
- def on_enter_row arow
169
- fire_handler :ENTER_ROW, self
170
- @repaint_required = true
171
- end
172
- def on_leave_row arow
173
- fire_handler :LEAVE_ROW, self
174
- end
175
- def fire_action_event
176
- require 'rbcurse/ractionevent'
177
- fire_handler :PRESS, ActionEvent.new(self, :PRESS, text)
178
- end
179
- def current_value
180
- @list[@current_index]
181
- end
182
- alias :text :current_value
183
- ##
184
- end # class
185
- end # module
186
- if __FILE__ == $PROGRAM_NAME
187
- require 'rbcurse/app'
188
-
189
- App.new do
190
- require 'rbcurse/extras/horizlist'
191
- require 'fileutils'
192
- l = HorizList.new @form, :row => 5, :col => 5, :width => 80
193
- list = Dir.glob("*")
194
- l.list(list)
195
- l.bind(:PRESS){ |eve| alert "You pressed #{eve.text} " }
196
- sl = status_line
197
- sl.command do
198
- " Status: #{$status_message} "
199
- end
200
- end
201
-
202
-
203
- end