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,330 +0,0 @@
1
- =begin
2
- * Name: Multiform.rb
3
- * Description View (cycle) multiple forms
4
- * Author: rkumar (arunachalesha)
5
- * file created 2011-10-17 8:18 PM
6
- --------
7
- * License:
8
- Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
9
-
10
- =end
11
- require 'rbcurse'
12
-
13
- include RubyCurses
14
- module RubyCurses
15
- extend self
16
-
17
- # Trying to implement TabbedPanes using a multiform approach, but no more windows
18
- # or pads. Try to keep it as simple as possible
19
- class MultiForm < Widget
20
- dsl_accessor :title
21
-
22
-
23
- def initialize form = nil, config={}, &block
24
- @focusable = true
25
- @window = form.window
26
- @row_offset = @col_offset = 1
27
- @bmanager = BufferManager.new self
28
- @forms = []
29
- super
30
- init_vars
31
-
32
- end
33
- def init_vars
34
- super
35
- # the following allows us to navigate buffers with :bn :bp etc (with Alt pressed)
36
- bind_key(?\M-:, :buffer_menu)
37
- bind_key(?\M-;, :buffer_menu)
38
- # bind_key([?\C-x, ?f], :file_edit)
39
- bind_key([?\C-x, ?k], :delete_component)
40
- bind_key([?\C-x, ?\C-b], :list_components)
41
- bind_key(?\M-n, :goto_next_component)
42
- bind_key(?\M-p, :goto_prev_component)
43
- bind_key(?\M-1, :goto_first_component)
44
- # easily cycle using p. n is used for next search.
45
- #bind_key(?p, :buffer_previous)
46
- @suppress_borders = false
47
- @repaint_all = true
48
- @name ||= "multiform"
49
- end
50
- ## returns current buffer
51
- # @return [RBuffer] current buffer
52
- def current_component
53
- @bmanager.current
54
- end
55
- ##
56
- # multi-container
57
- def handle_key ch #:nodoc:
58
- @current_component.repaint
59
- @current_component.window.wrefresh
60
- $log.debug " MULTI handle_key #{ch}, #{@current_component}"
61
- ret = :UNHANDLED
62
- return :UNHANDLED unless @current_component
63
- ret = @current_component.handle_key(ch)
64
- $log.debug " MULTI comp #{@current_component} returned #{ret} "
65
- if ret == :UNHANDLED
66
- # check for bindings, these cannot override above keys since placed at end
67
- begin
68
- ret = process_key ch, self
69
- $log.debug " MULTI = process_key returned #{ret} "
70
- if ch > 177 && ch < 187
71
- n = ch - 177
72
- component_at(n)
73
- # go to component n
74
- end
75
- rescue => err
76
- # $error_message = err # changed 2010 dts
77
- $error_message.value = err.to_s
78
- #@form.window.print_error_message PLEASE CREATE LABEL
79
- $log.error " Multicomponent process_key #{err} "
80
- $log.debug(err.backtrace.join("\n"))
81
- alert err.to_s
82
- end
83
- return :UNHANDLED if ret == :UNHANDLED
84
- end
85
- @current_component.repaint
86
- @current_component.window.wrefresh
87
- FFI::NCurses.update_panels
88
-
89
- # check for any keys not handled and check our own ones
90
- return ret #
91
- end
92
- def repaint
93
- print_border if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
94
- return unless @current_component
95
- $log.debug " MULTIFORM REPAINT "
96
- ret = @current_component.repaint
97
- end
98
- def print_border #:nodoc:
99
- $log.debug " #{@name} print_borders, #{@graphic.name} "
100
- color = $datacolor
101
- @graphic.print_border_only @row, @col, @height-1, @width, color #, Ncurses::A_REVERSE
102
- print_title
103
- end
104
- def print_title #:nodoc:
105
- $log.debug " print_title #{@row}, #{@col}, #{@width} #{@title} "
106
- @graphic.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil?
107
- end
108
- # this is just a test of the simple "most" menu
109
- # can use this for next, prev, first, last, new, delete, overwrite etc
110
- def buffer_menu
111
- menu = PromptMenu.new self
112
- menu.add(menu.create_mitem( 'l', "list buffers", "list buffers ", :list_components ))
113
- item = menu.create_mitem( 'b', "Buffer Options", "Buffer Options" )
114
- menu1 = PromptMenu.new( self, "Buffer Options")
115
- menu1.add(menu1.create_mitem( 'n', "Next", "Switched to next buffer", :goto_next_component ))
116
- menu1.add(menu1.create_mitem( 'p', "Prev", "Switched to previous buffer", :goto_prev_component ))
117
- menu1.add(menu1.create_mitem( 'f', "First", "Switched to first buffer", :goto_first_component ))
118
- menu1.add(menu1.create_mitem( 'l', "Last", "Switched to last buffer", :goto_last_component ))
119
- menu1.add(menu1.create_mitem( 'd', "Delete", "Deleted buffer", :delete_component ))
120
- item.action = menu1
121
- menu.add(item)
122
- # how do i know what's available. the application or window should know where to place
123
- menu.display @form.window, $error_message_row, $error_message_col, $datacolor #, menu
124
- end
125
-
126
-
127
- def goto_next_component
128
- perror "No other buffer" and return if @bmanager.size < 2
129
-
130
- @current_component = @bmanager.next
131
- set_current_component
132
- # set_form_row and shit
133
- end
134
-
135
- def goto_prev_component
136
- perror "No other buffer" and return if @bmanager.size < 2
137
-
138
- @current_component = @bmanager.previous
139
- $log.debug " buffer_prev got #{@current_component} "
140
- set_current_component
141
- end
142
- def goto_first_component
143
- @current_component = @bmanager.first
144
- $log.debug " buffer_first got #{@current_component} "
145
- set_current_component
146
- end
147
- def goto_last_component
148
- @current_component = @bmanager.last
149
- $log.debug " buffer_last got #{@current_component} "
150
- set_current_component
151
- end
152
- def delete_component
153
- if @bmanager.size > 1
154
- @bmanager.delete_at
155
- @current_component = @bmanager.previous
156
- set_current_component
157
- else
158
- perror "Only one buffer. Cannot delete."
159
- end
160
- end
161
-
162
- def component_at index
163
- cc = @bmanager.element_at index
164
- return unless cc
165
- @current_component = cc
166
- #$log.debug " buffer_last got #{@current_component} "
167
- set_current_component
168
- end
169
- def add_form title, config={}, &blk
170
- $log.debug "XXX: add_form window coords were hwtl #{@height} , #{@width} , #{@top} , #{@left} "
171
- #w = VER::Window.new 16, 30, 2, 2 #@height-1, @width-1, @top, @left
172
- w = VER::Window.new @height-2, @width-2, @row+1, @col+1
173
- #w.box(0,0)
174
- frm = Form.new w
175
- @forms << frm
176
- frm.parent_form = @form
177
- frm.add_cols=@col+@col_offset
178
- frm.add_rows=@row+@row_offset
179
- @current_component = @bmanager.add frm, title
180
- set_current_component
181
- yield frm if block_given?
182
- return @current_component # not a form but a Rcomponent containing component and title
183
- end
184
- def _add_to(index, component)
185
- raise ArgumentError, "index out of bounds" unless @forms[index]
186
- component.set_form(@forms[index])
187
- $log.debug "XXX: comp r c #{component.row} #{component.col} "
188
- component.row += @row
189
- component.col += @col
190
- $log.debug "XXX: after comp r c #{component.row} #{component.col} "
191
- end
192
- ##
193
- # Add a component with a title
194
- # @param [Widget] component
195
- # @param [String] title
196
- def add component, title
197
- component.row = @row+@row_offset+0 # FFI changed 1 to 0 2011-09-12
198
- component.col = @col+@col_offset+0 # FFI changed 1 to 0 2011-09-12
199
- component.width = @width-2
200
- component.height = @height-2
201
- component.form = @form
202
- component.override_graphic(@graphic)
203
- @current_component = @bmanager.add component, title
204
- set_current_component
205
- set_form_row ## FFI added 2011-09-12 to get cursor at start when adding
206
- $log.debug " ADD got cb : #{@current_component} "
207
- end
208
- def set_current_component
209
- @title = @current_component.title
210
- @current_component = @current_component.component
211
- @current_component.repaint #2011-10-17 need to set all comps to repaint XXX
212
- @current_component.window.wrefresh
213
- @current_component.window.show
214
- FFI::NCurses.update_panels
215
- set_form_row
216
- #@current_title = @current_component.title
217
- #@current_component.repaint_all true 2011-10-17 need to set all comps to repaint XXX
218
- end
219
- def perror errmess
220
- alert errmess
221
- #@form.window.print_error_message errmess
222
- end
223
- def list_components
224
- $log.debug " TODO buffers_list: #{@bmanager.size} "
225
- menu = PromptMenu.new self
226
- @bmanager.each_with_index{ |b, ix|
227
- aproc = Proc.new { component_at(ix) }
228
- name = b.title
229
- num = ix + 1
230
- menu.add(menu.create_mitem( num.to_s, name, "Switched to buffer #{ix}", aproc ))
231
- }
232
- menu.display @form.window, $error_message_row, $error_message_col, $datacolor
233
- end
234
- # required otherwise some components may not get correct cursor position on entry
235
- # e.g. table
236
- def on_enter
237
- set_form_row # 2011-10-17
238
- end
239
- # nothing happening, the cursor goes to 1,1 and does not move
240
- # alhough the fields can be edited XXX
241
- def set_form_row #:nodoc:
242
- if !@current_component.nil?
243
- #$log.debug " #{@name} set_form_row calling sfr for #{@current_component.name} "
244
- #fc = @current_component.widgets[0]
245
- fc = @current_component.get_current_field
246
- fc ||= @current_component.widgets[0]
247
- fc.set_form_row if fc
248
- #fc.set_form_col
249
- end
250
- end
251
- # ADD HERE
252
- end # class multicontainer
253
- ##
254
- # Handles multiple buffers, navigation, maintenance etc
255
- # Instantiated at startup of
256
- #
257
- class BufferManager
258
- include Enumerable
259
- def initialize source
260
- @source = source
261
- @buffers = [] # contains RBuffer
262
- @counter = 0
263
- # for each buffer i need to store data, current_index (row), curpos (col offset) and title (filename).
264
- end
265
- def element_at index
266
- @buffers[index]
267
- end
268
- def each
269
- @buffers.each {|k| yield(k)}
270
- end
271
-
272
- ##
273
- # @return [RBuffer] current buffer/file
274
- ##
275
- def current
276
- @buffers[@counter]
277
- end
278
- ##
279
- # Would have liked to just return next buffer and not get lost in details of caller
280
- #
281
- # @return [RBuffer] next buffer/file
282
- ##
283
- def next
284
- @counter += 1
285
- @counter = 0 if @counter >= @buffers.size
286
- @buffers[@counter]
287
- end
288
- ##
289
- # @return [RBuffer] previous buffer/file
290
- ##
291
- def previous
292
- $log.debug " previous bs: #{@buffers.size}, #{@counter} "
293
- @counter -= 1
294
- return last() if @counter < 0
295
- $log.debug " previous ctr #{@counter} "
296
- @buffers[@counter]
297
- end
298
- def first
299
- @counter = 0
300
- @buffers[@counter]
301
- end
302
- def last
303
- @counter = @buffers.size - 1
304
- @buffers[@counter]
305
- end
306
- ##
307
- def delete_at index=@counter
308
- @buffers.delete_at index
309
- end
310
- def delete_by_name name
311
- @buffers.delete_if {|b| b.filename == name }
312
- end
313
- def insert component, position, title=nil
314
- anew = RComponents.new(component, title)
315
- @buffers.insert position, anew
316
- @counter = position
317
- return anew
318
- end
319
- def add component, title=nil
320
- #$log.debug " ADD H: #{component.height} C: #{component.width} "
321
- insert component, @buffers.size, title
322
- end
323
- def size
324
- @buffers.size
325
- end
326
- alias :count :size
327
- end
328
- RComponents = Struct.new(:component, :title)
329
-
330
- end # modul
@@ -1,142 +0,0 @@
1
- # ----------------------------------------------------------------------------- #
2
- # File: multilinelabel.rb
3
- # Description: Prints a label on the screen.
4
- # This is the original label that was present in rwidgets.rb
5
- # It allowed for multiple lines. I am simplifying that to a simple
6
- # single line label.
7
- # I am basically moving multiline labels out of hte core package
8
- # Author: rkumar http://github.com/rkumar/rbcurse/
9
- # Date: 2011-11-12 - 12:04
10
- # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
11
- # Last update: 2011-11-12 - 12:05
12
- # ----------------------------------------------------------------------------- #
13
- #
14
- module RubyCurses
15
-
16
- # print static text on a form, allowing for text to be wrapped.
17
- #
18
- class MultiLineLabel < Widget
19
- dsl_accessor :mnemonic # keyboard focus is passed to buddy based on this key (ALT mask)
20
-
21
- # justify required a display length, esp if center.
22
- dsl_property :justify #:right, :left, :center
23
- dsl_property :display_length #please give this to ensure the we only print this much
24
- #dsl_property :height #if you want a multiline label. already added to widget
25
- # for consistency with others 2011-11-5
26
- alias :width :display_length
27
- alias :width= :display_length=
28
-
29
- def initialize form, config={}, &block
30
-
31
- # this crap was used in position_label, find another way. where is it used ?
32
- #@row = config.fetch("row",-1) # why on earth this monstrosity ? 2011-11-5
33
- #@col = config.fetch("col",-1)
34
- #@bgcolor = config.fetch("bgcolor", $def_bg_color)
35
- #@color = config.fetch("color", $def_fg_color)
36
- @text = config.fetch("text", "NOTFOUND")
37
- @editable = false
38
- @focusable = false
39
- super
40
- @justify ||= :left
41
- @name ||= @text
42
- @repaint_required = true
43
- end
44
- #
45
- # get the value for the label
46
- def getvalue
47
- @text_variable && @text_variable.value || @text
48
- end
49
- def label_for field
50
- @label_for = field
51
- #$log.debug " label for: #{@label_for}"
52
- if @form
53
- bind_hotkey
54
- else
55
- @when_form ||= []
56
- @when_form << lambda { bind_hotkey }
57
- end
58
- end
59
-
60
- ##
61
- # for a button, fire it when label invoked without changing focus
62
- # for other widgets, attempt to change focus to that field
63
- def bind_hotkey
64
- if !@mnemonic.nil?
65
- ch = @mnemonic.downcase()[0].ord ## 1.9 DONE
66
- # meta key
67
- mch = ?\M-a.getbyte(0) + (ch - ?a.getbyte(0)) ## 1.9
68
- if @label_for.is_a? RubyCurses::Button and @label_for.respond_to? :fire
69
- @form.bind_key(mch, @label_for) { |_form, _butt| _butt.fire }
70
- else
71
- $log.debug " bind_hotkey label for: #{@label_for}"
72
- @form.bind_key(mch, @label_for) { |_form, _field| _field.focus }
73
- end
74
- end
75
- end
76
-
77
- ##
78
- # XXX need to move wrapping etc up and done once.
79
- def repaint
80
- return unless @repaint_required
81
- raise "Label row or col nil #{@row} , #{@col}, #{@text} " if @row.nil? || @col.nil?
82
- r,c = rowcol
83
-
84
- @bgcolor ||= $def_bg_color
85
- @color ||= $def_fg_color
86
- # value often nil so putting blank, but usually some application error
87
- value = getvalue_for_paint || ""
88
- lablist = []
89
- # trying out array values 2011-10-16 more for messageboxes.
90
- if value.is_a? Array
91
- lablist = text
92
- @height = text.size
93
- elsif @height && @height > 1
94
- lablist = wrap_text(value, @display_length).split("\n")
95
- else
96
- # ensure we do not exceed
97
- if !@display_length.nil?
98
- if value.length > @display_length
99
- value = value[0..@display_length-1]
100
- end
101
- end
102
- lablist << value
103
- end
104
- len = @display_length || value.length
105
- acolor = get_color $datacolor
106
- $log.debug "label :#{@text}, #{value}, r #{r}, c #{c} col= #{@color}, #{@bgcolor} acolor #{acolor} j:#{@justify} dlL: #{@display_length} "
107
- firstrow = r
108
- _height = @height || 1
109
- str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05
110
- # loop added for labels that are wrapped.
111
- # TODO clear separately since value can change in status like labels
112
-
113
- @graphic = @form.window if @graphic.nil? ## HACK messagebox givig this in repaint, 423 not working ??
114
- 0.upto(_height-1) { |i|
115
- @graphic.printstring r+i, c, " " * len , acolor,@attr
116
- }
117
- lablist.each_with_index do |_value, ix|
118
- break if ix >= _height
119
- if @justify.to_sym == :center
120
- padding = (@display_length - _value.length)/2
121
- _value = " "*padding + _value + " "*padding # so its cleared if we change it midway
122
- end
123
- @graphic.printstring r, c, str % [len, _value], acolor,@attr
124
- r += 1
125
- end
126
- if !@mnemonic.nil?
127
- ulindex = value.index(@mnemonic) || value.index(@mnemonic.swapcase)
128
- @graphic.mvchgat(y=firstrow, x=c+ulindex, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, acolor, nil)
129
- end
130
- #@form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, color, nil)
131
- @repaint_required = false
132
- end
133
- # Added 2011-10-22 to prevent some naive components from putting focus here.
134
- def on_enter
135
- raise "Cannot enter Label"
136
- end
137
- def on_leave
138
- raise "Cannot leave Label"
139
- end
140
- # ADD HERE LABEL
141
- end # class
142
- end # module