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,195 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
require 'rbhex'
|
|
3
|
+
require 'rbhex/core/include/appmethods.rb'
|
|
4
|
+
def help_text
|
|
5
|
+
<<-eos
|
|
6
|
+
FIELD HELP
|
|
7
|
+
|
|
8
|
+
This is some help text for Fields
|
|
9
|
+
|
|
10
|
+
Name is non-focusable
|
|
11
|
+
Line takes numbers from 1 to 200
|
|
12
|
+
Regex takes only alpha
|
|
13
|
+
Password takes only scotty or tiger or pass or qwerty, and maybe left blank
|
|
14
|
+
|
|
15
|
+
Use Alt (meta) with the highlighted character to jump to that field.
|
|
16
|
+
Alt-m goes to line, Alt-p to password.
|
|
17
|
+
|
|
18
|
+
Notice how the field label becomes red when focused (as in Pine/Alpine). This uses
|
|
19
|
+
the event :ENTER and :LEAVE
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
F10 - Exit application (also C-q)
|
|
24
|
+
Alt-! - Drop to shell
|
|
25
|
+
C-x c - Drop to shell
|
|
26
|
+
C-x l - list of files
|
|
27
|
+
C-x p - process list
|
|
28
|
+
C-x d - disk usage list
|
|
29
|
+
C-x s - Git status
|
|
30
|
+
C-x w - Git whatchanged
|
|
31
|
+
Alt-x - Command mode (<tab> to see commands and select)
|
|
32
|
+
|
|
33
|
+
F3 - View log
|
|
34
|
+
F4 - prompt for unix command and display in viewer
|
|
35
|
+
F5 - Drop to shell
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
-----------------------------------------------------------------------
|
|
39
|
+
eos
|
|
40
|
+
end
|
|
41
|
+
if $0 == __FILE__
|
|
42
|
+
|
|
43
|
+
include RubyCurses
|
|
44
|
+
include RubyCurses::Utils
|
|
45
|
+
|
|
46
|
+
begin
|
|
47
|
+
# Initialize curses
|
|
48
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
|
49
|
+
path = File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")
|
|
50
|
+
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
|
|
51
|
+
$log = Logger.new(path)
|
|
52
|
+
$log.level = Logger::DEBUG
|
|
53
|
+
|
|
54
|
+
@lookfeel = :classic # :dialog # or :classic
|
|
55
|
+
|
|
56
|
+
@window = VER::Window.root_window
|
|
57
|
+
# Initialize few color pairs
|
|
58
|
+
# Create the window to be associated with the form
|
|
59
|
+
# Un post form and free the memory
|
|
60
|
+
|
|
61
|
+
catch(:close) do
|
|
62
|
+
colors = Ncurses.COLORS
|
|
63
|
+
$log.debug "START #{colors} colors testfield.rb --------- #{@window} "
|
|
64
|
+
@form = Form.new @window
|
|
65
|
+
title = (" "*30) + "Demo of Field (F10 quits, F1 help) " + Rbhex::Core::VERSION
|
|
66
|
+
Label.new @form, {:text => title, :row => 1, :col => 0, :color => :green, :bgcolor => :black}
|
|
67
|
+
r = 3; fc = 12;
|
|
68
|
+
mnemonics = %w[ n l r p]
|
|
69
|
+
%w[ name line regex password].each_with_index do |w,i|
|
|
70
|
+
field = Field.new @form do
|
|
71
|
+
name w
|
|
72
|
+
row r
|
|
73
|
+
col fc
|
|
74
|
+
display_length 30
|
|
75
|
+
#set_buffer "abcd "
|
|
76
|
+
set_label Label.new @form, {:text => w, :color=> :cyan, :mnemonic => mnemonics[i]}
|
|
77
|
+
end
|
|
78
|
+
r += 1
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
f = @form.by_name["line"]
|
|
82
|
+
f.display_length(3).set_buffer(24).valid_range(1..200).
|
|
83
|
+
maxlen(3).
|
|
84
|
+
type(:integer)
|
|
85
|
+
|
|
86
|
+
@form.by_name["name"].set_buffer( "Not focusable").
|
|
87
|
+
set_focusable(false)
|
|
88
|
+
|
|
89
|
+
@form.by_name["regex"].valid_regex(/^[A-Z][a-z]*/).
|
|
90
|
+
set_buffer( "SYNOP").
|
|
91
|
+
display_length(10).
|
|
92
|
+
maxlen = 20
|
|
93
|
+
|
|
94
|
+
@form.by_name["password"].set_buffer("").
|
|
95
|
+
show('*').
|
|
96
|
+
color(:red).
|
|
97
|
+
values(%w[scotty tiger secret pass qwerty]).
|
|
98
|
+
null_allowed true
|
|
99
|
+
|
|
100
|
+
r += 3
|
|
101
|
+
l1 = Label.new @form, :name => "profile", :attr => 'bold', :text => "Profile", :row => r, :col => fc
|
|
102
|
+
r += 1
|
|
103
|
+
f1 = Field.new @form, :name => "name1", :maxlen => 20, :display_length => 20, :bgcolor => :white,
|
|
104
|
+
:color => :black, :text => "abc", :label => ' Name: ', :row => r, :col => fc
|
|
105
|
+
r += 1
|
|
106
|
+
f2 = Field.new @form, :name => "email", :display_length => 20, :bgcolor => :white,
|
|
107
|
+
:color => :blue, :text => "me@google.com", :label => ' Email: ', :row => r, :col => fc
|
|
108
|
+
r += 3
|
|
109
|
+
f3 = Field.new @form
|
|
110
|
+
f3.name("mobile").display_length(20).bgcolor(:white).color(:black).
|
|
111
|
+
text("").label(' Mobile: ').
|
|
112
|
+
row(r).col(fc).
|
|
113
|
+
type(:integer)
|
|
114
|
+
r += 2
|
|
115
|
+
|
|
116
|
+
Field.new(@form).
|
|
117
|
+
name("landline").display_length(20).bgcolor(:white).color(:black).
|
|
118
|
+
text("").label('Landline: ').
|
|
119
|
+
row(r).col(fc).
|
|
120
|
+
type(:integer)
|
|
121
|
+
# a form level event, whenever any widget is focussed, make the label red
|
|
122
|
+
@form.bind(:ENTER) { |f| f.label && f.label.bgcolor = :red if (f.respond_to? :label and f.label.respond_to?(:bgcolor))}
|
|
123
|
+
@form.bind(:LEAVE) { |f| f.label && f.label.bgcolor = 'black' if (f.respond_to? :label and f.label.respond_to?(:bgcolor))}
|
|
124
|
+
|
|
125
|
+
@form.bind_key(FFI::NCurses::KEY_F3,'view log') {
|
|
126
|
+
require 'rbhex/core/util/viewer'
|
|
127
|
+
RubyCurses::Viewer.view(path || "rbc13.log", :close_key => KEY_ENTER, :title => "<Enter> to close")
|
|
128
|
+
}
|
|
129
|
+
@form.bind_key(FFI::NCurses::KEY_F4, 'system command') { shell_output }
|
|
130
|
+
@form.bind_key(FFI::NCurses::KEY_F5, 'shell') { suspend }
|
|
131
|
+
@form.bind_key([?\C-x,?c], 'shell') { suspend }
|
|
132
|
+
@form.bind_key(?\M-!, 'shell') { suspend }
|
|
133
|
+
@form.bind_key([?\C-x,?l], 'ls -al') { run_command "ls -al" }
|
|
134
|
+
@form.bind_key([?\C-x,?p], 'ps -l') { run_command "ps -l" }
|
|
135
|
+
@form.bind_key([?\C-x,?d], 'df -h') { run_command "df -h" }
|
|
136
|
+
#@form.bind_key([?\C-x,?d], 'git diff') { run_command "git diff --name-status" }
|
|
137
|
+
@form.bind_key([?\C-x, ?s], 'git st') { run_command "git status" }
|
|
138
|
+
@form.bind_key([?\C-x,?w], 'git whatchanged') { run_command "git whatchanged" }
|
|
139
|
+
|
|
140
|
+
@form.help_manager.help_text = help_text
|
|
141
|
+
#@form.bind_key(FFI::NCurses::KEY_F1, 'help') { display_app_help help_text() }
|
|
142
|
+
@form.bind_key(FFI::NCurses::KEY_F1, 'help') { display_app_help }
|
|
143
|
+
@form.repaint
|
|
144
|
+
@window.wrefresh
|
|
145
|
+
Ncurses::Panel.update_panels
|
|
146
|
+
|
|
147
|
+
# the main loop
|
|
148
|
+
|
|
149
|
+
while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 )
|
|
150
|
+
break if ch == ?\C-q.getbyte(0)
|
|
151
|
+
begin
|
|
152
|
+
@form.handle_key(ch)
|
|
153
|
+
|
|
154
|
+
rescue FieldValidationException => fve
|
|
155
|
+
alert fve.to_s
|
|
156
|
+
|
|
157
|
+
f = @form.get_current_field
|
|
158
|
+
# lets restore the value
|
|
159
|
+
if f.respond_to? :restore_original_value
|
|
160
|
+
f.restore_original_value
|
|
161
|
+
@form.repaint
|
|
162
|
+
end
|
|
163
|
+
$error_message.value = ""
|
|
164
|
+
rescue => err
|
|
165
|
+
$log.error( err) if err
|
|
166
|
+
$log.error(err.backtrace.join("\n")) if err
|
|
167
|
+
textdialog err
|
|
168
|
+
$error_message.value = ""
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# this should be avoided, we should not muffle the exception and set a variable
|
|
172
|
+
# However, we have been doing that
|
|
173
|
+
if $error_message.get_value != ""
|
|
174
|
+
if @lookfeel == :dialog
|
|
175
|
+
alert($error_message, {:bgcolor => :red, 'color' => 'yellow'}) if $error_message.get_value != ""
|
|
176
|
+
else
|
|
177
|
+
print_error_message $error_message, {:bgcolor => :red, :color => :yellow}
|
|
178
|
+
end
|
|
179
|
+
$error_message.value = ""
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
@window.wrefresh
|
|
183
|
+
end # while loop
|
|
184
|
+
end # catch
|
|
185
|
+
rescue => ex
|
|
186
|
+
ensure
|
|
187
|
+
$log.debug " -==== EXCEPTION =====-"
|
|
188
|
+
$log.debug( ex) if ex
|
|
189
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
|
190
|
+
@window.destroy if !@window.nil?
|
|
191
|
+
VER::stop_ncurses
|
|
192
|
+
puts ex if ex
|
|
193
|
+
puts(ex.backtrace.join("\n")) if ex
|
|
194
|
+
end
|
|
195
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# demo to test keypresses
|
|
2
|
+
# press any key and see the value that ncurses or our routines catch.
|
|
3
|
+
# Press alt and control combinations and Function keys
|
|
4
|
+
# Ideally each key should return only one value. Sometimes, some TERM setting
|
|
5
|
+
# or terminal emulator may not give correct values or may give different values
|
|
6
|
+
# from what we are expecting.
|
|
7
|
+
# Exit using 'q'.
|
|
8
|
+
require 'logger'
|
|
9
|
+
require 'rbhex'
|
|
10
|
+
require 'rbhex/core/widgets/rtextview'
|
|
11
|
+
if $0 == __FILE__
|
|
12
|
+
include RubyCurses
|
|
13
|
+
include RubyCurses::Utils
|
|
14
|
+
|
|
15
|
+
begin
|
|
16
|
+
# Initialize curses
|
|
17
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
|
18
|
+
$log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
|
|
19
|
+
|
|
20
|
+
$log.level = Logger::DEBUG
|
|
21
|
+
|
|
22
|
+
@window = VER::Window.root_window
|
|
23
|
+
|
|
24
|
+
catch(:close) do
|
|
25
|
+
colors = Ncurses.COLORS
|
|
26
|
+
$log.debug "START #{colors} colors ---------"
|
|
27
|
+
@form = Form.new @window
|
|
28
|
+
r = 1; c = 30;
|
|
29
|
+
|
|
30
|
+
# please use a hash to pass these values, avoid this old style
|
|
31
|
+
# i want to move away from it as it comlpicates code
|
|
32
|
+
texta = TextView.new @form do
|
|
33
|
+
name "mytext"
|
|
34
|
+
row r
|
|
35
|
+
col c
|
|
36
|
+
width 60
|
|
37
|
+
height 15
|
|
38
|
+
#editable false
|
|
39
|
+
focusable false
|
|
40
|
+
title "[ Keypresses ]"
|
|
41
|
+
#title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
|
42
|
+
title_attrib (Ncurses::A_BOLD)
|
|
43
|
+
end
|
|
44
|
+
help = "q to quit. Check keys. F1..10, C-a..z, Alt a-zA-Z0-9, C-left,rt, Sh-F5..10 .: #{$0}"
|
|
45
|
+
help1 = "Press in quick succession: 1) M-[, w and (2) M-[, M-w. (3) M-Sh-O, w."
|
|
46
|
+
RubyCurses::Label.new @form, {'text' => help, "row" => 21, "col" => 2, "color" => "yellow"}
|
|
47
|
+
RubyCurses::Label.new @form, {'text' => help1, "row" => 22, "col" => 2, "color" => "green"}
|
|
48
|
+
|
|
49
|
+
@form.repaint
|
|
50
|
+
@window.wrefresh
|
|
51
|
+
Ncurses::Panel.update_panels
|
|
52
|
+
while((ch = @window.getchar()) != 0 )
|
|
53
|
+
str = keycode_tos ch
|
|
54
|
+
$log.debug "#{ch} got (#{str})"
|
|
55
|
+
texta << "#{ch} got (#{str})"
|
|
56
|
+
texta.goto_end
|
|
57
|
+
texta.repaint
|
|
58
|
+
@form.repaint
|
|
59
|
+
@window.wrefresh
|
|
60
|
+
break if ch == ?\q.getbyte(0)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
rescue => ex
|
|
64
|
+
ensure
|
|
65
|
+
@window.destroy if !@window.nil?
|
|
66
|
+
VER::stop_ncurses
|
|
67
|
+
p ex if ex
|
|
68
|
+
p(ex.backtrace.join("\n")) if ex
|
|
69
|
+
$log.debug( ex) if ex
|
|
70
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# NOTE: If the listbox is empty, that could mean that you have not generated
|
|
2
|
+
# ri documentation for this version of ruby. You can do so by doing:
|
|
3
|
+
# rvm docs generate-ri
|
|
4
|
+
# or
|
|
5
|
+
# rvm docs generate
|
|
6
|
+
# (This assumes you are using rvm)
|
|
7
|
+
#
|
|
8
|
+
# WARNING : IF THIS PROGRAM HANGS check the ri command
|
|
9
|
+
# Maybe your version of ri has different options and is going interactive.
|
|
10
|
+
# ruby 1.9.3's ri requires a -l option or else if becomes interactive.
|
|
11
|
+
# this program tests out a listbox
|
|
12
|
+
# This is written in the old style where we start and end ncurses and initiate a
|
|
13
|
+
# getch loop. It gives more control.
|
|
14
|
+
# The new style is to use App which does the ncurses setup and teardown, as well
|
|
15
|
+
# as manages keys. It also takes care of logger and includes major stuff.
|
|
16
|
+
require 'logger'
|
|
17
|
+
require 'rbhex'
|
|
18
|
+
require 'rbhex/core/widgets/rlist'
|
|
19
|
+
require 'rbhex/core/widgets/rtextview'
|
|
20
|
+
require 'rbhex/core/include/vieditable'
|
|
21
|
+
#require 'rbhex/experimental/widgets/undomanager'
|
|
22
|
+
class RubyCurses::List
|
|
23
|
+
# vieditable includes listeditable which
|
|
24
|
+
# does bring in some functions which can crash program like x and X TODO
|
|
25
|
+
# also, f overrides list f mapping. TODO
|
|
26
|
+
include ViEditable
|
|
27
|
+
end
|
|
28
|
+
def my_help_text
|
|
29
|
+
<<-eos
|
|
30
|
+
|
|
31
|
+
=========================================================================
|
|
32
|
+
Basic Usage
|
|
33
|
+
|
|
34
|
+
Press <ENTER> on a class name on the first list, to view ri information
|
|
35
|
+
for it on the right.
|
|
36
|
+
|
|
37
|
+
Tab to right area, and press <ENTER> on a method name, to see its details
|
|
38
|
+
Press / <slash> in any box to search. e.g /String will take you to the
|
|
39
|
+
first occurrence of String. <n> will take you to next.
|
|
40
|
+
|
|
41
|
+
To go quickly to first class starting with 'S', type <f> followed by <S>.
|
|
42
|
+
Then press <n> to go to next match.
|
|
43
|
+
|
|
44
|
+
=========================================================================
|
|
45
|
+
Vim Edit Keys
|
|
46
|
+
|
|
47
|
+
The list on left has some extra vim keys enabled such as :
|
|
48
|
+
yy - yank/copy current line/s
|
|
49
|
+
P, p - paste after or before
|
|
50
|
+
dd - delete current line
|
|
51
|
+
o - insert a line after this one
|
|
52
|
+
C - change content of current line
|
|
53
|
+
These are not of use here, but are demonstrative of list capabilities.
|
|
54
|
+
|
|
55
|
+
=========================================================================
|
|
56
|
+
Buffers
|
|
57
|
+
|
|
58
|
+
Ordinary a textview contains only one buffer. However, the one on the right
|
|
59
|
+
is extended for multiple buffers. Pressing ENTER on the left on several
|
|
60
|
+
rows opens multiple buffers on the right. Use M-n (Alt-N) and M-p to navigate.
|
|
61
|
+
ALternatively, : maps to a menu, so :n and :p may also be used.
|
|
62
|
+
<BACKSPACE> will also go to previous buffer, like a browser.
|
|
63
|
+
|
|
64
|
+
=========================================================================
|
|
65
|
+
Press <M-n> for next help screen, or try :n
|
|
66
|
+
|
|
67
|
+
eos
|
|
68
|
+
end
|
|
69
|
+
if $0 == __FILE__
|
|
70
|
+
include RubyCurses
|
|
71
|
+
|
|
72
|
+
begin
|
|
73
|
+
# Initialize curses
|
|
74
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
|
75
|
+
$log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
|
|
76
|
+
$log.level = Logger::DEBUG
|
|
77
|
+
|
|
78
|
+
@window = VER::Window.root_window
|
|
79
|
+
$catch_alt_digits = true; # emacs like alt-1..9 numeric arguments
|
|
80
|
+
install_help_text my_help_text
|
|
81
|
+
# Initialize few color pairs
|
|
82
|
+
# Create the window to be associated with the form
|
|
83
|
+
# Un post form and free the memory
|
|
84
|
+
|
|
85
|
+
catch(:close) do
|
|
86
|
+
@form = Form.new @window
|
|
87
|
+
@form.bind_key(KEY_F1, 'help'){ display_app_help }
|
|
88
|
+
|
|
89
|
+
# this is the old style of printing something directly on the window.
|
|
90
|
+
# The new style is to use a header
|
|
91
|
+
@form.window.printstring 0, 30, "Demo of Listbox - some vim keys", $normalcolor, BOLD
|
|
92
|
+
r = 1; fc = 1;
|
|
93
|
+
|
|
94
|
+
# this is the old style of using a label at the screen bottom, you can use the status_line
|
|
95
|
+
|
|
96
|
+
v = "F10 quits. F1 Help. Try j k gg G o O C dd f<char> w yy p P / . Press ENTER on Class or Method"
|
|
97
|
+
var = RubyCurses::Label.new @form, {'text' => v, "row" => FFI::NCurses.LINES-2,
|
|
98
|
+
"col" => fc, "display_length" => 100}
|
|
99
|
+
|
|
100
|
+
h = FFI::NCurses.LINES-3
|
|
101
|
+
file = "./data/ports.txt"
|
|
102
|
+
#mylist = File.open(file,'r').readlines
|
|
103
|
+
mylist = `ri -l `.split("\n")
|
|
104
|
+
w = 25
|
|
105
|
+
#0.upto(100) { |v| mylist << "#{v} scrollable data" }
|
|
106
|
+
#
|
|
107
|
+
listb = List.new @form, :name => "mylist" ,
|
|
108
|
+
:row => r ,
|
|
109
|
+
:col => 1 ,
|
|
110
|
+
:width => w,
|
|
111
|
+
:height => h,
|
|
112
|
+
:list => mylist,
|
|
113
|
+
:selection_mode => :SINGLE,
|
|
114
|
+
:show_selector => true,
|
|
115
|
+
#row_selected_symbol "[X] "
|
|
116
|
+
#row_unselected_symbol "[ ] "
|
|
117
|
+
:title => " Ruby Classes "
|
|
118
|
+
#title_attrib 'reverse'
|
|
119
|
+
listb.one_key_selection = false # this allows us to map keys to methods
|
|
120
|
+
listb.vieditable_init_listbox
|
|
121
|
+
include Io
|
|
122
|
+
listb.bind_key(?r, 'get file'){ get_file("Get a file:") }
|
|
123
|
+
listb.bind(:PRESS) {
|
|
124
|
+
w = @form.by_name["tv"];
|
|
125
|
+
lines = `ri -f bs #{listb.text}`.split("\n")
|
|
126
|
+
#w.set_content(lines, :ansi)
|
|
127
|
+
w.add_content(lines, :content_type => :ansi, :title => listb.text)
|
|
128
|
+
w.buffer_last
|
|
129
|
+
#w.title = listb.text
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
tv = RubyCurses::TextView.new @form, :row => r, :col => w+1, :height => h, :width => FFI::NCurses.COLS-w-1,
|
|
133
|
+
:name => "tv", :title => "Press Enter on method"
|
|
134
|
+
tv.set_content ["Press Enter on list to view ri information in this area.",
|
|
135
|
+
"Press ENTER on method name to see details"]
|
|
136
|
+
require 'rbhex/core/include/multibuffer'
|
|
137
|
+
tv.extend(RubyCurses::MultiBuffers)
|
|
138
|
+
|
|
139
|
+
# pressing ENTER on a method name will popup details for that method
|
|
140
|
+
tv.bind(:PRESS) { |ev|
|
|
141
|
+
w = ev.word_under_cursor.strip
|
|
142
|
+
# check that user did not hit enter on empty area
|
|
143
|
+
if w != ""
|
|
144
|
+
_text = `ri -f bs #{tv.title}.#{w} 2>&1`
|
|
145
|
+
_text = _text.split("\n")
|
|
146
|
+
if _text && _text.size != 0
|
|
147
|
+
view(_text, :content_type => :ansi)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@form.repaint
|
|
154
|
+
@window.wrefresh
|
|
155
|
+
Ncurses::Panel.update_panels
|
|
156
|
+
while((ch = @window.getchar()) != KEY_F10 )
|
|
157
|
+
@form.handle_key(ch)
|
|
158
|
+
@window.wrefresh
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
rescue => ex
|
|
162
|
+
$log.debug( ex) if ex
|
|
163
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
|
164
|
+
ensure
|
|
165
|
+
@window.destroy if !@window.nil?
|
|
166
|
+
VER::stop_ncurses
|
|
167
|
+
p ex if ex
|
|
168
|
+
p(ex.backtrace.join("\n")) if ex
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# To test out the new messagebox
|
|
2
|
+
# The old messagebox provided a lot of convenience methods that were complicated
|
|
3
|
+
# and confusing. This one is simpler.
|
|
4
|
+
# The examples here are based on the old test1.rb that will not work now
|
|
5
|
+
# since the interface has been changed and simplified
|
|
6
|
+
#
|
|
7
|
+
require 'logger'
|
|
8
|
+
require 'rbhex'
|
|
9
|
+
require 'rbhex/core/widgets/rmessagebox'
|
|
10
|
+
#require 'rbhex/deprecated/widgets/rmessagebox'
|
|
11
|
+
|
|
12
|
+
if $0 == __FILE__
|
|
13
|
+
# Initialize curses
|
|
14
|
+
begin
|
|
15
|
+
# XXX update with new color and kb
|
|
16
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
|
17
|
+
$log = Logger.new((File.join(ENV['LOGDIR'] || "./" ,"rbc13.log")))
|
|
18
|
+
$log.level = Logger::DEBUG
|
|
19
|
+
|
|
20
|
+
# @window = VER::Window.root_window
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
catch(:close) do
|
|
24
|
+
choice = ARGV[0] && ARGV[0].to_i || 3
|
|
25
|
+
$log.debug "START MESSAGE BOX TEST #{ARGV[0]}. choice==#{choice} ---------"
|
|
26
|
+
# need to pass a form, not window.
|
|
27
|
+
case choice
|
|
28
|
+
when 1
|
|
29
|
+
require 'rbhex/core/widgets/rlist'
|
|
30
|
+
nn = "mylist"
|
|
31
|
+
l = List.new nil, :row => 2, :col => 5, :list => %w[john tim lee wong rahul edward why chad andy],
|
|
32
|
+
:selection_mode => :multiple, :height => 10, :width => 20 , :selected_color => :green, :selected_bgcolor => :white, :selected_indices => [2,6], :name => nn
|
|
33
|
+
#default_values %w[ lee why ]
|
|
34
|
+
@mb = MessageBox.new :width => 30, :height => 18 do
|
|
35
|
+
title "Select a name"
|
|
36
|
+
button_type :ok_cancel
|
|
37
|
+
item Label.new :row => 1, :col => 1, :text => "Enter your name:"
|
|
38
|
+
item l
|
|
39
|
+
|
|
40
|
+
#default_button 0 # TODO
|
|
41
|
+
end
|
|
42
|
+
@mb.run
|
|
43
|
+
$log.debug "XXX: #{l.selected_indices} "
|
|
44
|
+
n = @mb.widget(nn)
|
|
45
|
+
$log.debug "XXXX: #{n.selected_indices}, #{n.name} "
|
|
46
|
+
when 2
|
|
47
|
+
@mb = RubyCurses::MessageBox.new do
|
|
48
|
+
title "Color selector"
|
|
49
|
+
message "Select a color"
|
|
50
|
+
#item Label.new :text => "Select a color", :row => 1 , :col => 2
|
|
51
|
+
|
|
52
|
+
r = 3
|
|
53
|
+
c = 2
|
|
54
|
+
%w[&red &green &blue &yellow].each_with_index { |b, i|
|
|
55
|
+
bu = Button.new :name => b, :text => b, :row => r, :col => c
|
|
56
|
+
bu.command { throw(:close, i) }
|
|
57
|
+
item bu
|
|
58
|
+
#bu.default_button(true) if i == 0
|
|
59
|
+
#r += 1
|
|
60
|
+
c += b.length + 5
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
index = @mb.run
|
|
64
|
+
$log.debug "XXX: messagebox 2 ret #{index} "
|
|
65
|
+
when 3
|
|
66
|
+
@mb = RubyCurses::MessageBox.new do
|
|
67
|
+
title "Enter your name"
|
|
68
|
+
#message "Enter your first name. You are not permitted to enter x z or q and must enter a capital first"
|
|
69
|
+
message "Enter your first name. Initcaps "
|
|
70
|
+
add Field.new :chars_allowed => /[^0-9xyz]/, :valid_regex => /^[A-Z][a-z]*/, :default => "Matz", :bgcolor => :cyan
|
|
71
|
+
button_type :ok_cancel
|
|
72
|
+
end
|
|
73
|
+
@mb.run
|
|
74
|
+
$log.debug "XXX: got #{@mb.widget(1).text} "
|
|
75
|
+
when 4
|
|
76
|
+
mb = MessageBox.new :title => "HTTP Configuration" , :width => 50 do
|
|
77
|
+
add Field.new :label => 'User', :name => "user", :display_length => 30, :bgcolor => :cyan
|
|
78
|
+
add CheckBox.new :text => "No &frames", :onvalue => "Selected", :offvalue => "UNselected"
|
|
79
|
+
add CheckBox.new :text => "Use &HTTP/1.0", :value => true
|
|
80
|
+
add CheckBox.new :text => "Use &passive FTP"
|
|
81
|
+
add Label.new :text => " Language ", :attr => REVERSE
|
|
82
|
+
$radio = RubyCurses::Variable.new
|
|
83
|
+
add RadioButton.new :text => "py&thon", :value => "python", :color => :blue, :variable => $radio
|
|
84
|
+
add RadioButton.new :text => "rub&y", :color => :red, :variable => $radio
|
|
85
|
+
button_type :ok
|
|
86
|
+
end
|
|
87
|
+
field = mb.widget("user")
|
|
88
|
+
field.bind(:ENTER) do |f|
|
|
89
|
+
listconfig = {'bgcolor' => 'blue', 'color' => 'white'}
|
|
90
|
+
users= %w[john tim lee wong rahul edward _why chad andy]
|
|
91
|
+
index = popuplist(users, :relative_to => field, :col => field.col + 6, :width => field.display_length)
|
|
92
|
+
field.set_buffer users[index] if index
|
|
93
|
+
end
|
|
94
|
+
mb.run
|
|
95
|
+
|
|
96
|
+
when 5
|
|
97
|
+
require 'rbhex/core/widgets/rlist'
|
|
98
|
+
label = Label.new 'text' => 'File', 'mnemonic'=>'F', :row => 3, :col => 5
|
|
99
|
+
field = Field.new :name => "file", :row => 3 , :col => 10, :width => 40, :set_label => label
|
|
100
|
+
#flist = Dir.glob(File.join( File.expand_path("~/"), "*"))
|
|
101
|
+
flist = Dir.glob("*")
|
|
102
|
+
listb = List.new :name => "mylist", :row => 4, :col => 3, :width => 50, :height => 10,
|
|
103
|
+
:list => flist, :title => "File List", :selected_bgcolor => :white, :selected_color => :blue,
|
|
104
|
+
:selection_mode => :single, :border_attrib => REVERSE
|
|
105
|
+
#listb.bind(:ENTER_ROW) { field.set_buffer listb.selected_item }
|
|
106
|
+
# if you find that cursor goes into listbox while typing, then
|
|
107
|
+
# i've put set_form_row in listbox list_data_changed
|
|
108
|
+
field.bind(:CHANGE) do |f|
|
|
109
|
+
flist = Dir.glob("*"+f.getvalue+"*")
|
|
110
|
+
#l.insert( 0, *flist) if flist
|
|
111
|
+
listb.list flist
|
|
112
|
+
end
|
|
113
|
+
mb = RubyCurses::MessageBox.new :height => 20, :width => 60 do
|
|
114
|
+
title "Sample File Selector"
|
|
115
|
+
add label
|
|
116
|
+
add field
|
|
117
|
+
add listb
|
|
118
|
+
#height 20
|
|
119
|
+
#width 60
|
|
120
|
+
#top 5
|
|
121
|
+
#left 20
|
|
122
|
+
#default_button 0
|
|
123
|
+
button_type :ok_cancel
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
mb.run
|
|
127
|
+
$log.debug "MBOX :selected #{listb.selected_item}"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
rescue => ex
|
|
132
|
+
ensure
|
|
133
|
+
@window.destroy unless @window.nil?
|
|
134
|
+
VER::stop_ncurses
|
|
135
|
+
p ex if ex
|
|
136
|
+
p(ex.backtrace.join("\n")) if ex
|
|
137
|
+
$log.debug( ex) if ex
|
|
138
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
|
139
|
+
end
|
|
140
|
+
end
|