rbcurse-core 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/README.md +69 -0
  2. data/VERSION +1 -0
  3. data/examples/abasiclist.rb +151 -0
  4. data/examples/alpmenu.rb +46 -0
  5. data/examples/app.sample +17 -0
  6. data/examples/atree.rb +100 -0
  7. data/examples/common/file.rb +45 -0
  8. data/examples/data/README.markdown +9 -0
  9. data/examples/data/brew.txt +38 -0
  10. data/examples/data/color.2 +37 -0
  11. data/examples/data/gemlist.txt +60 -0
  12. data/examples/data/lotr.txt +12 -0
  13. data/examples/data/ports.txt +136 -0
  14. data/examples/data/table.txt +37 -0
  15. data/examples/data/tasks.csv +88 -0
  16. data/examples/data/tasks.txt +27 -0
  17. data/examples/data/todo.txt +10 -0
  18. data/examples/data/todocsv.csv +28 -0
  19. data/examples/data/unix1.txt +21 -0
  20. data/examples/data/unix2.txt +11 -0
  21. data/examples/dbdemo.rb +487 -0
  22. data/examples/dirtree.rb +90 -0
  23. data/examples/newtabbedwindow.rb +100 -0
  24. data/examples/newtesttabp.rb +92 -0
  25. data/examples/tabular.rb +132 -0
  26. data/examples/tasks.rb +167 -0
  27. data/examples/term2.rb +83 -0
  28. data/examples/testkeypress.rb +72 -0
  29. data/examples/testlistbox.rb +158 -0
  30. data/examples/testmessagebox.rb +140 -0
  31. data/examples/testree.rb +106 -0
  32. data/examples/testwsshortcuts.rb +66 -0
  33. data/examples/testwsshortcuts2.rb +127 -0
  34. data/lib/rbcurse.rb +8 -0
  35. data/lib/rbcurse/core/docs/index.txt +73 -0
  36. data/lib/rbcurse/core/include/action.rb +40 -0
  37. data/lib/rbcurse/core/include/appmethods.rb +112 -0
  38. data/lib/rbcurse/core/include/bordertitle.rb +41 -0
  39. data/lib/rbcurse/core/include/chunk.rb +182 -0
  40. data/lib/rbcurse/core/include/io.rb +953 -0
  41. data/lib/rbcurse/core/include/listcellrenderer.rb +140 -0
  42. data/lib/rbcurse/core/include/listeditable.rb +317 -0
  43. data/lib/rbcurse/core/include/listscrollable.rb +590 -0
  44. data/lib/rbcurse/core/include/listselectable.rb +264 -0
  45. data/lib/rbcurse/core/include/multibuffer.rb +83 -0
  46. data/lib/rbcurse/core/include/orderedhash.rb +77 -0
  47. data/lib/rbcurse/core/include/ractionevent.rb +67 -0
  48. data/lib/rbcurse/core/include/rchangeevent.rb +27 -0
  49. data/lib/rbcurse/core/include/rhistory.rb +62 -0
  50. data/lib/rbcurse/core/include/rinputdataevent.rb +47 -0
  51. data/lib/rbcurse/core/include/vieditable.rb +170 -0
  52. data/lib/rbcurse/core/system/colormap.rb +163 -0
  53. data/lib/rbcurse/core/system/keyboard.rb +150 -0
  54. data/lib/rbcurse/core/system/keydefs.rb +30 -0
  55. data/lib/rbcurse/core/system/ncurses.rb +218 -0
  56. data/lib/rbcurse/core/system/panel.rb +162 -0
  57. data/lib/rbcurse/core/system/window.rb +901 -0
  58. data/lib/rbcurse/core/util/ansiparser.rb +117 -0
  59. data/lib/rbcurse/core/util/app.rb +1235 -0
  60. data/lib/rbcurse/core/util/basestack.rb +407 -0
  61. data/lib/rbcurse/core/util/bottomline.rb +1850 -0
  62. data/lib/rbcurse/core/util/colorparser.rb +71 -0
  63. data/lib/rbcurse/core/util/focusmanager.rb +31 -0
  64. data/lib/rbcurse/core/util/padreader.rb +189 -0
  65. data/lib/rbcurse/core/util/rcommandwindow.rb +587 -0
  66. data/lib/rbcurse/core/util/rdialogs.rb +619 -0
  67. data/lib/rbcurse/core/util/viewer.rb +149 -0
  68. data/lib/rbcurse/core/util/widgetshortcuts.rb +505 -0
  69. data/lib/rbcurse/core/widgets/applicationheader.rb +102 -0
  70. data/lib/rbcurse/core/widgets/box.rb +58 -0
  71. data/lib/rbcurse/core/widgets/divider.rb +310 -0
  72. data/lib/rbcurse/core/widgets/keylabelprinter.rb +178 -0
  73. data/lib/rbcurse/core/widgets/rcombo.rb +238 -0
  74. data/lib/rbcurse/core/widgets/rcontainer.rb +415 -0
  75. data/lib/rbcurse/core/widgets/rlink.rb +30 -0
  76. data/lib/rbcurse/core/widgets/rlist.rb +723 -0
  77. data/lib/rbcurse/core/widgets/rmenu.rb +939 -0
  78. data/lib/rbcurse/core/widgets/rmenulink.rb +22 -0
  79. data/lib/rbcurse/core/widgets/rmessagebox.rb +373 -0
  80. data/lib/rbcurse/core/widgets/rprogress.rb +118 -0
  81. data/lib/rbcurse/core/widgets/rtabbedpane.rb +615 -0
  82. data/lib/rbcurse/core/widgets/rtabbedwindow.rb +68 -0
  83. data/lib/rbcurse/core/widgets/rtextarea.rb +920 -0
  84. data/lib/rbcurse/core/widgets/rtextview.rb +780 -0
  85. data/lib/rbcurse/core/widgets/rtree.rb +787 -0
  86. data/lib/rbcurse/core/widgets/rwidget.rb +3040 -0
  87. data/lib/rbcurse/core/widgets/scrollbar.rb +143 -0
  88. data/lib/rbcurse/core/widgets/statusline.rb +94 -0
  89. data/lib/rbcurse/core/widgets/tabular.rb +264 -0
  90. data/lib/rbcurse/core/widgets/tabularwidget.rb +1211 -0
  91. data/lib/rbcurse/core/widgets/textpad.rb +516 -0
  92. data/lib/rbcurse/core/widgets/tree/treecellrenderer.rb +150 -0
  93. data/lib/rbcurse/core/widgets/tree/treemodel.rb +428 -0
  94. metadata +156 -0
