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,27 +0,0 @@
1
- =begin
2
- * Name: ChangeEvent
3
- * Description: Event used to notify interested parties that state of component has changed
4
- * Author: rkumar (arunachalesha)
5
-
6
- --------
7
- * Date: 2010-02-26 11:32
8
- * License:
9
- Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
10
-
11
- =end
12
-
13
- # Event created when state changed (as in ViewPort)
14
- module RubyCurses
15
- class ChangeEvent
16
- attr_accessor :source
17
- def initialize source
18
- @source = source
19
- end
20
- def to_s
21
- inspect
22
- end
23
- def inspect
24
- "ChangeEvent #{@source}"
25
- end
26
- end
27
- end
@@ -1,238 +0,0 @@
1
- # ----------------------------------------------------------------------------- #
2
- # File: rcombo.rb
3
- # Description: Non-editable combo box.
4
- # Make it dead-simple to use.
5
- # This is a simpler version of the original ComboBox which allowed
6
- # editing and used rlistbox. This simpler class is meant for the rbcurse
7
- # core package and will only depend on a core class if at all.
8
- # Author: rkumar http://github.com/rkumar/rbcurse/
9
- # Date: 2011-11-11 - 21:42
10
- # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
11
- # Last update: use ,,L
12
- # ----------------------------------------------------------------------------- #
13
- #
14
- require 'rbcurse'
15
-
16
- include RubyCurses
17
- module RubyCurses
18
- extend self
19
-
20
- # the quick approach would be to use field, and just add a popup.
21
- # Or since we are not editing, we could use a Label and a popup
22
- # Or just display a label and a popup without using anything else.
23
- #
24
-
25
- class ComboBox < Field
26
- include RubyCurses::EventHandler
27
- dsl_accessor :list_config
28
-
29
- attr_accessor :current_index
30
- # the symbol you want to use for combos
31
- attr_accessor :COMBO_SYMBOL
32
- attr_accessor :show_symbol # show that funny symbol after a combo to signify its a combo
33
- dsl_accessor :arrow_key_policy # :IGNORE :NEXT_ROW :POPUP
34
-
35
- def initialize form, config={}, &block
36
- @arrow_key_policy = :ignore
37
- @editable = false
38
- @COMBO_SYMBOL = "v".ord # trying this out
39
- @current_index = 0
40
- super
41
- # added if check since it was overriding set_buffer in creation. 2009-01-18 00:03
42
- set_buffer @list[@current_index].dup if @buffer.nil? or @buffer.empty?
43
- init_vars
44
- @_events.push(*[:CHANGE, :ENTER_ROW, :LEAVE_ROW])
45
- end
46
- def init_vars
47
- super
48
- @show_symbol = true if @show_symbol.nil? # if set to false don't touch
49
- #@show_symbol = false if @label # 2011-11-13
50
- @COMBO_SYMBOL ||= FFI::NCurses::ACS_DARROW #GEQUAL
51
- bind_key(KEY_UP) { previous_row }
52
- bind_key(KEY_DOWN) { next_row }
53
- end
54
- def selected_item
55
- @list[@current_index]
56
- end
57
- def selected_index
58
- @current_index
59
- end
60
-
61
- ##
62
- # convert given list to datamodel
63
- def list alist=nil
64
- return @list if alist.nil?
65
- #@list = RubyCurses::ListDataModel.new(alist)
66
- @list = alist
67
- end
68
- ##
69
- # combo edit box key handling
70
- # removed UP and DOWN and bound it, so it can be unbound
71
- def handle_key(ch)
72
- @current_index ||= 0
73
- # added 2009-01-18 22:44 no point moving horiz or passing up to Field if not edit
74
- if !@editable
75
- if ch == KEY_LEFT or ch == KEY_RIGHT
76
- return :UNHANDLED
77
- end
78
- end
79
- case @arrow_key_policy
80
- when :ignore
81
- if ch == KEY_DOWN or ch == KEY_UP
82
- return :UNHANDLED
83
- end
84
- when :popup
85
- if ch == KEY_DOWN or ch == KEY_UP
86
- popup
87
- end
88
- end
89
- case ch
90
- #when KEY_UP # show previous value
91
- # previous_row
92
- #when KEY_DOWN # show previous value
93
- # next_row
94
- # adding spacebar to popup combo, as in microemacs 2010-10-01 13:21
95
- when 32, KEY_DOWN+ META_KEY # alt down
96
- popup # pop up the popup
97
- else
98
- super
99
- end
100
- end
101
- def DEPprevious_row
102
- @current_index -= 1 if @current_index > 0
103
- set_buffer @list[@current_index].dup
104
- set_modified(true) ## ??? not required
105
- fire_handler :ENTER_ROW, self
106
- @list.on_enter_row self
107
- end
108
- def DEPnext_row
109
- @current_index += 1 if @current_index < @list.length()-1
110
- set_buffer @list[@current_index].dup
111
- set_modified(true) ## ??? not required
112
- fire_handler :ENTER_ROW, self
113
- @list.on_enter_row self
114
- end
115
- ##
116
- # calls a popup list
117
- # TODO: should not be positioned so that it goes off edge
118
- # user's customizations of list should be passed in
119
- # The dup of listconfig is due to a tricky feature/bug.
120
- # I try to keep the config hash and instance variables in synch. So
121
- # this config hash is sent to popuplist which updates its row col and
122
- # next time we pop up the popup row and col are zero.
123
- #
124
- #
125
- # added dup in PRESS since editing edit field mods this
126
- # on pressing ENTER, value set back and current_index updated
127
- def popup
128
- @list_config ||= {}
129
- @list_config[:row] ||= @row
130
- @list_config[:col] ||= @col
131
- @list_config[:relative_to] ||= self
132
- # this does not allow us to bind to events in the list
133
- index = popuplist @list, @list_config
134
- if index
135
- set_buffer @list[index].dup
136
- set_modified(true) if @current_index != index
137
- @current_index = index
138
- end
139
- end
140
- def OLDpopup
141
- listconfig = (@list_config && @list_config.dup) || {}
142
- dm = @list
143
- # current item in edit box will be focussed when list pops up
144
- #$log.debug "XXX POPUP: #{dm.selected_index} = #{@current_index}, value #{@buffer}"
145
- # we are having some problms when using this in a list. it retains earlier value
146
- _index = dm.index @buffer
147
- dm.selected_index = _index # @current_index
148
- poprow = @row+0 # one row below the edit box
149
- popcol = @col
150
- dlength = @display_length
151
- f = self
152
- @popup = RubyCurses::PopupList.new do
153
- row poprow
154
- col popcol
155
- width dlength
156
- list_data_model dm
157
- list_selection_mode 'single'
158
- relative_to f
159
- list_config listconfig
160
- bind(:PRESS) do |index|
161
- f.set_buffer dm[index].dup
162
- f.set_modified(true) if f.current_index != index
163
- f.current_index = index
164
- end
165
- end
166
- end
167
-
168
- # Field putc advances cursor when it gives a char so we override this
169
- def putc c
170
- if c >= 0 and c <= 127
171
- ret = putch c.chr
172
- if ret == 0
173
- addcol 1 if @editable
174
- set_modified
175
- end
176
- end
177
- return -1 # always ??? XXX
178
- end
179
- ##
180
- # field does not give char to non-editable fields so we override
181
- def putch char
182
- @current_index ||= 0
183
- if @editable
184
- super
185
- return 0
186
- else
187
- match = next_match(char)
188
- set_buffer match unless match.nil?
189
- fire_handler :ENTER_ROW, self
190
- end
191
- @modified = true
192
- fire_handler :CHANGE, self # 2008-12-09 14:51 ???
193
- 0
194
- end
195
- ##
196
- # the sets the next match in the edit field
197
- def next_match char
198
- start = @current_index
199
- start.upto(@list.length-1) do |ix|
200
- if @list[ix][0,1].casecmp(char) == 0
201
- return @list[ix] unless @list[ix] == @buffer
202
- end
203
- @current_index += 1
204
- end
205
- ## could not find, start from zero
206
- @current_index = 0
207
- start = [@list.length()-1, start].min
208
- 0.upto(start) do |ix|
209
- if @list[ix][0,1].casecmp(char) == 0
210
- return @list[ix] unless @list[ix] == @buffer
211
- end
212
- @current_index += 1
213
- end
214
- @current_index = [@list.length()-1, @current_index].min
215
- return nil
216
- end
217
- ##
218
- # on leaving the listbox, update the combo/datamodel.
219
- # we are using methods of the datamodel. Updating our list will have
220
- # no effect on the list, and wont trigger events.
221
- # Do not override.
222
- def on_leave
223
- fire_handler :LEAVE, self
224
- end
225
-
226
- def repaint
227
- super
228
- c = @col + @display_length
229
- if @show_symbol # 2009-01-11 18:47
230
- # i have changed c +1 to c, since we have no right to print beyond display_length
231
- @form.window.mvwaddch @row, c, @COMBO_SYMBOL # Ncurses::ACS_GEQUAL
232
- @form.window.mvchgat(y=@row, x=c, max=1, Ncurses::A_REVERSE|Ncurses::A_UNDERLINE, $datacolor, nil)
233
- end
234
- end
235
-
236
- end # class ComboBox
237
-
238
- end # module
@@ -1,587 +0,0 @@
1
- =begin
2
- * Name: rcommandwindow: pops up a status message at bottom of screen
3
- creating a new window, so we don't have to worry about having window
4
- handle.
5
- Can use with say, ask etc. wsay wask wagree etc !
6
- * Description
7
- * Author: rkumar (arunachalesha)
8
- * Date: 2008-11-19 12:49
9
- * License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
10
- * file separated on 2009-01-13 22:39
11
-
12
- =end
13
- require 'rbcurse'
14
-
15
- module RubyCurses
16
- ##
17
- #
18
- #
19
- class CommandWindow
20
- include RubyCurses::Utils
21
- dsl_accessor :box
22
- dsl_accessor :title
23
- attr_reader :config
24
- attr_reader :layout
25
- attr_reader :window # required for keyboard or printing
26
- dsl_accessor :height, :width, :top, :left # 2009-01-06 00:05 after removing meth missing
27
-
28
- def initialize form=nil, aconfig={}, &block
29
- @config = aconfig
30
- @config.each_pair { |k,v| instance_variable_set("@#{k}",v) }
31
- instance_eval &block if block_given?
32
- if @layout.nil?
33
- set_layout(1,80, -1, 0)
34
- end
35
- @height = @layout[:height]
36
- @width = @layout[:width]
37
- @window = VER::Window.new(@layout)
38
- @start = 0 # row for display of text with paging
39
- @list = []
40
- require 'forwardable'
41
- require 'rbcurse/extras/bottomline'
42
- @bottomline = Bottomline.new @window, 0
43
- @bottomline.name = "rcommandwindow's bl"
44
- extend Forwardable
45
- def_delegators :@bottomline, :ask, :say, :agree, :choose #, :display_text_interactive
46
- if @box == :border
47
- @window.box 0,0
48
- elsif @box
49
- @window.attron(Ncurses.COLOR_PAIR($normalcolor) | Ncurses::A_REVERSE)
50
- @window.mvhline 0,0,1,@width
51
- @window.printstring 0,0,@title, $normalcolor #, 'normal' if @title
52
- @window.attroff(Ncurses.COLOR_PAIR($normalcolor) | Ncurses::A_REVERSE)
53
- else
54
- #@window.printstring 0,0,@title, $normalcolor, 'reverse' if @title
55
- title @title
56
- end
57
- @window.wrefresh
58
- @panel = @window.panel
59
- Ncurses::Panel.update_panels
60
- @window.wrefresh
61
- @row_offset = 0
62
- if @box
63
- @row_offset = 1
64
- end
65
- end
66
- # modify the window title, or get it if no params passed.
67
- def title t=nil
68
- return @title unless t
69
- @title = t
70
- @window.printstring 0,0,@title, $normalcolor, 'reverse' if @title
71
- end
72
- ##
73
- ## message box
74
- def stopping?
75
- @stop
76
- end
77
- # todo handle mappings, so user can map keys TODO
78
- def handle_keys
79
- begin
80
- while((ch = @window.getchar()) != 999 )
81
- case ch
82
- when -1
83
- next
84
- else
85
- press ch
86
- break if @stop
87
- yield ch if block_given?
88
- end
89
- end
90
- ensure
91
- destroy
92
- end
93
- return #@selected_index
94
- end
95
- # handles a key, commandline
96
- def press ch
97
- ch = ch.getbyte(0) if ch.class==String ## 1.9
98
- $log.debug " XXX press #{ch} " if $log.debug?
99
- case ch
100
- when -1
101
- return
102
- when KEY_F1, 27, ?\C-q.getbyte(0)
103
- @stop = true
104
- return
105
- when KEY_ENTER, 10, 13
106
- #$log.debug "popup ENTER : #{@selected_index} "
107
- #$log.debug "popup ENTER : #{field.name}" if !field.nil?
108
- @stop = true
109
- return
110
- when ?\C-d.getbyte(0)
111
- @start += @height-1
112
- bounds_check
113
- when KEY_UP
114
- @start -= 1
115
- @start = 0 if @start < 0
116
- when KEY_DOWN
117
- @start += 1
118
- bounds_check
119
- when ?\C-b.getbyte(0)
120
- @start -= @height-1
121
- @start = 0 if @start < 0
122
- when 0
123
- @start = 0
124
- end
125
- Ncurses::Panel.update_panels();
126
- Ncurses.doupdate();
127
- @window.wrefresh
128
- end
129
- # might as well add more keys for paging.
130
- def configure(*val , &block)
131
- case val.size
132
- when 1
133
- return @config[val[0]]
134
- when 2
135
- @config[val[0]] = val[1]
136
- instance_variable_set("@#{val[0]}", val[1])
137
- end
138
- instance_eval &block if block_given?
139
- end
140
- def cget param
141
- @config[param]
142
- end
143
-
144
- def set_layout(height=0, width=0, top=0, left=0)
145
- # negative means top should be n rows from last line. -1 is last line
146
- if top < 0
147
- top = Ncurses.LINES-top
148
- end
149
- @layout = { :height => height, :width => width, :top => top, :left => left }
150
- @height = height
151
- @width = width
152
- end
153
- def destroy
154
- $log.debug "DESTROY : rcommandwindow"
155
- if @window
156
- begin
157
- panel = @window.panel
158
- Ncurses::Panel.del_panel(panel.pointer) if panel
159
- @window.delwin
160
- rescue => exc
161
- end
162
- end
163
- end
164
- #
165
- # Displays list in a window at bottom of screen, if large then 2 or 3 columns.
166
- # @param [Array] list of string to be displayed
167
- # @param [Hash] configuration options: indexing and indexcolor
168
- # indexing - can be letter or number. Anything else will be ignored, however
169
- # it will result in first letter being highlighted in indexcolor
170
- # indexcolor - color of mnemonic, default green
171
- def display_menu list, options={}
172
- indexing = options[:indexing]
173
- indexcolor = options[:indexcolor] || get_color($normalcolor, :yellow, :black)
174
- indexatt = Ncurses::A_BOLD
175
- #
176
- # the index to start from (used when scrolling a long menu such as file list)
177
- startindex = options[:startindex] || 0
178
-
179
- max_cols = 3 # maximum no of columns, we will reduce based on data size
180
- l_succ = "`"
181
- act_height = @height
182
- if @box
183
- act_height = @height - 2
184
- end
185
- lh = list.size
186
- if lh < act_height
187
- $log.debug "DDD inside one window" if $log.debug?
188
- list.each_with_index { |e, i|
189
- text = e
190
- case e
191
- when Array
192
- text = e.first + " ..."
193
- end
194
- if indexing == :number
195
- mnem = i+1
196
- text = "%d. %s" % [i+1, text]
197
- elsif indexing == :letter
198
- mnem = l_succ.succ!
199
- text = "%s. %s" % [mnem, text]
200
- end
201
- @window.printstring i+@row_offset, 1, text, $normalcolor
202
- if indexing
203
- window.mvchgat(y=i+@row_offset, x=1, max=1, indexatt, indexcolor, nil)
204
- end
205
- }
206
- else
207
- $log.debug "DDD inside two window" if $log.debug?
208
- row = 0
209
- h = act_height
210
- cols = (lh*1.0 / h).ceil
211
- cols = max_cols if cols > max_cols
212
- # sometimes elements are large like directory paths, so check size
213
- datasize = list.first.length
214
- if datasize > @width/3 # keep safety margin since checking only first row
215
- cols = 1
216
- elsif datasize > @width/2
217
- cols = [2,cols].min
218
- end
219
- adv = (@width/cols).to_i
220
- colct = 0
221
- col = 1
222
- $log.debug "DDDcols #{cols}, adv #{adv} size: #{lh} h: #{act_height} w #{@width} " if $log.debug?
223
- list.each_with_index { |e, i|
224
- text = e
225
- # signify that there's a deeper level
226
- case e
227
- when Array
228
- text = e.first + "..."
229
- end
230
- if indexing == :number
231
- mnem = i+1
232
- text = "%d. %s" % [mnem, text]
233
- elsif indexing == :letter
234
- mnem = l_succ.succ!
235
- text = "%s. %s" % [mnem, text]
236
- end
237
- # print only within range and window height
238
- if i >= startindex && row < @window.actual_height
239
- $log.debug "XXX: MENU #{i} > #{startindex} row #{row} col #{col} "
240
- @window.printstring row+@row_offset, col, text, $normalcolor
241
- if indexing
242
- @window.mvchgat(y=row+@row_offset, x=col, max=1, indexatt, indexcolor, nil)
243
- end
244
- colct += 1
245
- if colct == cols
246
- col = 1
247
- row += 1
248
- colct = 0
249
- else
250
- col += adv
251
- end
252
- end # startindex
253
- }
254
- end
255
- Ncurses::Panel.update_panels();
256
- Ncurses.doupdate();
257
- @window.wrefresh
258
- end
259
- # refresh whatevers painted onto the window
260
- def refresh
261
- Ncurses::Panel.update_panels();
262
- Ncurses.doupdate();
263
- @window.wrefresh
264
- end
265
- # clears the window, leaving the title line as is, from row 1 onwards
266
- def clear
267
- @window.wmove 1,1
268
- @window.wclrtobot
269
- @window.box 0,0 if @box == :border
270
- # lower line of border will get erased currently since we are writing to
271
- # last line FIXME
272
- end
273
- def display_interactive text, config={}
274
- if @to
275
- @to.content text
276
- else
277
- config[:box] = @box
278
- @to = ListObject.new self, text, config
279
- end
280
- yield @to if block_given?
281
- @to.display_interactive # this returns the item selected
282
- @to # this will return the ListObject to the user with list and current_index
283
- end
284
- # non interactive list display - EACH CALL IS CREATING A LIST OBJECT
285
- def udisplay_list text, config={}
286
- if @to
287
- @to.content text
288
- else
289
- config[:box] = @box
290
- @to = ListObject.new self, text, config
291
- end
292
- #@to ||= ListObject.new self, text, config
293
- yield @to if block_given?
294
- @to.display_content
295
- @to
296
- end
297
- # displays a list
298
- class ListObject
299
- attr_reader :cw
300
- attr_reader :list
301
- attr_reader :current_index
302
- attr_accessor :focussed_attrib
303
- attr_accessor :focussed_symbol
304
- def initialize cw, _list, config={}
305
- @cw = cw
306
- layout = @cw.layout
307
- @window = @cw.window
308
- @height = layout[:height]
309
- @width = layout[:width]
310
- content(_list)
311
- @height_adjust = config.fetch(:box, true) == :border ? 3 : 2
312
- @selected_index = nil
313
- @current_index = 0
314
- @row_offset = 1
315
- @toprow = 0
316
- $multiplier = 0 # till we can do something
317
-
318
- @focussed_symbol = ''
319
- @row_selected_symbol = ''
320
- #@show_selector = true
321
- if @show_selector
322
- @row_selected_symbol ||= '*'
323
- @row_unselected_symbol ||= ' '
324
- @left_margin ||= @row_selected_symbol.length
325
- end
326
- #@show_selector = true
327
- #@row_selected_symbol = '*'
328
- #@row_unselected_symbol = ' '
329
- end
330
- def content txt, config={}
331
- @current_index = 0 # sometimes it gets left at a higher value than there are rows to show
332
- case txt
333
- when String
334
- txt = wrap_text(txt, @width-2).split("\n")
335
- when Array
336
- # okay
337
- end
338
- @list = txt
339
- end
340
- # maybe we should just use a textview or label rather than try to
341
- # do it all voer again !
342
- def display_interactive
343
- display_content
344
- while !@stop
345
- @window.wrefresh # FFI 2011-09-12
346
- # FIXME only clear and redisplay if change has happened (repaint_require)
347
- handle_keys { |ch| @cw.clear; display_content }
348
- end
349
- return @list[@current_index]
350
- end
351
- def is_row_selected row
352
- @selected_index == row
353
- end
354
-
355
- def scrollatrow
356
- @height - 3
357
- end
358
- def row_count
359
- @list.size
360
- end
361
- def rowcol
362
- return @row_offset, @col_offset
363
- end
364
- def display_content #:nodoc:
365
-
366
- @graphic = @window
367
- @start ||= 0
368
- @toprow ||= 0
369
- @left_margin ||= @row_selected_symbol.length + @focussed_symbol.length
370
-
371
- #print_borders unless @suppress_borders # do this once only, unless everything changes
372
- #maxlen = @maxlen ||= @width-2
373
- tm = @list
374
- rc = tm.size
375
- @col_offset = 1
376
- #@longest_line = @width
377
- if rc > 0 # just added in case no data passed
378
- #tr = @start #@toprow
379
- tr = @toprow
380
- acolor = get_color $datacolor
381
- #h = @height - 3 #2
382
- h = @height - @height_adjust
383
- r,c = @row_offset, @col_offset
384
- 0.upto(h) do |hh|
385
- crow = tr+hh
386
- if crow < rc
387
- focussed = @current_index == crow # row focussed ?
388
- selected = is_row_selected crow
389
- content = tm[crow] # 2009-01-17 18:37 chomp giving error in some cases says frozen
390
- # by now it has to be a String
391
- ## set the selector symbol if requested
392
- selection_symbol = ''
393
- if @show_selector
394
- if selected
395
- selection_symbol = @row_selected_symbol
396
- else
397
- selection_symbol = @row_unselected_symbol
398
- end
399
- @graphic.printstring r+hh, c, selection_symbol, acolor,@attr
400
- end
401
- #renderer = get_default_cell_renderer_for_class content.class.to_s
402
- if focussed
403
- if @focussed_symbol
404
- @graphic.printstring r+hh, c, @focussed_symbol, acolor,@attr
405
- end
406
- @graphic.printstring r+hh, c+@left_margin, content, acolor, @focussed_attrib || 'reverse'
407
- else
408
- @graphic.printstring r+hh, c+@left_margin, content, acolor,@attr
409
- end
410
- #renderer.repaint @graphic, r+hh, c+@left_margin, crow, content, focussed, selected
411
- else
412
- # clear rows
413
- @graphic.printstring r+hh, c, " " * (@width-2), acolor,@attr
414
- end
415
- end
416
- end # rc == 0
417
- set_form_row
418
- end
419
- # listobject
420
- def press ch # list TODO copy from rbasiclist
421
- ch = ch.getbyte(0) if ch.class==String ## 1.9
422
- $log.debug " XXX press #{ch} " if $log.debug?
423
- case ch
424
- when -1
425
- return
426
- when KEY_F1, 27, ?\C-q.getbyte(0)
427
- @stop = true
428
- return
429
- when KEY_ENTER, 10, 13
430
- #$log.debug "popup ENTER : #{@selected_index} "
431
- #$log.debug "popup ENTER : #{field.name}" if !field.nil?
432
- @stop = true
433
- return
434
- when 32, ?\C-d.getbyte(0)
435
- scroll_forward
436
- #@start += @height-1
437
- #bounds_check
438
- when KEY_UP, ?k.getbyte(0)
439
- previous_row
440
- #@start -= 1
441
- #@current_index -= 1
442
- #@current_index = 0 if @current_index < 0
443
- #@start = 0 if @start < 0
444
- when KEY_DOWN, ?j.getbyte(0)
445
- next_row
446
- #@start += 1
447
- #@current_index += 1
448
- #bounds_check
449
- when ?\C-b.getbyte(0)
450
- scroll_backward
451
- #@start -= @height-1
452
- #@start = 0 if @start < 0
453
- when 0, ?g.getbyte(0)
454
- goto_top
455
- when ?G.getbyte(0)
456
- goto_bottom
457
- end
458
- #@form.repaint
459
- Ncurses::Panel.update_panels();
460
- Ncurses.doupdate();
461
- @window.wrefresh
462
- end
463
-
464
- def previous_row num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
465
- #return :UNHANDLED if @current_index == 0 # EVIL
466
- return false if @current_index == 0
467
- @oldrow = @current_index
468
- num.times {
469
- @current_index -= 1 if @current_index > 0
470
- }
471
- bounds_check
472
- $multiplier = 0
473
- end
474
- alias :up :previous_row
475
- def next_row num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
476
- rc = row_count
477
- return false if @current_index == rc-1
478
- @oldrow = @current_index
479
- @current_index += 1*num if @current_index < rc
480
- bounds_check
481
- $multiplier = 0
482
- end
483
- alias :down :next_row
484
- def goto_bottom
485
- @oldrow = @current_index
486
- rc = row_count
487
- @current_index = rc -1
488
- bounds_check
489
- end
490
- alias :goto_end :goto_bottom
491
- def goto_top
492
- @oldrow = @current_index
493
- @current_index = 0
494
- bounds_check
495
- end
496
- alias :goto_start :goto_top
497
- def scroll_backward
498
- @oldrow = @current_index
499
- h = scrollatrow()
500
- m = $multiplier == 0? 1 : $multiplier
501
- @current_index -= h * m
502
- bounds_check
503
- $multiplier = 0
504
- end
505
- def scroll_forward
506
- @oldrow = @current_index
507
- h = scrollatrow()
508
- rc = row_count
509
- m = $multiplier == 0? 1 : $multiplier
510
- # more rows than box
511
- if h * m < rc
512
- @toprow += h+1 #if @current_index+h < rc
513
- @current_index = @toprow
514
- else
515
- # fewer rows than box
516
- @current_index = rc -1
517
- end
518
- #@current_index += h+1 #if @current_index+h < rc
519
- bounds_check
520
- end
521
-
522
- ##
523
- # please set oldrow before calling this. Store current_index as oldrow before changing. NOTE
524
- def bounds_check
525
- h = scrollatrow()
526
- rc = row_count
527
-
528
- @current_index = 0 if @current_index < 0 # not lt 0
529
- @current_index = rc-1 if @current_index >= rc && rc>0 # not gt rowcount
530
- @toprow = rc-h-1 if rc > h && @toprow > rc - h - 1 # toprow shows full page if possible
531
- # curr has gone below table, move toprow forward
532
- if @current_index - @toprow > h
533
- @toprow = @current_index - h
534
- elsif @current_index < @toprow
535
- # curr has gone above table, move toprow up
536
- @toprow = @current_index
537
- end
538
- set_form_row
539
-
540
- end
541
-
542
- def set_form_row
543
- r,c = rowcol
544
-
545
-
546
- # when the toprow is set externally then cursor can be mispositioned since
547
- # bounds_check has not been called
548
- if @current_index < @toprow
549
- # cursor is outside table
550
- @current_index = @toprow # ??? only if toprow 2010-10-19 12:56
551
- end
552
-
553
- row = r + (@current_index-@toprow)
554
- # row should not be < r or greater than r+height TODO FIXME
555
-
556
- #setrowcol row, nil
557
- @window.wmove row, c
558
- @window.wrefresh # FFI added to keep cursor display in synch with selection
559
- end
560
- def OLDbounds_check #:nodoc:
561
- @start = 0 if @start < 0
562
- row_offset = 1
563
- last = (@list.length)-(@height-row_offset-1)
564
- if @start > last
565
- @start = last
566
- end
567
- end # bounds_check
568
- def handle_keys #:nodoc:
569
- begin
570
- while((ch = @window.getchar()) != 999 )
571
- case ch
572
- when -1
573
- next
574
- else
575
- press ch
576
- break if @stop
577
- yield ch if block_given?
578
- end
579
- end
580
- ensure
581
- @cw.destroy
582
- end
583
- return @current_index
584
- end
585
- end # class ListObject
586
- end # class CommandWindow
587
- end # module