rbhex-core 1.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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/CHANGELOG +2000 -0
- data/LICENSE +56 -0
- data/README.md +44 -0
- data/examples/abasiclist.rb +179 -0
- data/examples/alpmenu.rb +50 -0
- data/examples/app.sample +19 -0
- data/examples/atree.rb +100 -0
- data/examples/bline.rb +136 -0
- data/examples/common/file.rb +45 -0
- data/examples/data/README.markdown +9 -0
- data/examples/data/brew.txt +38 -0
- data/examples/data/color.2 +37 -0
- data/examples/data/gemlist.txt +60 -0
- data/examples/data/lotr.txt +12 -0
- data/examples/data/ports.txt +136 -0
- data/examples/data/table.txt +37 -0
- data/examples/data/tasks.csv +88 -0
- data/examples/data/tasks.txt +27 -0
- data/examples/data/todo.txt +10 -0
- data/examples/data/todo.txt.bak +10 -0
- data/examples/data/todocsv.csv +28 -0
- data/examples/data/unix1.txt +21 -0
- data/examples/data/unix2.txt +11 -0
- data/examples/dbdemo.rb +502 -0
- data/examples/dirtree.rb +94 -0
- data/examples/newtabbedwindow.rb +100 -0
- data/examples/newtesttabp.rb +92 -0
- data/examples/tabular.rb +146 -0
- data/examples/tasks.rb +178 -0
- data/examples/term2.rb +84 -0
- data/examples/testbuttons.rb +296 -0
- data/examples/testcombo.rb +102 -0
- data/examples/testfields.rb +195 -0
- data/examples/testkeypress.rb +72 -0
- data/examples/testlistbox.rb +170 -0
- data/examples/testmessagebox.rb +140 -0
- data/examples/testprogress.rb +116 -0
- data/examples/testree.rb +106 -0
- data/examples/testwsshortcuts.rb +66 -0
- data/examples/testwsshortcuts2.rb +128 -0
- data/lib/rbhex.rb +6 -0
- data/lib/rbhex/core/docs/index.txt +73 -0
- data/lib/rbhex/core/include/action.rb +80 -0
- data/lib/rbhex/core/include/actionmanager.rb +49 -0
- data/lib/rbhex/core/include/appmethods.rb +214 -0
- data/lib/rbhex/core/include/bordertitle.rb +48 -0
- data/lib/rbhex/core/include/chunk.rb +203 -0
- data/lib/rbhex/core/include/io.rb +553 -0
- data/lib/rbhex/core/include/listbindings.rb +74 -0
- data/lib/rbhex/core/include/listcellrenderer.rb +140 -0
- data/lib/rbhex/core/include/listeditable.rb +317 -0
- data/lib/rbhex/core/include/listscrollable.rb +663 -0
- data/lib/rbhex/core/include/listselectable.rb +271 -0
- data/lib/rbhex/core/include/multibuffer.rb +83 -0
- data/lib/rbhex/core/include/orderedhash.rb +77 -0
- data/lib/rbhex/core/include/ractionevent.rb +73 -0
- data/lib/rbhex/core/include/rchangeevent.rb +27 -0
- data/lib/rbhex/core/include/rhistory.rb +95 -0
- data/lib/rbhex/core/include/rinputdataevent.rb +47 -0
- data/lib/rbhex/core/include/vieditable.rb +172 -0
- data/lib/rbhex/core/include/widgetmenu.rb +66 -0
- data/lib/rbhex/core/system/colormap.rb +165 -0
- data/lib/rbhex/core/system/keyboard.rb +150 -0
- data/lib/rbhex/core/system/keydefs.rb +30 -0
- data/lib/rbhex/core/system/ncurses.rb +236 -0
- data/lib/rbhex/core/system/panel.rb +162 -0
- data/lib/rbhex/core/system/window.rb +913 -0
- data/lib/rbhex/core/util/ansiparser.rb +119 -0
- data/lib/rbhex/core/util/app.rb +1228 -0
- data/lib/rbhex/core/util/basestack.rb +410 -0
- data/lib/rbhex/core/util/bottomline.rb +1859 -0
- data/lib/rbhex/core/util/colorparser.rb +77 -0
- data/lib/rbhex/core/util/focusmanager.rb +31 -0
- data/lib/rbhex/core/util/padreader.rb +192 -0
- data/lib/rbhex/core/util/rcommandwindow.rb +604 -0
- data/lib/rbhex/core/util/rdialogs.rb +574 -0
- data/lib/rbhex/core/util/viewer.rb +149 -0
- data/lib/rbhex/core/util/widgetshortcuts.rb +506 -0
- data/lib/rbhex/core/version.rb +5 -0
- data/lib/rbhex/core/widgets/applicationheader.rb +103 -0
- data/lib/rbhex/core/widgets/box.rb +58 -0
- data/lib/rbhex/core/widgets/divider.rb +310 -0
- data/lib/rbhex/core/widgets/keylabelprinter.rb +194 -0
- data/lib/rbhex/core/widgets/rcombo.rb +253 -0
- data/lib/rbhex/core/widgets/rcontainer.rb +415 -0
- data/lib/rbhex/core/widgets/rlink.rb +30 -0
- data/lib/rbhex/core/widgets/rlist.rb +696 -0
- data/lib/rbhex/core/widgets/rmenu.rb +958 -0
- data/lib/rbhex/core/widgets/rmenulink.rb +22 -0
- data/lib/rbhex/core/widgets/rmessagebox.rb +387 -0
- data/lib/rbhex/core/widgets/rprogress.rb +118 -0
- data/lib/rbhex/core/widgets/rtabbedpane.rb +634 -0
- data/lib/rbhex/core/widgets/rtabbedwindow.rb +70 -0
- data/lib/rbhex/core/widgets/rtextarea.rb +960 -0
- data/lib/rbhex/core/widgets/rtextview.rb +739 -0
- data/lib/rbhex/core/widgets/rtree.rb +768 -0
- data/lib/rbhex/core/widgets/rwidget.rb +3277 -0
- data/lib/rbhex/core/widgets/scrollbar.rb +143 -0
- data/lib/rbhex/core/widgets/statusline.rb +113 -0
- data/lib/rbhex/core/widgets/tabular.rb +264 -0
- data/lib/rbhex/core/widgets/tabularwidget.rb +1142 -0
- data/lib/rbhex/core/widgets/textpad.rb +995 -0
- data/lib/rbhex/core/widgets/tree/treecellrenderer.rb +150 -0
- data/lib/rbhex/core/widgets/tree/treemodel.rb +428 -0
- data/rbhex-core.gemspec +32 -0
- metadata +172 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'rbhex/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,387 @@
|
|
|
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 'rbhex'
|
|
24
|
+
require 'rbhex/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
|
+
yield_or_eval &block if block_given?
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
def item widget
|
|
73
|
+
# remove from existing form if set FIXME
|
|
74
|
+
if widget.form
|
|
75
|
+
f = widget.form
|
|
76
|
+
f.remove_widget widget
|
|
77
|
+
end
|
|
78
|
+
@maxrow ||= 3
|
|
79
|
+
widget.set_form @form
|
|
80
|
+
widget.row ||= 0
|
|
81
|
+
widget.col ||= 0
|
|
82
|
+
if widget.row == 0
|
|
83
|
+
widget.row = [@maxrow+1, 3].max if widget.row == 0
|
|
84
|
+
else
|
|
85
|
+
widget.row += @row_offset
|
|
86
|
+
end
|
|
87
|
+
if widget.col === 0
|
|
88
|
+
widget.col = 5 if widget.col === 0
|
|
89
|
+
else
|
|
90
|
+
# i don't know button_offset as yet
|
|
91
|
+
widget.col += @col_offset
|
|
92
|
+
end
|
|
93
|
+
# in most cases this override is okay, but what if user has set it
|
|
94
|
+
# The problem is that widget and field are doing a default setting so i don't know
|
|
95
|
+
# if user has set or widget has done a default setting. NOTE
|
|
96
|
+
widget.color ||= @color # we are overriding colors, how to avoid since widget sets it
|
|
97
|
+
widget.bgcolor ||= @bgcolor
|
|
98
|
+
widget.attr = @attr if @attr # we are overriding what user has put. DARN !
|
|
99
|
+
@maxrow = widget.row if widget.row > @maxrow
|
|
100
|
+
@suggested_h = @height || @maxrow+6
|
|
101
|
+
@suggested_w ||= 0
|
|
102
|
+
@suggested_w = widget.col + 15 if widget.col > @suggested_w
|
|
103
|
+
# if w's given col is > width then add to suggested_w or text.length
|
|
104
|
+
end
|
|
105
|
+
alias :add :item
|
|
106
|
+
# returns button index
|
|
107
|
+
# Call this after instantiating the window
|
|
108
|
+
def run
|
|
109
|
+
repaint
|
|
110
|
+
@form.repaint
|
|
111
|
+
@window.wrefresh
|
|
112
|
+
return handle_keys
|
|
113
|
+
end
|
|
114
|
+
def repaint
|
|
115
|
+
_create_window unless @window
|
|
116
|
+
acolor = get_color $reverscolor # this implicitly uses color and bgcolor fooling me often
|
|
117
|
+
$log.debug " MESSAGE BOX bg:#{@bgcolor} , co:#{@color} , colorpair:#{acolor}"
|
|
118
|
+
@window.wbkgd(Ncurses.COLOR_PAIR(acolor)); # does not work on xterm-256color
|
|
119
|
+
|
|
120
|
+
#print_borders unless @suppress_borders # do this once only, unless everything changes
|
|
121
|
+
#@window.print_border_mb 1,2, @height, @width, $normalcolor, FFI::NCurses::A_REVERSE
|
|
122
|
+
@color_pair = get_color($datacolor)
|
|
123
|
+
bordercolor = @border_color || @color_pair
|
|
124
|
+
borderatt = @border_attrib || Ncurses::A_NORMAL
|
|
125
|
+
@window.wattron(Ncurses.COLOR_PAIR(bordercolor) | (borderatt || FFI::NCurses::A_NORMAL))
|
|
126
|
+
@window.print_border_mb 1,2, @height, @width, bordercolor, borderatt
|
|
127
|
+
@window.wattroff(Ncurses.COLOR_PAIR(bordercolor) | (borderatt || FFI::NCurses::A_NORMAL))
|
|
128
|
+
@title ||= "+-+"
|
|
129
|
+
title = " "+@title+" "
|
|
130
|
+
@window.printstring(@row=1,@col=(@width-title.length)/2,title, color=$normalcolor)
|
|
131
|
+
#print_message if @message
|
|
132
|
+
create_action_buttons unless @action_buttons
|
|
133
|
+
end
|
|
134
|
+
# Pass a short message to be printed.
|
|
135
|
+
# This creates a label for a short message, and a field for a long one.
|
|
136
|
+
# @yield field created
|
|
137
|
+
# @param [String] text to display
|
|
138
|
+
def message message # yield label or field being used for display for further customization
|
|
139
|
+
@suggested_h = @height || 10
|
|
140
|
+
message = message.gsub(/[\n\r\t]/,' ') rescue message
|
|
141
|
+
message_col = 5
|
|
142
|
+
@suggested_w = @width || [message.size + 8 + message_col , FFI::NCurses.COLS-2].min
|
|
143
|
+
r = 3
|
|
144
|
+
len = message.length
|
|
145
|
+
@suggested_w = len + 8 + message_col if len < @suggested_w - 8 - message_col
|
|
146
|
+
|
|
147
|
+
display_length = @suggested_w-8
|
|
148
|
+
display_length -= message_col
|
|
149
|
+
message_height = 2
|
|
150
|
+
clr = @color || :white
|
|
151
|
+
bgclr = @bgcolor || :black
|
|
152
|
+
|
|
153
|
+
# trying this out. sometimes very long labels get truncated, so i give a field in wchich user
|
|
154
|
+
# can use arrow key or C-a and C-e
|
|
155
|
+
if message.size > display_length
|
|
156
|
+
message_label = RubyCurses::Field.new @form, {:text => message, :name=>"message_label",
|
|
157
|
+
:row => r, :col => message_col, :display_length => display_length,
|
|
158
|
+
:bgcolor => bgclr , :color => clr, :editable => false}
|
|
159
|
+
else
|
|
160
|
+
message_label = RubyCurses::Label.new @form, {:text => message, :name=>"message_label",
|
|
161
|
+
:row => r, :col => message_col, :display_length => display_length,
|
|
162
|
+
:height => message_height, :bgcolor => bgclr , :color => clr}
|
|
163
|
+
end
|
|
164
|
+
@maxrow = 3
|
|
165
|
+
yield message_label if block_given?
|
|
166
|
+
end
|
|
167
|
+
alias :message= :message
|
|
168
|
+
|
|
169
|
+
# This is for larger messages, or messages where the size is not known.
|
|
170
|
+
# A textview object is created and yielded.
|
|
171
|
+
#
|
|
172
|
+
def text message
|
|
173
|
+
@suggested_w = @width || (FFI::NCurses.COLS * 0.80).floor
|
|
174
|
+
@suggested_h = @height || (FFI::NCurses.LINES * 0.80).floor
|
|
175
|
+
|
|
176
|
+
message_col = 3
|
|
177
|
+
r = 2
|
|
178
|
+
display_length = @suggested_w-4
|
|
179
|
+
display_length -= message_col
|
|
180
|
+
clr = @color || :white
|
|
181
|
+
bgclr = @bgcolor || :black
|
|
182
|
+
|
|
183
|
+
if message.is_a? Array
|
|
184
|
+
l = longest_in_list message
|
|
185
|
+
if l > @suggested_w
|
|
186
|
+
if l < FFI::NCurses.COLS
|
|
187
|
+
#@suggested_w = l
|
|
188
|
+
@suggested_w = FFI::NCurses.COLS-2
|
|
189
|
+
else
|
|
190
|
+
@suggested_w = FFI::NCurses.COLS-2
|
|
191
|
+
end
|
|
192
|
+
display_length = @suggested_w-6
|
|
193
|
+
end
|
|
194
|
+
# reduce width and height if you can based on array contents
|
|
195
|
+
else
|
|
196
|
+
message = wrap_text(message, display_length).split("\n")
|
|
197
|
+
end
|
|
198
|
+
message_height = message.size + 8
|
|
199
|
+
# reduce if possible if its not required.
|
|
200
|
+
#
|
|
201
|
+
r1 = (FFI::NCurses.LINES-@suggested_h)/2
|
|
202
|
+
r1 = r1.floor
|
|
203
|
+
w = @suggested_w
|
|
204
|
+
c1 = (FFI::NCurses.COLS-w)/2
|
|
205
|
+
c1 = c1.floor
|
|
206
|
+
@suggested_row = r1
|
|
207
|
+
@suggested_col = c1
|
|
208
|
+
brow = @button_row || @suggested_h-4
|
|
209
|
+
available_ht = brow - r + 1
|
|
210
|
+
message_height = [message_height, available_ht].min
|
|
211
|
+
require 'rbhex/core/widgets/rtextview'
|
|
212
|
+
message_label = RubyCurses::TextView.new @form, {:name=>"message_label", :text => message,
|
|
213
|
+
:row => r, :col => message_col, :width => display_length, :suppress_borders => true,
|
|
214
|
+
:height => message_height, :bgcolor => bgclr , :color => clr}
|
|
215
|
+
#message_label.set_content message
|
|
216
|
+
yield message_label if block_given?
|
|
217
|
+
|
|
218
|
+
end
|
|
219
|
+
alias :text= :text
|
|
220
|
+
|
|
221
|
+
# returns button index (or in some cases, whatever value was thrown
|
|
222
|
+
# if user did not specify any button_type but gave his own and did throw (:close, x)
|
|
223
|
+
private
|
|
224
|
+
def handle_keys
|
|
225
|
+
buttonindex = catch(:close) do
|
|
226
|
+
while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
|
|
227
|
+
break if ch == ?\C-q.getbyte(0) || ch == 2727 # added double esc
|
|
228
|
+
begin
|
|
229
|
+
@form.handle_key(ch)
|
|
230
|
+
@window.wrefresh
|
|
231
|
+
rescue => err
|
|
232
|
+
$log.debug( err) if err
|
|
233
|
+
$log.debug(err.backtrace.join("\n")) if err
|
|
234
|
+
textdialog ["Error in Messagebox: #{err} ", *err.backtrace], :title => "Exception"
|
|
235
|
+
@window.refresh # otherwise the window keeps showing (new FFI-ncurses issue)
|
|
236
|
+
$error_message.value = ""
|
|
237
|
+
ensure
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
end # while loop
|
|
241
|
+
end # close
|
|
242
|
+
$log.debug "XXX: CALLER GOT #{buttonindex} "
|
|
243
|
+
@window.destroy
|
|
244
|
+
return buttonindex
|
|
245
|
+
end
|
|
246
|
+
private
|
|
247
|
+
def create_action_buttons
|
|
248
|
+
return unless @button_type
|
|
249
|
+
@default_button = 0 if !@default_button
|
|
250
|
+
case @button_type.to_s.downcase
|
|
251
|
+
when "ok"
|
|
252
|
+
make_buttons ["&OK"]
|
|
253
|
+
when "ok_cancel" #, "input", "list", "field_list"
|
|
254
|
+
make_buttons %w[&OK &Cancel]
|
|
255
|
+
when "ok_apply_cancel" #, "input", "list", "field_list"
|
|
256
|
+
make_buttons %w[&OK &Apply &Cancel]
|
|
257
|
+
when "yes_no"
|
|
258
|
+
make_buttons %w[&Yes &No]
|
|
259
|
+
when "yes_no_cancel"
|
|
260
|
+
make_buttons ["&Yes", "&No", "&Cancel"]
|
|
261
|
+
when "custom"
|
|
262
|
+
raise "Blank list of buttons passed to custom" if @buttons.nil? or @buttons.size == 0
|
|
263
|
+
make_buttons @buttons
|
|
264
|
+
else
|
|
265
|
+
$log.warn "No buttontype passed for creating tabbedpane. Not creating any"
|
|
266
|
+
#make_buttons ["&OK"]
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
private
|
|
270
|
+
def make_buttons names
|
|
271
|
+
@action_buttons = []
|
|
272
|
+
$log.debug "XXX: came to NTP make buttons FORM= #{@form.name} names #{names} "
|
|
273
|
+
total = names.inject(0) {|total, item| total + item.length + 4}
|
|
274
|
+
bcol = align_buttons total, @button_orientation
|
|
275
|
+
|
|
276
|
+
# this craps out when height is zero
|
|
277
|
+
brow = @row + @height-4
|
|
278
|
+
brow = FFI::NCurses.LINES-2 if brow < 0
|
|
279
|
+
@button_row = brow
|
|
280
|
+
#color_pair = get_color($normalcolor)
|
|
281
|
+
#@window.wattron(Ncurses.COLOR_PAIR(color_pair) | (@attrib || FFI::NCurses::A_NORMAL))
|
|
282
|
+
#@window.mvwhline( brow-1, @col+1, Ncurses::ACS_HLINE, @width-2)
|
|
283
|
+
#@window.wattroff(Ncurses.COLOR_PAIR(color_pair) | (@attrib || FFI::NCurses::A_NORMAL))
|
|
284
|
+
$log.debug "XXX: putting buttons :on #{brow} , #{bcol} : #{@row} , #{@height} "
|
|
285
|
+
button_ct =0
|
|
286
|
+
tpp = self
|
|
287
|
+
_color = @color
|
|
288
|
+
_bgcolor = @bgcolor
|
|
289
|
+
names.each_with_index do |bname, ix|
|
|
290
|
+
text = bname
|
|
291
|
+
|
|
292
|
+
button = Button.new @form do
|
|
293
|
+
text text
|
|
294
|
+
name bname
|
|
295
|
+
row brow
|
|
296
|
+
col bcol
|
|
297
|
+
highlight_background $reversecolor
|
|
298
|
+
color _color
|
|
299
|
+
bgcolor _bgcolor
|
|
300
|
+
end
|
|
301
|
+
@action_buttons << button
|
|
302
|
+
button.form = @form
|
|
303
|
+
button.override_graphic @graphic
|
|
304
|
+
button.default_button(true) if (@default_button && @default_button == ix)
|
|
305
|
+
index = button_ct
|
|
306
|
+
tpp = self
|
|
307
|
+
button.command { |form| @selected_index = index; @stop = true;
|
|
308
|
+
# ActionEvent has source event and action_command
|
|
309
|
+
action = ActionEvent.new(tpp, index, button.text)
|
|
310
|
+
if @command
|
|
311
|
+
@command.call(action, @args)
|
|
312
|
+
else
|
|
313
|
+
# default action if you don't specify anything
|
|
314
|
+
throw(:close, @selected_index)
|
|
315
|
+
end
|
|
316
|
+
}
|
|
317
|
+
# we map the key of the button to the alphabet so user can press just the mnemonic, and not
|
|
318
|
+
# just the Alt combination.
|
|
319
|
+
mn = button.mnemonic
|
|
320
|
+
@form.bind_key(mn.downcase) { button.fire} if mn
|
|
321
|
+
button_ct += 1
|
|
322
|
+
bcol += text.length+6
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
def _create_window
|
|
326
|
+
|
|
327
|
+
@width ||= @suggested_w || 60
|
|
328
|
+
@height = @suggested_h || 10
|
|
329
|
+
if @suggested_row
|
|
330
|
+
@row = @suggested_row
|
|
331
|
+
else
|
|
332
|
+
@row = ((FFI::NCurses.LINES-@height)/2).floor
|
|
333
|
+
end
|
|
334
|
+
if @suggested_col
|
|
335
|
+
@col = @suggested_col
|
|
336
|
+
else
|
|
337
|
+
w = @width
|
|
338
|
+
@col = ((FFI::NCurses.COLS-w)/2).floor
|
|
339
|
+
end
|
|
340
|
+
@window = VER::Window.new :height => @height, :width => @width, :top => @row, :left => @col
|
|
341
|
+
@graphic = @window
|
|
342
|
+
@form.window = @window
|
|
343
|
+
end
|
|
344
|
+
#
|
|
345
|
+
# specify a code block to be fired when an action button is pressed
|
|
346
|
+
# This will supply (to the code block) an ActionEvent followed by
|
|
347
|
+
# whatever args that were given.
|
|
348
|
+
# ActionEvent contains source, event, action_command which map to
|
|
349
|
+
# the messagebox, selected_index (base 0) and button title.
|
|
350
|
+
#
|
|
351
|
+
public
|
|
352
|
+
def command *args, &blk
|
|
353
|
+
@command = blk
|
|
354
|
+
@args = args
|
|
355
|
+
end
|
|
356
|
+
# returns array of widgets declared for querying
|
|
357
|
+
def widgets
|
|
358
|
+
@form.widgets
|
|
359
|
+
end
|
|
360
|
+
# returns a widget based on offset, or name (if you gave it a :name)
|
|
361
|
+
# e.g. a list was declared and we wish to know the selected_indices
|
|
362
|
+
def widget n
|
|
363
|
+
case n
|
|
364
|
+
when Fixnum
|
|
365
|
+
@form.widgets[n]
|
|
366
|
+
when String, Symbol
|
|
367
|
+
@form.by_name[n]
|
|
368
|
+
else
|
|
369
|
+
raise "messagebox.widget can't handle #{n.class} "
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# returns starting column for buttons to start painting
|
|
374
|
+
# Not very correct in case of :right
|
|
375
|
+
private
|
|
376
|
+
def align_buttons textlen, orient=:center
|
|
377
|
+
case orient
|
|
378
|
+
when :left
|
|
379
|
+
return @col+@col_offset
|
|
380
|
+
when :right
|
|
381
|
+
return (@width-textlen)-5
|
|
382
|
+
else
|
|
383
|
+
return (@width-textlen)/2
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#require 'ncurses'
|
|
2
|
+
require 'logger'
|
|
3
|
+
require 'rbhex'
|
|
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
|