@@ -0,0 +1,22 @@
1
+ require 'rbcurse/core/widgets/rlink'
2
+ ##
3
+ module RubyCurses
4
+ class MenuLink < Link
5
+ dsl_property :description
6
+
7
+ def initialize form, config={}, &block
8
+ config[:hotkey] = true
9
+ super
10
+ @col_offset = -1 * (@col || 1)
11
+ @row_offset = -1 * (@row || 1)
12
+ end
13
+ # added for some standardization 2010-09-07 20:28
14
+ # alias :text :getvalue # NEXT VERSION
15
+ # change existing text to label
16
+
17
+ def getvalue_for_paint
18
+ "%s %-12s - %-s" % [ @mnemonic , getvalue(), @description ]
19
+ end
20
+ ##
21
+ end # class
22
+ end # module
@@ -0,0 +1,373 @@
1
+ # --------------------------------------------------------------------------------- #
2
+ # File: rmessagebox.rb
3
+ # Description: This is a cleaner attempt at messagebox on the lines of
4
+ # the new tabbedpane and window.
5
+ # Author: rkumar http://github.com/rkumar/rbcurse/
6
+ # Date: 03.11.11 - 22:15
7
+ # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
8
+ # Last update: 03.11.11 - 23:47
9
+ # == CHANGES
10
+ # == TODO
11
+ # _ <ENTER> should result in OK being pressed if its default, ESC should result in cancel esp 2 time
12
+ # ensure that text and message are used in isolation and not with other things
13
+ #
14
+ # _ determine window size, but we are doing instance eval later.
15
+ #
16
+ # _ maybe have shortcuts for some widgets field, buttons, text and label and
17
+ # share with app and otherszz
18
+ #
19
+ # _ stack, flow and grid
20
+ #
21
+ # --------------------------------------------------------------------------------- #
22
+
23
+ require 'rbcurse'
24
+ require 'rbcurse/core/include/bordertitle'
25
+
26
+ include RubyCurses
27
+ module RubyCurses
28
+ extend self
29
+ class MessageBox
30
+ include BorderTitle
31
+ include RubyCurses::Utils
32
+
33
+ attr_reader :form
34
+ attr_reader :window
35
+ dsl_accessor :button_type
36
+ dsl_accessor :default_button
37
+ #
38
+ # a message to be printed, usually this will be the only thing supplied
39
+ # with an OK button. This should be a short string, a label will be used
40
+ # and input_config passed to it
41
+
42
+ #dsl_accessor :message
43
+ # you can also set button_orientation : :right, :left, :center
44
+ #
45
+ def initialize config={}, &block
46
+
47
+ h = config.fetch(:height, nil)
48
+ w = config.fetch(:width, nil)
49
+ t = config.fetch(:row, nil)
50
+ l = config.fetch(:col, nil)
51
+ if h && w && t && l
52
+ @window = VER::Window.new :height => h, :width => w, :top => t, :left => l
53
+ @graphic = @window
54
+ end
55
+ @form = Form.new @window
56
+
57
+ config.each_pair { |k,v| instance_variable_set("@#{k}",v) }
58
+ @config = config
59
+ @row = 0
60
+ @col = 0
61
+ @row_offset = 1
62
+ @col_offset = 2
63
+ #bordertitle_init
64
+ @color ||= :black
65
+ @bgcolor ||= :white
66
+ @maxrow = 3
67
+
68
+ instance_eval &block if block_given?
69
+
70
+ end
71
+ def item widget
72
+ # remove from existing form if set FIXME
73
+ if widget.form
74
+ f = widget.form
75
+ f.remove_widget widget
76
+ end
77
+ @maxrow ||= 3
78
+ widget.set_form @form
79
+ widget.row ||= 0
80
+ widget.col ||= 0
81
+ if widget.row == 0
82
+ widget.row = [@maxrow+1, 3].max if widget.row == 0
83
+ else
84
+ widget.row += @row_offset
85
+ end
86
+ if widget.col === 0
87
+ widget.col = 5 if widget.col === 0
88
+ else
89
+ # i don't know button_offset as yet
90
+ widget.col += @col_offset
91
+ end
92
+ # in most cases this override is okay, but what if user has set it
93
+ # The problem is that widget and field are doing a default setting so i don't know
94
+ # if user has set or widget has done a default setting. NOTE
95
+ widget.color ||= @color # we are overriding colors, how to avoid since widget sets it
96
+ widget.bgcolor ||= @bgcolor
97
+ widget.attr = @attr if @attr # we are overriding what user has put. DARN !
98
+ @maxrow = widget.row if widget.row > @maxrow
99
+ @suggested_h = @height || @maxrow+6
100
+ @suggested_w ||= 0
101
+ @suggested_w = widget.col + 15 if widget.col > @suggested_w
102
+ # if w's given col is > width then add to suggested_w or text.length
103
+ end
104
+ alias :add :item
105
+ # returns button index
106
+ # Call this after instantiating the window
107
+ def run
108
+ repaint
109
+ @form.repaint
110
+ @window.wrefresh
111
+ return handle_keys
112
+ end
113
+ def repaint
114
+ _create_window unless @window
115
+ acolor = get_color $reverscolor # this implicitly uses color and bgcolor fooling me often
116
+ $log.debug " MESSAGE BOX bg:#{@bgcolor} , co:#{@color} , colorpair:#{acolor}"
117
+ @window.wbkgd(Ncurses.COLOR_PAIR(acolor)); # does not work on xterm-256color
118
+
119
+ #print_borders unless @suppress_borders # do this once only, unless everything changes
120
+ #@window.print_border_mb 1,2, @height, @width, $normalcolor, FFI::NCurses::A_REVERSE
121
+ @color_pair = get_color($datacolor)
122
+ bordercolor = @border_color || @color_pair
123
+ borderatt = @border_attrib || Ncurses::A_NORMAL
124
+ @window.wattron(Ncurses.COLOR_PAIR(bordercolor) | (borderatt || FFI::NCurses::A_NORMAL))
125
+ @window.print_border_mb 1,2, @height, @width, bordercolor, borderatt
126
+ @window.wattroff(Ncurses.COLOR_PAIR(bordercolor) | (borderatt || FFI::NCurses::A_NORMAL))
127
+ @title ||= "+-+"
128
+ title = " "+@title+" "
129
+ @window.printstring(@row=1,@col=(@width-title.length)/2,title, color=$normalcolor)
130
+ #print_message if @message
131
+ create_action_buttons unless @action_buttons
132
+ end
133
+ # Pass a short message to be printed.
134
+ # This creates a label for a short message, and a field for a long one.
135
+ # @yield field created
136
+ # @param [String] text to display
137
+ def message message # yield label or field being used for display for further customization
138
+ @suggested_h = @height || 10
139
+ message = message.gsub(/[\n\r\t]/,' ') rescue message
140
+ message_col = 5
141
+ @suggested_w = @width || [message.size + 8 + message_col , FFI::NCurses.COLS-2].min
142
+ r = 3
143
+ len = message.length
144
+ @suggested_w = len + 8 + message_col if len < @suggested_w - 8 - message_col
145
+
146
+ display_length = @suggested_w-8
147
+ display_length -= message_col
148
+ message_height = 2
149
+ clr = @color || :white
150
+ bgclr = @bgcolor || :black
151
+
152
+ # trying this out. sometimes very long labels get truncated, so i give a field in wchich user
153
+ # can use arrow key or C-a and C-e
154
+ if message.size > display_length
155
+ message_label = RubyCurses::Field.new @form, {:text => message, :name=>"message_label",
156
+ :row => r, :col => message_col, :display_length => display_length,
157
+ :bgcolor => bgclr , :color => clr, :editable => false}
158
+ else
159
+ message_label = RubyCurses::Label.new @form, {:text => message, :name=>"message_label",
160
+ :row => r, :col => message_col, :display_length => display_length,
161
+ :height => message_height, :bgcolor => bgclr , :color => clr}
162
+ end
163
+ @maxrow = 3
164
+ yield message_label if block_given?
165
+ end
166
+
167
+ # This is for larger messages, or messages where the size is not known.
168
+ # A textview object is created and yielded.
169
+ #
170
+ def text message
171
+ @suggested_w = @width || (FFI::NCurses.COLS * 0.70).floor
172
+ @suggested_h = @height || (FFI::NCurses.LINES * 0.70).floor
173
+
174
+ message_col = 3
175
+ r = 2
176
+ display_length = @suggested_w-4
177
+ display_length -= message_col
178
+ clr = @color || :white
179
+ bgclr = @bgcolor || :black
180
+
181
+ if message.is_a? Array
182
+ # reduce width and height if you can based on array contents
183
+ else
184
+ message = wrap_text(message, display_length).split("\n")
185
+ end
186
+ message_height = message.size
187
+ # reduce if possible if its not required.
188
+ #
189
+ r1 = (FFI::NCurses.LINES-@suggested_h)/2
190
+ r1 = r1.floor
191
+ w = @suggested_w
192
+ c1 = (FFI::NCurses.COLS-w)/2
193
+ c1 = c1.floor
194
+ @suggested_row = r1
195
+ @suggested_col = c1
196
+ brow = @button_row || @suggested_h-4
197
+ available_ht = brow - r + 1
198
+ message_height = [message_height, available_ht].min
199
+ require 'rbcurse/core/widgets/rtextview'
200
+ message_label = RubyCurses::TextView.new @form, {:name=>"message_label", :text => message,
201
+ :row => r, :col => message_col, :width => display_length, :suppress_borders => true,
202
+ :height => message_height, :bgcolor => bgclr , :color => clr}
203
+ #message_label.set_content message
204
+ yield message_label if block_given?
205
+
206
+ end
207
+ # returns button index (or in some cases, whatever value was thrown
208
+ # if user did not specify any button_type but gave his own and did throw (:close, x)
209
+ private
210
+ def handle_keys
211
+ buttonindex = catch(:close) do
212
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
213
+ break if ch == ?\C-q.getbyte(0)
214
+ begin
215
+ @form.handle_key(ch)
216
+ @window.wrefresh
217
+ rescue => err
218
+ $log.debug( err) if err
219
+ $log.debug(err.backtrace.join("\n")) if err
220
+ alert "Exception in Messagebox: #{err}. Check log"
221
+ @window.refresh # otherwise the window keeps showing (new FFI-ncurses issue)
222
+ $error_message.value = ""
223
+ ensure
224
+ end
225
+
226
+ end # while loop
227
+ end # close
228
+ $log.debug "XXX: CALLER GOT #{buttonindex} "
229
+ @window.destroy
230
+ return buttonindex
231
+ end
232
+ private
233
+ def create_action_buttons
234
+ return unless @button_type
235
+ @default_button = 0 if !@default_button
236
+ case @button_type.to_s.downcase
237
+ when "ok"
238
+ make_buttons ["&OK"]
239
+ when "ok_cancel" #, "input", "list", "field_list"
240
+ make_buttons %w[&OK &Cancel]
241
+ when "ok_apply_cancel" #, "input", "list", "field_list"
242
+ make_buttons %w[&OK &Apply &Cancel]
243
+ when "yes_no"
244
+ make_buttons %w[&Yes &No]
245
+ when "yes_no_cancel"
246
+ make_buttons ["&Yes", "&No", "&Cancel"]
247
+ when "custom"
248
+ raise "Blank list of buttons passed to custom" if @buttons.nil? or @buttons.size == 0
249
+ make_buttons @buttons
250
+ else
251
+ $log.warn "No buttontype passed for creating tabbedpane. Not creating any"
252
+ #make_buttons ["&OK"]
253
+ end
254
+ end
255
+ private
256
+ def make_buttons names
257
+ @action_buttons = []
258
+ $log.debug "XXX: came to NTP make buttons FORM= #{@form.name} names #{names} "
259
+ total = names.inject(0) {|total, item| total + item.length + 4}
260
+ bcol = align_buttons total, @button_orientation
261
+
262
+ # this craps out when height is zero
263
+ brow = @row + @height-4
264
+ brow = FFI::NCurses.LINES-2 if brow < 0
265
+ @button_row = brow
266
+ #color_pair = get_color($normalcolor)
267
+ #@window.wattron(Ncurses.COLOR_PAIR(color_pair) | (@attrib || FFI::NCurses::A_NORMAL))
268
+ #@window.mvwhline( brow-1, @col+1, Ncurses::ACS_HLINE, @width-2)
269
+ #@window.wattroff(Ncurses.COLOR_PAIR(color_pair) | (@attrib || FFI::NCurses::A_NORMAL))
270
+ $log.debug "XXX: putting buttons :on #{brow} , #{bcol} : #{@row} , #{@height} "
271
+ button_ct =0
272
+ tpp = self
273
+ _color = @color
274
+ _bgcolor = @bgcolor
275
+ names.each_with_index do |bname, ix|
276
+ text = bname
277
+
278
+ button = Button.new @form do
279
+ text text
280
+ name bname
281
+ row brow
282
+ col bcol
283
+ highlight_background $reversecolor
284
+ color _color
285
+ bgcolor _bgcolor
286
+ end
287
+ @action_buttons << button
288
+ button.form = @form
289
+ button.override_graphic @graphic
290
+ button.default_button(true) if (@default_button && @default_button == ix)
291
+ index = button_ct
292
+ tpp = self
293
+ button.command { |form| @selected_index = index; @stop = true;
294
+ # ActionEvent has source event and action_command
295
+ action = ActionEvent.new(tpp, index, button.text)
296
+ if @command
297
+ @command.call(action, @args)
298
+ else
299
+ # default action if you don't specify anything
300
+ throw(:close, @selected_index)
301
+ end
302
+ }
303
+ # we map the key of the button to the alphabet so user can press just the mnemonic, and not
304
+ # just the Alt combination.
305
+ mn = button.mnemonic
306
+ @form.bind_key(mn.downcase) { button.fire} if mn
307
+ button_ct += 1
308
+ bcol += text.length+6
309
+ end
310
+ end
311
+ def _create_window
312
+
313
+ @width ||= @suggested_w || 60
314
+ @height = @suggested_h || 10
315
+ if @suggested_row
316
+ @row = @suggested_row
317
+ else
318
+ @row = ((FFI::NCurses.LINES-@height)/2).floor
319
+ end
320
+ if @suggested_col
321
+ @col = @suggested_col
322
+ else
323
+ w = @width
324
+ @col = ((FFI::NCurses.COLS-w)/2).floor
325
+ end
326
+ @window = VER::Window.new :height => @height, :width => @width, :top => @row, :left => @col
327
+ @graphic = @window
328
+ @form.window = @window
329
+ end
330
+ #
331
+ # specify a code block to be fired when an action button is pressed
332
+ # This will supply (to the code block) an ActionEvent followed by
333
+ # whatever args that were given.
334
+ # ActionEvent contains source, event, action_command which map to
335
+ # the messagebox, selected_index (base 0) and button title.
336
+ #
337
+ public
338
+ def command *args, &blk
339
+ @command = blk
340
+ @args = args
341
+ end
342
+ # returns array of widgets declared for querying
343
+ def widgets
344
+ @form.widgets
345
+ end
346
+ # returns a widget based on offset, or name (if you gave it a :name)
347
+ # e.g. a list was declared and we wish to know the selected_indices
348
+ def widget n
349
+ case n
350
+ when Fixnum
351
+ @form.widgets[n]
352
+ when String, Symbol
353
+ @form.by_name[n]
354
+ else
355
+ raise "messagebox.widget can't handle #{n.class} "
356
+ end
357
+ end
358
+
359
+ # returns starting column for buttons to start painting
360
+ # Not very correct in case of :right
361
+ private
362
+ def align_buttons textlen, orient=:center
363
+ case orient
364
+ when :left
365
+ return @col+@col_offset
366
+ when :right
367
+ return (@width-textlen)-5
368
+ else
369
+ return (@width-textlen)/2
370
+ end
371
+ end
372
+ end
373
+ end
@@ -0,0 +1,118 @@
1
+ #require 'ncurses'
2
+ require 'logger'
3
+ require 'rbcurse'
4
+
5
+ #include Ncurses # FFI 2011-09-8
6
+ include RubyCurses
7
+ module RubyCurses
8
+ extend self
9
+ ##
10
+ # TODO user may want to print a label on progress: like not started or complete.
11
+ class Progress < Widget
12
+ dsl_property :width # please give this to ensure the we only print this much
13
+ dsl_property :fraction # how much to cover
14
+ dsl_property :char # what char to use for filling, default space
15
+ dsl_property :text # text to put over bar
16
+ dsl_accessor :style # :old or nil/anything else
17
+ dsl_accessor :surround_chars # "[]"
18
+
19
+ def initialize form, config={}, &block
20
+
21
+ @row = config.fetch("row",-1)
22
+ @col = config.fetch("col",-1)
23
+ @bgcolor = config.fetch("bgcolor", $def_bg_color)
24
+ @color = config.fetch("color", $def_fg_color)
25
+ @name = config.fetch("name", "pbar")
26
+ @editable = false
27
+ @focusable = false
28
+ super
29
+ @surround_chars ||= "[]" # for :old style
30
+ @repaint_required = true
31
+ end
32
+ def getvalue
33
+ @fraction || 0.0
34
+ end
35
+
36
+ ##
37
+ #
38
+ def repaint
39
+ return unless @repaint_required
40
+ $log.debug " XXXX PBAR inside repaint #{@color} , #{@fraction} "
41
+ r,c = rowcol
42
+ #value = getvalue_for_paint
43
+ acolor = get_color @bgcolor
44
+ bcolor = get_color @color
45
+ @graphic = @form.window if @graphic.nil? ## HACK messagebox givig this in repaint, 423 not working ??
46
+ len = 0
47
+ w2 = @width - 6 #2 account for brackets and printing of percentage
48
+ if @fraction
49
+ @fraction = 1.0 if @fraction > 1.0
50
+ @fraction = 0 if @fraction < 0
51
+ if @fraction > 0
52
+ len = @fraction * @width
53
+ end
54
+ end
55
+ if @style == :old
56
+ ftext=""
57
+ char = @char || "="
58
+ if @fraction && @fraction >= 0
59
+ len = @fraction * (w2)
60
+ ftext << sprintf("%3d%s",(@fraction * 100).to_i, "%")
61
+ end
62
+ incomplete = w2 - len
63
+ complete = len
64
+ # I am printing 2 times since sometimes the ending bracket gets printed one position less
65
+ str = @surround_chars[0] + " "*w2 + @surround_chars[1] + ftext
66
+ @graphic.printstring r, c, str , acolor,@attr
67
+ str = char*complete
68
+ str[-1] = ">" if char == "=" && complete > 2
69
+ @graphic.printstring r, c+1, str , acolor,@attr
70
+ else
71
+
72
+ char = @char || " "
73
+ # first print the background horizonal bar
74
+ @graphic.printstring r, c, " " * @width , acolor,@attr
75
+
76
+ # if the user has passed a percentage we need to print that in @color
77
+ if @fraction
78
+ #bcolor = get_color @color
79
+ #@fraction = 1.0 if @fraction > 1.0
80
+ #@fraction = 0 if @fraction < 0
81
+ #if @fraction > 0
82
+ #len = @fraction * @width
83
+ #char = @char || " "
84
+
85
+ # if text is to printed over the bar
86
+ if @text
87
+ textcolor = get_color $datacolor, 'black'
88
+ txt = @text
89
+ txt = @text[0..@width] if @text.length > @width
90
+ textattr = 'bold'
91
+ # write the text in a color that contrasts with the background
92
+ # typically black
93
+ @graphic.printstring r, c, txt , textcolor, textattr if @text
94
+
95
+ # now write the text again, in a color that contrasts with the progress
96
+ # bar color that is expanding. However, the text must be padded to len and truncated
97
+ # to len as well. it must be exactly len in size.
98
+ txt = sprintf("%-*s", len, txt)
99
+ if len > 0
100
+ if len < txt.length
101
+ txt = txt[0..len]
102
+ end
103
+ textcolor = get_color $datacolor, 'white', @color
104
+ @graphic.printstring r, c, txt , textcolor, textattr if @text
105
+ end
106
+ else
107
+ # no text was given just print a horizontal bar
108
+ @graphic.printstring r, c, char * len , bcolor, 'reverse'
109
+ end
110
+ end # frac > 0
111
+ end # fraction
112
+ end # style
113
+ @repaint_required = false
114
+ end
115
+ def repaint_old
116
+ end
117
+ # ADD HERE progress
118
+ end