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,301 +0,0 @@
1
- #### ---------------------- ####
2
- # CAUTION: This is the worst piece of code ever written, pls do not
3
- # go further. I will remove this very soon.
4
- # -- Shamefully yours.
5
- #### ---------------------- ####
6
- # Provides the ability to scroll content, typically an array
7
- # widget that includes may override on_enter_row and on_leave_row
8
- # This was essentially copied and modifed from the pad scroller
9
- # i think i can redo it and make it much simpler XXX
10
- module Scrollable
11
- def init_scrollable
12
- @toprow = @prow = @winrow = @pcol = 0
13
- @oldwinrow = @oldprow = @oldtoprow = 0
14
- @startrow = 1 # from where we start prniting, taking header row into account
15
- @cols = @width
16
- @left_margin ||= 2
17
- @show_focus = true if @show_focus.nil?
18
-
19
- # @right_margin ||= @left_margin
20
- # @scrollatrow ||= @height-2
21
- end
22
- def goto_start
23
- @prow = 0
24
- @toprow = @prow
25
- @winrow = 0
26
- end
27
- def goto_end
28
- @prow = get_content().length-1
29
- #@toprow = @prow
30
- #@winrow = 0 # not putting this was cause prow < toprow !!
31
- @toprow = @prow - @scrollatrow # ensure screen is filled when we show last. so clear not required
32
- @toprow = 0 if @toprow < 0
33
- ## except what if very few rows
34
- @winrow = @scrollatrow
35
- end
36
- def right
37
- @hscrollcols ||= @cols/2
38
- @pcol += @hscrollcols if @pcol + @hscrollcols < @padcols
39
- # window_erase @win XXX
40
- end
41
- def left
42
- @hscrollcols ||= @cols/2
43
- @pcol -= @hscrollcols if @pcol > 0
44
- @pcol = 0 if @pcol < 0
45
- end
46
- # not that saving content_rows is buggy since we add rows.
47
- def down num=1
48
- # $log.debug "inside down"
49
- num.times do
50
- if @prow >= get_content().length-1
51
- #Ncurses.beep
52
- @message = "No more rows"
53
- return -1
54
- end
55
- if @winrow < @scrollatrow # 20
56
- @winrow += 1 # move cursor down
57
- else
58
- @toprow += 1 # scroll down a row
59
- end
60
- @prow += 1 # incr pad row
61
- end
62
- end
63
- def up num=1 # UP
64
- num.times do
65
- if @prow <= 0
66
- #Ncurses.beep
67
- @message = "This is the first row"
68
- @prow = 0
69
- return -1
70
- else
71
- @prow -= 1
72
- end
73
- if @winrow > 0
74
- @winrow -= 1
75
- else
76
- @toprow -= 1 if @toprow > 0
77
- end
78
- @toprow = @prow if @prow < @toprow
79
- end
80
- end
81
- def scroll_forward
82
- if @toprow + @scrollatrow+1 >= get_content().length
83
- # so cursor goes to last line
84
- @prow += get_content().length - @prow - 1 # XXX 2008-11-27 14:18
85
- else
86
- @toprow += @scrollatrow+1 # @rows-2 2008-11-13 23:41 put toprow here too
87
- $log.debug "space pr #{@prow}"
88
- @prow = @toprow
89
- end
90
- end
91
- def scroll_backward
92
- if @prow <= 0
93
- @message = "This is the first row"
94
- @prow = 0
95
- #next
96
- else
97
- @prow -= (@scrollatrow+1) #(@rows-2)
98
- @prow = 0 if @prow < 0
99
- end
100
- @toprow = @prow
101
- end
102
- def pre_key
103
- @oldprow = @prow
104
- @oldtoprow = @toprow
105
- @oldwinrow = @winrow
106
- end
107
- # prior to repaint. but after keypress
108
- def post_key
109
- # $log.debug "1 post_key w:#{@winrow} p:#{@prow} t:#{@toprow}"
110
- @toprow = @prow if @prow < @toprow # ensre search could be
111
- @toprow = @prow if @prow > @toprow + @scrollatrow
112
- @winrow = @prow - @toprow
113
- # $log.debug "2 post_key w:#{@winrow} p:#{@prow} t:#{@toprow}"
114
- # wont work first time - added 2008-11-26 20:56
115
- if @oldprow != @prow
116
- $log.debug "going to call on leave and on enter"
117
- on_leave_row @oldprow if respond_to? :on_leave_row # to be defined by widget that has included this
118
- on_enter_row @prow if respond_to? :on_enter_row # to be defined by widget that has included this
119
- end
120
- #@form.row = @winrow
121
- set_form_row
122
-
123
- end
124
- ##
125
- # caution, this now uses winrow not prow
126
- def show_focus_on_row row0, _prow, tf=true
127
- # color = tf ? $reversecolor : $datacolor
128
- # if cursor on row, reverse else normal
129
- attr = tf ? Ncurses::A_REVERSE : Ncurses::A_NORMAL
130
- color = @color_pair
131
- r = row0+1
132
- #check if row is selected or not
133
- row_att = @list_attribs[_prow] unless @list_attribs.nil?
134
- if !row_att.nil?
135
- status = row_att.fetch(:status, " ")
136
- attr1 = row_att[:bgcolor]
137
- color = attr1 unless attr1.nil?
138
- end
139
- @datawidth ||= @width-2
140
- return if r > get_content().length
141
- @form.window.mvchgat(y=r+@row, x=1+@col, max=@datawidth, attr, color, nil)
142
- end
143
- ##
144
- # unfocus the previous row cursor was on
145
- # and put focus on currrent row
146
- # Called after repaint
147
- def show_focus
148
- show_focus_on_row(@oldwinrow, @oldprow, false)
149
- show_focus_on_row(@winrow, @prow, true)
150
- # printstr @form.window, 23, 10, @prow
151
- end
152
- ## call from repaint
153
- # TODO i can simplif, i think
154
- # - if user scrolls horizontally, use column as starting point
155
- def paint
156
- #$log.debug "called paint t:#{@toprow} p:#{@prow} w:#{@winrow}"
157
- list = get_content
158
- @content_rows = list.length # rows can be added at any time
159
- win = get_window
160
- maxlen = @maxlen || @width-2
161
- if @bgcolor.is_a? String and @color.is_a? String
162
- acolor = ColorMap.get_color(@color, @bgcolor)
163
- else
164
- acolor = $datacolor
165
- end
166
- @color_pair = acolor
167
- 0.upto(@height-2) {|r|
168
- if @toprow + r < @content_rows
169
- # this relates to selection of a row, as yet
170
- # check if any status of attribs for this row
171
- row_att = @list_attribs[@toprow+r] unless @list_attribs.nil?
172
- status = " "
173
- #bgcolor = $datacolor
174
- bgcolor = nil
175
- if !row_att.nil?
176
- status = row_att.fetch(:status, " ")
177
- bgcolor = row_att[:bgcolor]
178
- end
179
- # sanitize
180
- content = list[@toprow+r].chomp # don't display newline
181
- content.gsub!(/\t/, ' ') # don't display tab
182
- content.gsub!(/[^[:print:]]/, '') # don't display non print characters
183
-
184
- #content = content[0..maxlen-1] if !content.nil? && content.length > maxlen # only show maxlen
185
- if !content.nil?
186
- if content.length > maxlen # only show maxlen
187
- content = content[@pcol..@pcol+maxlen-1]
188
- else
189
- content = content[@pcol..-1]
190
- end
191
- end
192
-
193
- width = @width-(@left_margin+1)
194
- @form.window.printstring @row+r+1, @col+@left_margin-1, "%s" % status, acolor, @attr if @implements_selectable
195
- @form.window.printstring @row+r+1, @col+@left_margin, "%-*s" % [width,content], acolor, @attr
196
- win.mvchgat(y=r+@row+1, x=@col+@left_margin, max=width, Ncurses::A_NORMAL, bgcolor, nil) unless bgcolor.nil?
197
- dollar = "|"
198
- dollar = "$" if list[@toprow+r][-1,1]=="\r"
199
- @form.window.printstring @row+r+1, @col+@width-1, dollar, acolor, @attr
200
-
201
- else
202
- # clear the displayed area
203
- @form.window.printstring @row+r+1, @col+@left_margin, " "*(@width-(@left_margin+1)), acolor
204
- dollar = "|"
205
- @form.window.printstring @row+r+1, @col+@width-1, dollar, acolor, @attr
206
- end
207
- }
208
- show_focus if @show_focus
209
- end
210
- ## for user to know which row is being focussed on
211
- def focussed_index
212
- @prow
213
- end
214
- # only to be used in single selection cases as focussed item FIXME.
215
- def selected_item
216
- get_content()[focussed_index()]
217
- end
218
- alias :current_index :focussed_index
219
- alias :selected_index :focussed_index
220
- def scrollable_handle_key ch
221
- begin
222
- pre_key
223
- case ch
224
- when ?\C-n.getbyte(0)
225
- scroll_forward
226
- when 32
227
- scroll_forward
228
- when ?\C-p.getbyte(0)
229
- scroll_backward
230
- when ?0.getbyte(0)
231
- goto_start
232
- when ?9.getbyte(0)
233
- goto_end
234
- when ?[.getbyte(0)
235
- when ?[.getbyte(0)
236
- when KEY_UP
237
- #select_prev_row
238
- up
239
- when KEY_LEFT
240
- when KEY_RIGHT
241
- when KEY_DOWN
242
- down
243
- # select_next_row
244
- when KEY_ENTER, 10, 13
245
- if respond_to? :fire
246
- fire
247
- end
248
- when ?A.getbyte(0)..?Z.getbyte(0), ?a.getbyte(0)..?z.getbyte(0)
249
- ret = set_selection_for_char ch.chr
250
- else
251
- return :UNHANDLED #if ret == -1
252
- end
253
- ensure
254
- post_key
255
- end
256
- end # handle_k listb
257
- ## 2008-12-18 18:03
258
- # finds the next match for the char pressed
259
- # returning the index
260
- def next_match char
261
- data = get_content
262
- row = focussed_index
263
- currval = data[row].chomp
264
- row.upto(data.length-1) do |ix|
265
- val = data[ix].chomp
266
- if val[0,1] == char and val != currval
267
- return ix
268
- end
269
- end
270
- 0.upto(row) do |ix|
271
- val = data[ix].chomp
272
- if val[0,1] == char and val != currval
273
- return ix
274
- end
275
- end
276
- return -1
277
- end
278
- ## 2008-12-18 18:03
279
- # sets the selection to the next row starting with char
280
- def set_selection_for_char char
281
- ix = next_match char
282
- @prow = ix if ix != -1
283
- return ix
284
- end
285
- ##
286
- # 2008-12-18 18:05
287
- # set focus on given index
288
- def set_focus_on arow
289
- return if arow > get_content().length-1 or arow < 0
290
- total = get_content().length
291
- @prow = arow
292
- sar = @scrollatrow + 1
293
- @toprow = (@prow / sar) * sar
294
-
295
- if total - @toprow < sar
296
- @toprow = (total - sar)
297
- end
298
- @winrow = @prow - @toprow
299
- end
300
-
301
- end
@@ -1,86 +0,0 @@
1
- module RubyCurses
2
- class TableCellRenderer
3
- #include DSL
4
- #include EventHandler
5
- include ConfigSetup
6
- include RubyCurses::Utils
7
- dsl_accessor :justify # :right, :left, :center # added 2008-12-22 19:02
8
- dsl_accessor :display_length # please give this to ensure the we only print this much
9
- dsl_accessor :height # if you want a multiline label.
10
- dsl_accessor :text # text of label
11
- dsl_accessor :color, :bgcolor
12
- dsl_accessor :row, :col
13
- dsl_accessor :parent #usuall the table to get colors and other default info
14
-
15
- def initialize text="", config={}, &block
16
- @text = text
17
- @editable = false
18
- @focusable = false
19
- config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
20
- instance_eval &block if block_given?
21
- init_vars
22
- end
23
- def init_vars
24
- @justify ||= :left
25
- @display_length ||= 10
26
- end
27
- def transform value
28
- return value.to_s
29
- end
30
-
31
- ##
32
- # XXX need to move wrapping etc up and done once.
33
- def repaint graphic, r=@row,c=@col, row_index=-1, value=@text, focussed=false, selected=false
34
- lablist = []
35
- #value=value.to_s # ??
36
- value=transform value
37
- if @height && @height > 1
38
- lablist = wrap_text(value, @display_length).split("\n")
39
- else
40
- # ensure we do not exceed
41
- if !@display_length.nil?
42
- if value.length > @display_length
43
- dlen = @display_length - 1
44
- dlen = 0 if dlen < 0
45
- value = value[0..dlen]
46
- end
47
- end
48
- lablist << value
49
- end
50
- len = @display_length || value.length
51
- #$log.debug "less ZERO #{@display_length} || #{value.length}, ri: #{row_index}" if len < 0
52
- acolor = get_color $datacolor
53
- #acolor =get_color $datacolor, @color || @parent.color, @bgcolor || @parent.bgcolor #unless @parent.nil?
54
- _attr = Ncurses::A_NORMAL
55
- if selected
56
- _attr = Ncurses::A_BOLD if selected
57
- acolor =get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor unless @parent.nil?
58
- end
59
- if focussed
60
- _attr |= Ncurses::A_REVERSE
61
- end
62
- #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} "
63
- _height = @height || 1
64
- str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05
65
- # loop added for labels that are wrapped.
66
- # TODO clear separately since value can change in status like labels
67
- 0.upto(_height-1) { |i|
68
- graphic.printstring r+i, c, " " * len , acolor,_attr
69
- }
70
- lablist.each_with_index do |_value, ix|
71
- break if ix >= _height
72
- if @justify.to_sym == :center
73
- padding = (@display_length - _value.length)/2
74
- padding = 0 if padding < 0
75
- _value = " "*padding + _value + " "*padding # so its cleared if we change it midway
76
- end
77
- # XXX 2009-10-05 23:01 since the len can vary when scrolling
78
- # right justification for numbers suffers.
79
- # perhaps one should use display_length and then truncate using len
80
- graphic.printstring r, c, str % [len, _value], acolor,_attr
81
- r += 1
82
- end
83
- end
84
- # ADD HERE LABEL
85
- end
86
- end
@@ -1,98 +0,0 @@
1
- module RubyCurses
2
- class TableDateCellRenderer
3
- #include EventHandler
4
- include ConfigSetup
5
- include RubyCurses::Utils
6
- dsl_accessor :justify # :right, :left, :center # added 2008-12-22 19:02
7
- dsl_accessor :format # date or numeric format
8
- dsl_accessor :format_hint # date :DATE_ONLY, :TIME_ONLY, :LONG
9
- dsl_accessor :display_length # please give this to ensure the we only print this much
10
- dsl_accessor :height # if you want a multiline label.
11
- dsl_accessor :text # text of label
12
- dsl_accessor :color, :bgcolor
13
- dsl_accessor :row, :col
14
- dsl_accessor :parent #usuall the table to get colors and other default info
15
-
16
- def initialize text="", config={}, &block
17
- @text = text
18
- @editable = false
19
- @focusable = false
20
- config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
21
- instance_eval &block if block_given?
22
- init_vars
23
- end
24
- def init_vars
25
- @justify ||= :left
26
- @display_length ||= 10
27
- @format ||= "%Y/%m/%d %H:%M"
28
- case @format_hint
29
- when :LONG
30
- @format = nil
31
- when :DATE_ONLY
32
- @format = "%Y/%m/%d"
33
- when :TIME_ONLY
34
- @format ||= "%H/%M"
35
- when :TIME_ONLY_12
36
- @format ||= "%I/%M%p"
37
- end
38
- # use %I:%M%p for 12 hour ampm"
39
- end
40
- def transform value
41
- if @format.nil?
42
- return value.to_s
43
- end
44
- return value.strftime(@format)
45
- end
46
-
47
- ##
48
- # XXX need to move wrapping etc up and done once.
49
- def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false
50
- lablist = []
51
- #value=value.to_s # ??
52
- value=transform value
53
- if @height && @height > 1
54
- lablist = wrap_text(value, @display_length).split("\n")
55
- else
56
- # ensure we do not exceed
57
- if !@display_length.nil?
58
- if value.length > @display_length
59
- dlen = @display_length - 1
60
- dlen = 0 if dlen < 0
61
- value = value[0..dlen]
62
- end
63
- end
64
- lablist << value
65
- end
66
- len = @display_length || value.length
67
- acolor = get_color $datacolor
68
- #acolor =get_color $datacolor, @color || @parent.color, @bgcolor || @parent.bgcolor #unless @parent.nil?
69
- _attr = Ncurses::A_NORMAL
70
- if selected
71
- _attr = Ncurses::A_BOLD if selected
72
- acolor =get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor unless @parent.nil?
73
- end
74
- if focussed
75
- _attr |= Ncurses::A_REVERSE
76
- end
77
- #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} "
78
- _height = @height || 1
79
- str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05
80
- # loop added for labels that are wrapped.
81
- # TODO clear separately since value can change in status like labels
82
- 0.upto(_height-1) { |i|
83
- graphic.printstring r+i, c, " " * len , acolor,_attr
84
- }
85
- lablist.each_with_index do |_value, ix|
86
- break if ix >= _height
87
- if @justify.to_sym == :center
88
- padding = (@display_length - _value.length)/2
89
- padding = 0 if padding < 0
90
- _value = " "*padding + _value + " "*padding # so its cleared if we change it midway
91
- end
92
- graphic.printstring r, c, str % [len, _value], acolor,_attr
93
- r += 1
94
- end
95
- end
96
- # ADD HERE
97
- end
98
- end