rbcurse 0.1.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 (55) hide show
  1. data/CHANGELOG +1570 -0
  2. data/History.txt +6 -0
  3. data/Manifest.txt +54 -0
  4. data/README.txt +304 -0
  5. data/Rakefile +28 -0
  6. data/examples/qdfilechooser.rb +68 -0
  7. data/examples/rfe.rb +853 -0
  8. data/examples/rfe_renderer.rb +69 -0
  9. data/examples/test1.rb +242 -0
  10. data/examples/test2.rb +498 -0
  11. data/examples/testcombo.rb +95 -0
  12. data/examples/testkeypress.rb +61 -0
  13. data/examples/testmenu.rb +105 -0
  14. data/examples/testtable.rb +266 -0
  15. data/examples/testtabp.rb +106 -0
  16. data/examples/testtodo.rb +532 -0
  17. data/examples/viewtodo.rb +512 -0
  18. data/lib/rbcurse/action.rb +31 -0
  19. data/lib/rbcurse/applicationheader.rb +57 -0
  20. data/lib/rbcurse/celleditor.rb +120 -0
  21. data/lib/rbcurse/checkboxcellrenderer.rb +69 -0
  22. data/lib/rbcurse/colormap.rb +133 -0
  23. data/lib/rbcurse/comboboxcellrenderer.rb +45 -0
  24. data/lib/rbcurse/defaultlistselectionmodel.rb +49 -0
  25. data/lib/rbcurse/keylabelprinter.rb +143 -0
  26. data/lib/rbcurse/listcellrenderer.rb +99 -0
  27. data/lib/rbcurse/listkeys.rb +33 -0
  28. data/lib/rbcurse/listscrollable.rb +216 -0
  29. data/lib/rbcurse/listselectable.rb +67 -0
  30. data/lib/rbcurse/mapper.rb +108 -0
  31. data/lib/rbcurse/orderedhash.rb +77 -0
  32. data/lib/rbcurse/rcombo.rb +243 -0
  33. data/lib/rbcurse/rdialogs.rb +183 -0
  34. data/lib/rbcurse/rform.rb +845 -0
  35. data/lib/rbcurse/rinputdataevent.rb +36 -0
  36. data/lib/rbcurse/rlistbox.rb +804 -0
  37. data/lib/rbcurse/rmenu.rb +666 -0
  38. data/lib/rbcurse/rmessagebox.rb +325 -0
  39. data/lib/rbcurse/rpopupmenu.rb +754 -0
  40. data/lib/rbcurse/rtabbedpane.rb +259 -0
  41. data/lib/rbcurse/rtable.rb +1296 -0
  42. data/lib/rbcurse/rtextarea.rb +673 -0
  43. data/lib/rbcurse/rtextview.rb +335 -0
  44. data/lib/rbcurse/rwidget.rb +1731 -0
  45. data/lib/rbcurse/scrollable.rb +301 -0
  46. data/lib/rbcurse/selectable.rb +94 -0
  47. data/lib/rbcurse/table/tablecellrenderer.rb +85 -0
  48. data/lib/rbcurse/table/tabledatecellrenderer.rb +102 -0
  49. data/lib/rbcurse.rb +7 -0
  50. data/lib/ver/keyboard.rb +150 -0
  51. data/lib/ver/keyboard2.rb +170 -0
  52. data/lib/ver/ncurses.rb +102 -0
  53. data/lib/ver/window.rb +369 -0
  54. data/test/test_rbcurse.rb +0 -0
  55. metadata +118 -0
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-10-26
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,54 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ CHANGELOG
5
+ Rakefile
6
+ lib/rbcurse.rb
7
+ test/test_rbcurse.rb
8
+ lib/rbcurse/action.rb
9
+ lib/rbcurse/applicationheader.rb
10
+ lib/rbcurse/celleditor.rb
11
+ lib/rbcurse/checkboxcellrenderer.rb
12
+ lib/rbcurse/colormap.rb
13
+ lib/rbcurse/comboboxcellrenderer.rb
14
+ lib/rbcurse/defaultlistselectionmodel.rb
15
+ lib/rbcurse/keylabelprinter.rb
16
+ lib/rbcurse/listcellrenderer.rb
17
+ lib/rbcurse/listkeys.rb
18
+ lib/rbcurse/listscrollable.rb
19
+ lib/rbcurse/listselectable.rb
20
+ lib/rbcurse/mapper.rb
21
+ lib/rbcurse/orderedhash.rb
22
+ lib/rbcurse/rcombo.rb
23
+ lib/rbcurse/rdialogs.rb
24
+ lib/rbcurse/rform.rb
25
+ lib/rbcurse/rinputdataevent.rb
26
+ lib/rbcurse/rlistbox.rb
27
+ lib/rbcurse/rmenu.rb
28
+ lib/rbcurse/rmessagebox.rb
29
+ lib/rbcurse/rpopupmenu.rb
30
+ lib/rbcurse/rtabbedpane.rb
31
+ lib/rbcurse/rtable.rb
32
+ lib/rbcurse/rtextarea.rb
33
+ lib/rbcurse/rtextview.rb
34
+ lib/rbcurse/rwidget.rb
35
+ lib/rbcurse/scrollable.rb
36
+ lib/rbcurse/selectable.rb
37
+ lib/rbcurse/table/tablecellrenderer.rb
38
+ lib/rbcurse/table/tabledatecellrenderer.rb
39
+ lib/ver/keyboard.rb
40
+ lib/ver/keyboard2.rb
41
+ lib/ver/ncurses.rb
42
+ lib/ver/window.rb
43
+ examples/qdfilechooser.rb
44
+ examples/rfe.rb
45
+ examples/rfe_renderer.rb
46
+ examples/test1.rb
47
+ examples/test2.rb
48
+ examples/testcombo.rb
49
+ examples/testkeypress.rb
50
+ examples/testmenu.rb
51
+ examples/testtable.rb
52
+ examples/testtabp.rb
53
+ examples/testtodo.rb
54
+ examples/viewtodo.rb
data/README.txt ADDED
@@ -0,0 +1,304 @@
1
+ = rbcurse
2
+
3
+ * http://totalrecall.wordpress.com << CORRECTED !!!
4
+
5
+ * See latest changes on http://github.com/rkumar/rbcurse/tree/master/CHANGELOG
6
+
7
+ * For a working example, execute test2.rb (exit with F1, Or Cancel
8
+ button/Alt-C).
9
+
10
+ * Screenshots on http://github.com/rkumar/rbcurse/wikis/screenshots
11
+ and http://www.benegal.org/files/screen/
12
+
13
+ Full screen sample: http://www.benegal.org/files/screen/nc_ss_full.png
14
+
15
+ == DESCRIPTION:
16
+
17
+ A small widget library written in ruby for creating ncurses
18
+ applications.
19
+ See lib/rbcurse/rwidgets.rb and lib/rbcurse/rform.rb.
20
+ Test programs are in base dir: test1.rb, test2.rb, testtabp.rb
21
+
22
+ == FEATURES
23
+
24
+ * entry fields in ruby
25
+ * scrollable list box (new, editable with Field, checkbox and combos)
26
+ * multi-line editable area
27
+ * togglebutton, radio and check buttons (with mnemonics)
28
+ * message box
29
+ * menubar - with submenu and CheckBoxMenuItem
30
+ * popup list
31
+ * tabbedpane (multiple forms using tabbed metaphor)
32
+ * combobox
33
+ * labels with mnemonics (hotkeys)
34
+ * multi-column table - with cell selection and editing
35
+
36
+ Above may be created using DSL like syntax, or hashes.
37
+
38
+ == Sample programs:
39
+
40
+ * test2.rb most widgets (including menus)
41
+ http://github.com/rkumar/rbcurse/tree/master/test2.rb
42
+ * test1.rb various kinds of messageboxes (input, list, custom)
43
+ http://github.com/rkumar/rbcurse/tree/master/test1.rb
44
+ * testtabp.rb tabbed pane
45
+ http://github.com/rkumar/rbcurse/tree/master/testtabp.rb
46
+ * testcombo.rb combos with various insert policies and vertical
47
+ alignments
48
+
49
+ == PROBLEMS, ISSUES
50
+ TextArea not bug free. Some situations wrapping errors could exist.
51
+
52
+ == Terminal related issues.
53
+
54
+ * Some terminals may not show underlines (e.g screen).
55
+
56
+ * Some terminals (xterm-color) do not process Function keys, avoid declaring F1 etc if
57
+ unsure of client terminals. I have put in fixes for xterm-color F1 and
58
+ backtab.
59
+
60
+ * To use ALT/META keys on a Mac OS X, in Terminal preferences, under
61
+ Keyboard, select
62
+ "use Option as Meta key". All hotkeys are automatically, ALT combinations.
63
+
64
+ * Some screens do not display window background color under spaces.
65
+ This is okay under "screen" and "xterm-color" but not under "xterm". You will notice
66
+ this in the message box samples.
67
+
68
+ I am developing and testing under "screen" under OS X Leopard.
69
+
70
+ == SYNOPSIS:
71
+
72
+ See lib/rbcurse/rwidgets.rb.
73
+ For test programs, see test1, test2, testcombo etc in root folder.
74
+
75
+ This depends only on "window" provided by ncurses. Does not use forms
76
+ and fields. Minor changes and improvements may have happened to sample
77
+ code below. See test programs for latest, working code.
78
+
79
+ === create a window and a form based on window
80
+
81
+ @layout = { :height => 0, :width => 0, :top => 0, :left => 0 }
82
+ @win = VER::Window.new(@layout)
83
+
84
+ @form = Form.new @win
85
+
86
+
87
+ === create a bunch of fields with dependent labels
88
+
89
+ r = 1; c = 22;
90
+ %w[ name age company].each do |w|
91
+ field = Field.new @form do
92
+ name w
93
+ row r
94
+ col c
95
+ display_length 30
96
+ set_buffer "abcd #{w}"
97
+ set_label Label.new @form, {'text' => w}
98
+ end
99
+ r += 1
100
+ end
101
+
102
+ === create a variable (like TkVariable) and tie a label to it.
103
+
104
+ $results = Variable.new
105
+ $results.value = "A variable"
106
+ var = RubyCurses::Label.new @form, {'text_variable' => $results, "row" => r, "col" => 22}
107
+ r += 1
108
+
109
+ === create a list and a list box based on the list.
110
+
111
+ mylist = []
112
+ 0.upto(100) { |v| mylist << "#{v} scrollable data" }
113
+
114
+ field = Listbox.new @form do
115
+ name "mylist"
116
+ row r
117
+ col 1
118
+ width 40
119
+ height 10
120
+ list mylist
121
+ end
122
+ field.insert 5, "hello ruby", "so long python", "farewell java", "RIP .Net"
123
+
124
+ === create a textarea for entry (this can be buggy at present)
125
+
126
+ texta = TextArea.new @form do
127
+ name "mytext"
128
+ row 1
129
+ col 52
130
+ width 40
131
+ height 20
132
+ end
133
+ texta << "hello there" << "we are testing deletes in this application"
134
+ texta << "HELLO there" << "WE ARE testing deletes in this application"
135
+
136
+ === create a check box, updates a Variable
137
+
138
+ checkbutton = CheckBox.new @form do
139
+ text_variable $results
140
+ #value = true
141
+ onvalue "selected cb"
142
+ offvalue "UNselected cb"
143
+ text "Please click me"
144
+ row 17
145
+ col 22
146
+ end
147
+
148
+ === change field properties at any time by referring to them by name
149
+
150
+ @form.by_name["age"].display_length = 3
151
+ @form.by_name["age"].maxlen = 3
152
+ @form.by_name["age"].set_buffer "24"
153
+ @form.by_name["name"].set_buffer "Not focusable"
154
+ @form.by_name["age"].chars_allowed = /\d/
155
+ @form.by_name["company"].type(:ALPHA)
156
+ @form.by_name["name"].set_focusable(false)
157
+
158
+ @form.by_name["password"].color 'red'
159
+ @form.by_name["password"].bgcolor 'blue'
160
+
161
+ # restrict entry to some values
162
+ password.values(%w[ scotty tiger secret qwerty])
163
+
164
+ # validation using ruby's regular expressions
165
+
166
+ field.valid_regex(/^[A-Z]\d+/)
167
+
168
+ === bind events to forms, and fields
169
+
170
+ @form.bind(:ENTER) { |f| f.label.bgcolor = $promptcolor if f.instance_of? RubyCurses::Field}
171
+ @form.bind(:LEAVE) { |f| f.label.bgcolor = $datacolor if f.instance_of? RubyCurses::Field}
172
+
173
+ === create buttons
174
+
175
+ ok_button = Button.new @form do
176
+ text "OK"
177
+ name "OK"
178
+ row 18
179
+ col 22
180
+ end
181
+ ok_button.command { |form| $results.value = "OK PRESS:";form.printstr(@window, 23,45, "OK CALLED") }
182
+ #text "Cancel"
183
+ cancel_button = Button.new @form do
184
+ text_variable $results
185
+ row 18
186
+ col 28
187
+ end
188
+ cancel_button.command { |form| form.printstr(@window, 23,45, "Cancel CALLED"); throw(:close); }
189
+
190
+ === create radio buttons
191
+
192
+ colorlabel = Label.new @form, {'text' => "Select a color:", "row" => 20,
193
+ "col" => 22, "color"=> "cyan"}
194
+ $radio = Variable.new
195
+ radio1 = RadioButton.new @form do
196
+ text_variable $radio
197
+ text "red"
198
+ value "red"
199
+ color "red"
200
+ row 21
201
+ col 22
202
+ end
203
+ radio2 = RadioButton.new @form do
204
+ text_variable $radio
205
+ text "green"
206
+ value "green"
207
+ color "green"
208
+ row 22
209
+ col 22
210
+ end
211
+
212
+ === create a messagebox
213
+
214
+ @mb = RubyCurses::MessageBox.new do
215
+ title "Enter your name"
216
+ message "Enter your name"
217
+ type :input
218
+ default_value "rahul"
219
+ default_button 0
220
+ end
221
+ #title "Color selector"
222
+ #type :custom
223
+ #buttons %w[red green blue yellow]
224
+ #underlines [0,0,0,0]
225
+
226
+ $log.debug "MBOX : #{@mb.selected_index} "
227
+ $log.debug "MBOX : #{@mb.input_value} "
228
+
229
+ === create a read-only scrollable view of data
230
+
231
+ @textview = TextView.new @form do
232
+ name "myView"
233
+ row 16
234
+ col 52
235
+ width 40
236
+ height 7
237
+ end
238
+ content = File.open("../../README.txt","r").readlines
239
+ @textview.set_content content
240
+
241
+ ## set it to point to row 21
242
+ @textview.top_row 21
243
+
244
+
245
+ # lets scroll the text view as we scroll the listbox
246
+
247
+ listb.bind(:ENTER_ROW, @textview) { |arow, tview| tview.top_row arow }
248
+
249
+ # lets scroll the text view to the line you enter in the numeric
250
+ # field
251
+ @form.by_name["line"].bind(:LEAVE, @textview) { |fld, tv| tv.top_row(fld.getvalue.to_i) }
252
+
253
+ # lets scroll the text view to the first match of the regex you
254
+ # enter
255
+ @form.by_name["regex"].bind(:LEAVE, @textview) { |fld, tv| tv.top_row(tv.find_first_match(fld.getvalue)) }
256
+
257
+ # change the value of colorlabel to the selected radiobutton
258
+ # (red or green)
259
+
260
+ $radio.update_command(colorlabel) {|tv, label| label.color tv.value}
261
+
262
+ # change the attribute of colorlabel to bold or normal
263
+
264
+ $results.update_command(colorlabel,checkbutton) {|tv, label, cb|
265
+ attrs = cb.value ? 'bold' : nil; label.attrs(attrs)}
266
+
267
+ # during menu creation, create a checkboxmenuitem
268
+
269
+ item = RubyCurses::CheckBoxMenuItem.new "CheckMe"
270
+
271
+ # when selected, make colorlabel attribute reverse.
272
+
273
+ item.command(colorlabel){|it, label| att = it.getvalue ? 'reverse' :
274
+ nil; label.attrs(att); label.repaint}
275
+
276
+ == REQUIREMENTS:
277
+
278
+ * ruby 1.8.7 (not compatible with 1.9)
279
+
280
+ * ncurses-ruby
281
+
282
+ (following is provided with source)
283
+
284
+ * uses the window class created by "manveru" (michael) - this can be
285
+ removed if not needed. (lib/ver/window)
286
+ It is provided with this package, and has some alterations from the
287
+ original. I have added a method getchar() which traps and returns
288
+ ALT/META, META+CTRL, META+SHIFT+CONTROL, ALT+Fn etc.
289
+
290
+ So basically do not remove it unless you have very different
291
+ requirements.
292
+
293
+ == INSTALL:
294
+
295
+ * currently, just unzip/untar in a folder. Please change the path in
296
+ the top line of the test programs.
297
+
298
+ (Please advice me how i can improve installation procedure)
299
+
300
+ == LICENSE:
301
+
302
+ Copyright (c) 2008 rkumar
303
+
304
+ Same as ruby license.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+
3
+
4
+ #
5
+ require 'rubygems'
6
+ require 'hoe'
7
+ $:.unshift(File.dirname(__FILE__) + "/lib")
8
+ require 'rbcurse'
9
+ #require './lib/rbcurse.rb'
10
+
11
+ Hoe.new('rbcurse', Rbcurse::VERSION) do |p|
12
+ p.name = "rbcurse"
13
+ p.author = "Rahul Kumar"
14
+ p.description = "Ruby curses widgets for easy application development"
15
+ p.email = 'sentinel.2001@gmx.com'
16
+ p.summary = "Ruby curses widgets."
17
+ p.url = "http://rbcurse.rubyforge.org/"
18
+ p.clean_globs = ['test/actual'] # Remove this directory on "rake clean"
19
+ p.remote_rdoc_dir = '' # Release to root
20
+ p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
21
+ # * extra_deps - An array of rubygem dependencies.
22
+ end
23
+
24
+
25
+ desc "Release and publish documentation"
26
+ task :repubdoc => [:release, :publish_docs]
27
+
28
+ # vim: syntax=Ruby
@@ -0,0 +1,68 @@
1
+ # this is a test program, tests out messageboxes. type F1 to exit
2
+ # a quick dirty file chooser in 2 lines of code.
3
+ #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
4
+ require 'rubygems'
5
+ require 'ncurses'
6
+ require 'logger'
7
+ require 'ver/ncurses'
8
+ require 'ver/window'
9
+ require 'rbcurse/rwidget'
10
+
11
+ ##
12
+ # a quick dirty file chooser - only temporary till we make something better.
13
+ class QDFileChooser
14
+ attr_accessor :show_folders # bool
15
+ attr_accessor :traverse_folders # bool
16
+ attr_accessor :default_pattern # e.g. "*.*"
17
+ attr_accessor :dialog_title # File Chooser
18
+ def initialize
19
+
20
+ end
21
+ def show_open_dialog
22
+ @form = RubyCurses::Form.new nil
23
+ label = RubyCurses::Label.new @form, {'text' => 'File', 'row'=>3, 'col'=>4, 'color'=>'black', 'bgcolor'=>'white', 'mnemonic'=>'F'}
24
+ field = RubyCurses::Field.new @form do
25
+ name "file"
26
+ row 3
27
+ col 10
28
+ display_length 40
29
+ set_label label
30
+ end
31
+ default_pattern ||= "*.*"
32
+ flist = Dir.glob(default_pattern)
33
+ @listb = RubyCurses::Listbox.new @form do
34
+ name "mylist"
35
+ row 5
36
+ col 10
37
+ width 40
38
+ height 10
39
+ list flist
40
+ title "File list"
41
+ title_attrib 'bold'
42
+ end
43
+ #@listb.list.bind(:ENTER_ROW) { field.set_buffer @listb.selected_item }
44
+ listb = @listb
45
+ field.bind(:CHANGE) do |f|
46
+ flist = Dir.glob(f.getvalue+"*")
47
+ l = listb.list
48
+ l.remove_all
49
+ l.insert 0, *flist
50
+ end
51
+ atitle = @dialog_title || "Quick Dirty(TM) File Chooser"
52
+ @mb = RubyCurses::MessageBox.new @form do
53
+ title atitle
54
+ type :override
55
+ height 20
56
+ width 60
57
+ top 5
58
+ left 20
59
+ default_button 0
60
+ button_type :ok_cancel
61
+ end
62
+ return @mb.selected_index == 0 ? :OK : :CANCEL
63
+ $log.debug "MBOX :selected #{@listb.selected_item}"
64
+ end
65
+ def get_selected_file
66
+ return @mb.selected_index == 0 ? @listb.selected_item : nil
67
+ end
68
+ end