rbcurse 0.1.3 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG +126 -0
  2. data/Manifest.txt +53 -20
  3. data/README.markdown +423 -0
  4. data/Rakefile +3 -1
  5. data/examples/keytest.rb +177 -0
  6. data/examples/mpad2.rb +156 -0
  7. data/examples/newtesttabp.rb +121 -0
  8. data/examples/rfe.rb +48 -10
  9. data/examples/rfe_renderer.rb +4 -4
  10. data/examples/rvimsplit.rb +376 -0
  11. data/examples/sqlc.rb +97 -106
  12. data/examples/sqlm.rb +446 -0
  13. data/examples/test1.rb +4 -4
  14. data/examples/test2.rb +12 -12
  15. data/examples/testchars.rb +140 -0
  16. data/examples/testkeypress.rb +9 -4
  17. data/examples/testmulticomp.rb +72 -0
  18. data/examples/testscroller.rb +136 -0
  19. data/examples/testscrolllb.rb +86 -0
  20. data/examples/testscrollp.rb +87 -0
  21. data/examples/testscrollta.rb +80 -0
  22. data/examples/testscrolltable.rb +166 -0
  23. data/examples/testsplit.rb +87 -0
  24. data/examples/testsplit2.rb +123 -0
  25. data/examples/testsplit3.rb +215 -0
  26. data/examples/testsplit3_1.rb +244 -0
  27. data/examples/testsplit3a.rb +215 -0
  28. data/examples/testsplit3b.rb +237 -0
  29. data/examples/testsplitta.rb +148 -0
  30. data/examples/testsplittv.rb +142 -0
  31. data/examples/testsplittvv.rb +144 -0
  32. data/examples/testtable.rb +1 -1
  33. data/examples/testtabp.rb +3 -2
  34. data/examples/testtestw.rb +69 -0
  35. data/examples/testtodo.rb +5 -3
  36. data/examples/testtpane.rb +203 -0
  37. data/examples/testtpane2.rb +145 -0
  38. data/examples/testtpanetable.rb +199 -0
  39. data/examples/viewtodo.rb +5 -3
  40. data/lib/rbcurse.rb +1 -1
  41. data/lib/rbcurse/celleditor.rb +2 -2
  42. data/lib/rbcurse/colormap.rb +5 -5
  43. data/lib/rbcurse/defaultlistselectionmodel.rb +3 -3
  44. data/lib/rbcurse/io.rb +663 -0
  45. data/lib/rbcurse/listeditable.rb +306 -0
  46. data/lib/rbcurse/listkeys.rb +15 -15
  47. data/lib/rbcurse/listscrollable.rb +168 -27
  48. data/lib/rbcurse/mapper.rb +35 -13
  49. data/lib/rbcurse/rchangeevent.rb +28 -0
  50. data/lib/rbcurse/rform.rb +845 -0
  51. data/lib/rbcurse/rlistbox.rb +144 -34
  52. data/lib/rbcurse/rmessagebox.rb +10 -5
  53. data/lib/rbcurse/rmulticontainer.rb +325 -0
  54. data/lib/rbcurse/rmultitextview.rb +306 -0
  55. data/lib/rbcurse/rscrollform.rb +369 -0
  56. data/lib/rbcurse/rscrollpane.rb +511 -0
  57. data/lib/rbcurse/rsplitpane.rb +820 -0
  58. data/lib/rbcurse/rtabbedpane.rb +737 -109
  59. data/lib/rbcurse/rtabbedwindow.rb +326 -0
  60. data/lib/rbcurse/rtable.rb +220 -64
  61. data/lib/rbcurse/rtextarea.rb +340 -181
  62. data/lib/rbcurse/rtextview.rb +237 -101
  63. data/lib/rbcurse/rviewport.rb +203 -0
  64. data/lib/rbcurse/rwidget.rb +919 -95
  65. data/lib/rbcurse/scrollable.rb +7 -7
  66. data/lib/rbcurse/selectable.rb +4 -4
  67. data/lib/rbcurse/table/tablecellrenderer.rb +3 -0
  68. data/lib/rbcurse/undomanager.rb +181 -0
  69. data/lib/rbcurse/vieditable.rb +100 -0
  70. data/lib/ver/window.rb +471 -21
  71. metadata +66 -22
  72. data/README.txt +0 -312
  73. data/examples/testd.db +0 -0
  74. data/examples/todocsv.csv +0 -28
data/CHANGELOG CHANGED
@@ -1,3 +1,129 @@
1
+ **2010-03-01 00:00**
2
+ ## Overhaul of tabbedpane
3
+
4
+ Simplified, and it more or less completely makes sense now.
5
+ A component may be added directly without creating a form
6
+ which allows the TP to set row, col, and height width.
7
+
8
+ At this moment, it no longer creates a form automatically, you have to call
9
+ tp.form(tab) to get a form associated with the tab. Check code for latest on
10
+ this. Or check samples: testtpane.rb and testtpane2.rb.
11
+
12
+ **2010-02-18 22:58**
13
+ ## RFED16 new simplified buffering
14
+
15
+ Major changes. Most widgets redone (buffer part).
16
+ Containers majorly done. Table and TabbedPane still pending.
17
+
18
+ **2009-11-03 23:30**
19
+ ## tabbedpanes ##
20
+
21
+ Now on first click of tabbed button, form is painted.
22
+ A form.repaint for the lower form was required.
23
+
24
+ frmincr200911032330.tgz
25
+ * * *
26
+ **2009-11-03 00:19**
27
+ ## some progress on tabbedpanes ##
28
+
29
+ Ugly hacking and I really haven't a clue what's happening
30
+ since there's internal forms working.
31
+ Anyhow, its now showing up, can see form cursor moving.
32
+ Does not show up immediately, have to press key several times for form to display.
33
+
34
+ frmincr200911030018.tgz
35
+ * * *
36
+ **2009-11-02 13:15**
37
+ ## before rtabbedpane ##
38
+
39
+ After all the changes, the new tabbedpane is not printing the form fields.
40
+ Working on that now.
41
+
42
+ frmincr200911021314.tgz
43
+ * * *
44
+ **2009-11-02 12:13**
45
+ ## splitpane and scrollpane working ##
46
+
47
+ Both are working. Changes to copywin had caused issues. And printborder.
48
+ Decreasing comp width does not reduce pad size, but pad keeps printing larger size.
49
+ So in Splitpane it was overwriting. Now in Pad we maintain sheight as comp's height.
50
+ Major change in pad, but hope it works and doesn't bomb out somewhere.
51
+
52
+ frmincr200911021212.tgz
53
+ * * *
54
+ **2009-11-02 01:03**
55
+ ## SplitPane retouching ##
56
+
57
+ began majorly misprinting after changes to printborder and copywin().
58
+ ALmost corrected. Still some issues in copywin which are making separator and border
59
+ to get eaten up.
60
+
61
+ frmincr200911020102.tgz
62
+ * * *
63
+ **2009-11-01 22:28**
64
+ ## scrollbars in scrollpane ##
65
+
66
+ Added scrollbars in scrollpane. Sized and positioned nicely.
67
+
68
+ frmincr200911012228.tgz
69
+ * * *
70
+ **2009-11-01 01:05**
71
+ ## scrollpane WIP ##
72
+
73
+ scrollpane with viewport and child object
74
+ i can see the child within. have to test scrolling now.
75
+ Issue is largely with copywin which gives errors.
76
+
77
+ frmincr200911010104.tgz
78
+ * * *
79
+ **2009-10-31 22:07**
80
+ ## scrollpane WIP ##
81
+
82
+ ,,,
83
+
84
+ frmincr200910312206.tgz
85
+ * * *
86
+ **2009-10-30 23:32**
87
+ ## more testing with SplitPane and 2 splitpanes in it ##
88
+
89
+ vertical and horizontal
90
+ check against min sizes
91
+
92
+ frmincr200910302331.tgz
93
+ * * *
94
+ **2009-10-30 17:47**
95
+ ## buffering ##
96
+
97
+ major change is buffering added (using pad)
98
+ height and width added to Widget
99
+ Splitpane added (midway)
100
+
101
+ frmincr200910301746.tgz
102
+ * * *
103
+ **2009-10-07 10:14**
104
+ ## Prior to change in next_column ##
105
+
106
+ Currently, after last visible column tab goes to next row.
107
+ We want to scroll if more columns.
108
+ At present, table will not print if a col goes out of bounds. but this does not impact
109
+ first or last column to print variables.
110
+
111
+ frmincr200910071012.tgz
112
+ * * *
113
+ ** 2009-10-05 11:00 **
114
+ ## Horizontal scrolling in tables - some cleaning ##
115
+
116
+ When increasing the size of a column, other cols could write
117
+ outside the table. Fixed.
118
+
119
+ * * *
120
+ ** 2009-10-05 00:00 **
121
+ ## Making changes for 1.9 and testing ##
122
+
123
+ Mostly key related changes.
124
+ However, there could be some string index change lurking around
125
+
126
+ * * *
1
127
  ** 2009-02-22 20:48 **
2
128
 
3
129
  ## Released 0.1.2 ##
@@ -1,25 +1,8 @@
1
1
  CHANGELOG
2
2
  History.txt
3
3
  Manifest.txt
4
- README.txt
4
+ README.markdown
5
5
  Rakefile
6
- examples/qdfilechooser.rb
7
- examples/rfe.rb
8
- examples/rfe_renderer.rb
9
- examples/sqlc.rb
10
- examples/test1.rb
11
- examples/test2.rb
12
- examples/testcombo.rb
13
- examples/testd.db
14
- examples/testkeypress.rb
15
- examples/testmenu.rb
16
- examples/testtable.rb
17
- examples/testtabp.rb
18
- examples/testtodo.rb
19
- examples/todocsv.csv
20
- examples/viewtodo.rb
21
- lib/rbcurse.rb
22
- lib/rbcurse.rb
23
6
  lib/rbcurse/action.rb
24
7
  lib/rbcurse/applicationheader.rb
25
8
  lib/rbcurse/celleditor.rb
@@ -27,32 +10,82 @@ lib/rbcurse/checkboxcellrenderer.rb
27
10
  lib/rbcurse/colormap.rb
28
11
  lib/rbcurse/comboboxcellrenderer.rb
29
12
  lib/rbcurse/defaultlistselectionmodel.rb
13
+ lib/rbcurse/io.rb
30
14
  lib/rbcurse/keylabelprinter.rb
31
15
  lib/rbcurse/listcellrenderer.rb
16
+ lib/rbcurse/listeditable.rb
32
17
  lib/rbcurse/listkeys.rb
33
18
  lib/rbcurse/listscrollable.rb
34
19
  lib/rbcurse/listselectable.rb
35
20
  lib/rbcurse/mapper.rb
36
21
  lib/rbcurse/orderedhash.rb
22
+ lib/rbcurse/rchangeevent.rb
37
23
  lib/rbcurse/rcombo.rb
38
24
  lib/rbcurse/rdialogs.rb
25
+ lib/rbcurse/rform.rb
39
26
  lib/rbcurse/rinputdataevent.rb
40
27
  lib/rbcurse/rlistbox.rb
41
28
  lib/rbcurse/rmenu.rb
42
29
  lib/rbcurse/rmessagebox.rb
30
+ lib/rbcurse/rmulticontainer.rb
31
+ lib/rbcurse/rmultitextview.rb
43
32
  lib/rbcurse/rpopupmenu.rb
33
+ lib/rbcurse/rscrollform.rb
34
+ lib/rbcurse/rscrollpane.rb
35
+ lib/rbcurse/rsplitpane.rb
44
36
  lib/rbcurse/rtabbedpane.rb
37
+ lib/rbcurse/rtabbedwindow.rb
45
38
  lib/rbcurse/rtable.rb
46
39
  lib/rbcurse/rtextarea.rb
47
40
  lib/rbcurse/rtextview.rb
41
+ lib/rbcurse/rviewport.rb
48
42
  lib/rbcurse/rwidget.rb
49
43
  lib/rbcurse/scrollable.rb
50
44
  lib/rbcurse/selectable.rb
51
45
  lib/rbcurse/table/tablecellrenderer.rb
52
46
  lib/rbcurse/table/tabledatecellrenderer.rb
47
+ lib/rbcurse/undomanager.rb
48
+ lib/rbcurse/vieditable.rb
49
+ lib/rbcurse.rb
53
50
  lib/ver/keyboard.rb
54
51
  lib/ver/keyboard2.rb
55
52
  lib/ver/ncurses.rb
56
53
  lib/ver/window.rb
57
- test/test_rbcurse.rb
58
-
54
+ examples/keytest.rb
55
+ examples/mpad2.rb
56
+ examples/newtesttabp.rb
57
+ examples/qdfilechooser.rb
58
+ examples/rfe.rb
59
+ examples/rfe_renderer.rb
60
+ examples/rvimsplit.rb
61
+ examples/sqlc.rb
62
+ examples/sqlm.rb
63
+ examples/test1.rb
64
+ examples/test2.rb
65
+ examples/testchars.rb
66
+ examples/testcombo.rb
67
+ examples/testkeypress.rb
68
+ examples/testmenu.rb
69
+ examples/testmulticomp.rb
70
+ examples/testscroller.rb
71
+ examples/testscrolllb.rb
72
+ examples/testscrollp.rb
73
+ examples/testscrollta.rb
74
+ examples/testscrolltable.rb
75
+ examples/testsplit.rb
76
+ examples/testsplit2.rb
77
+ examples/testsplit3.rb
78
+ examples/testsplit3_1.rb
79
+ examples/testsplit3a.rb
80
+ examples/testsplit3b.rb
81
+ examples/testsplitta.rb
82
+ examples/testsplittv.rb
83
+ examples/testsplittvv.rb
84
+ examples/testtable.rb
85
+ examples/testtabp.rb
86
+ examples/testtestw.rb
87
+ examples/testtodo.rb
88
+ examples/testtpane.rb
89
+ examples/testtpane2.rb
90
+ examples/testtpanetable.rb
91
+ examples/viewtodo.rb
@@ -0,0 +1,423 @@
1
+ # rbcurse (for ruby 1.9.1)
2
+
3
+ * Version to work with ruby 1.9 (backward compatible with 1.8.7)
4
+
5
+ This branch - RFED19 - contains major rework on the buffering approach. It only affect
6
+ programs that have used buffers such as splitpanes, scrollpanes and tabbedpanes.
7
+ All are fixed.
8
+
9
+ Check downloads at <http://github.com/rkumar/rbcurse/downloads>
10
+
11
+ Some of the samples mentioned below may **not** work. test2.rb works - i always give it a quick run after making changes. All the testsplit* and testscroll* examples are working.
12
+
13
+ * <http://totalrecall.wordpress.com> - always has some status posted.
14
+
15
+ * Notes on rbcurse - very frequent updates <http://rbcurse.tumblr.com/>
16
+
17
+ * rbcurse on rubyforge: <http://rbcurse.rubyforge.org/> - Not updated.
18
+
19
+ * See changes on (not updated often)
20
+ <http://github.com/rkumar/rbcurse/tree/master/CHANGELOG>
21
+
22
+ * Many working demos in examples folder, such as:
23
+
24
+ * test2.rb (exit with F1, Or Cancel button/Alt-C) contains various
25
+ widgets. F2 for menubar toggling
26
+
27
+ * rfe.rb is a ruby file explorer demo.
28
+
29
+ * sqlc.rb is a ruby sql client _demo_ (using testd.db at
30
+ <http://www.benegal.org/files/screen/testd.db>)
31
+ (requires gem sqlite3-ruby)
32
+ sqlc.rb: uses tabbedpanes - each query opens a new tab
33
+ sqlm.rb: uses a multi-container - each query opens a new table in the multicontainer
34
+
35
+ * testtodo.rb is a test TODO application (now using fastercsv)
36
+ (needs retesting - may not work at all)
37
+
38
+ * Screenshots on
39
+ <http://www.benegal.org/files/screen/?M=D> (new)
40
+ and on blog, <http://totalrecall.wordpress.com>
41
+ and http://github.com/rkumar/rbcurse/wikis/screenshots (old)
42
+
43
+ * Todo (for 0.1.2):
44
+ <http://rubyforge.org/pm/task.php?group_id=7775&group_project_id=13812&func=browse>
45
+
46
+ See [TODO2.txt](http://github.com/rkumar/rbcurse/blob/rbcurse19/TODO2.txt) (created and maintained by [todoapp.sh](http://github.com/rkumar/todoapp), also hosted here)
47
+
48
+ * Next Major Release:
49
+ <http://rubyforge.org/pm/task.php?group_project_id=13813&group_id=7775&func=browse>
50
+
51
+ ## DESCRIPTION:
52
+
53
+ A small but comprehensive widget library written in ruby for creating ncurses
54
+ applications.
55
+
56
+ ## FEATURES
57
+
58
+ * Field : text/entry fields in pure ruby (not ncurses)
59
+ * scrollable list box (also editable lists with Field, checkbox and combos)
60
+ * Textarea : multi-line editable area
61
+ * togglebutton, radio and check buttons (with mnemonics)
62
+ * message box
63
+ * menubar - with submenu and CheckBoxMenuItem
64
+ * popup list
65
+ * tabbedpane (multiple forms using tabbed metaphor)
66
+ * combobox
67
+ * labels with mnemonics (hotkeys)
68
+ * Table: multi-column table - with cell selection and editing, horizontal and
69
+ vertical scrolling
70
+ * Scrollpanes which can contain textviews, textareas, listboxes.
71
+ * Splitpanes which can contain scrollpanes, textviews/areas, listboxes *or splitpanes* ...
72
+ * MultiContainer = add any number of objects to it (such as tables or text objects) and cycle through them
73
+ (saves screen estate)
74
+ * MultiTextView - have multiple files open for viewing in one component. Since these are readonly files, one can map a lot of single-keys as in vim for operating and cycling through buffers.
75
+ * Textview - editable option using vim like keys.
76
+ * PromptMenu - A simple interactive menu like the `most` application. Saves on allocating keybindings and memorizing them.
77
+ * multiple key bindings for Procs, block and symbols (as in vim and emacs: `C-x C-f` or `15dd`)
78
+ * Kill-ring concept of emacs for cut-paste operations
79
+ * Unlimited undo and redo in TextArea (needs to be switched on at present on instance basis)
80
+ * Numeric arguments. (vim: 25dd etc. Or in an editable box, emacs's C-u or Alt-1..9)
81
+ * Various others, too
82
+
83
+ Above may be created using DSL like syntax, or hashes, and modified at
84
+ runtime. Very flexible unlike ncurses forms and fields.
85
+
86
+ ## Current work
87
+
88
+ I've just added vi and emacs key bindings to some classes, multiple object containers such as MultiContainer
89
+ and MultiTextView. Emacs like kill-ring in TextArea and TextView. Tabbedpane can have unlimited tabs, we can scroll the tabs. Bunch of other stuff. Multiple keys can be bound to a Proc or symbol as in emacs and vim (dd or C-x C-f).
90
+
91
+ I've made a demo using ScrollForm (testscroller.rb)- a form that takes more fields/objects than
92
+ can be viewed at a go. Meta keys scroll the form.
93
+ Then onto testing what's there, before making a stable
94
+ release.
95
+
96
+ ## Sample programs:
97
+
98
+ * test2.rb most widgets (including menus)
99
+ * sqlc.rb is a ruby sql client demo (using sqlite3-ruby)
100
+ * rfe : file explorer or Finder like app
101
+ * testcombo.rb combos with various insert policies and vertical
102
+ alignments
103
+ * testtodo.rb : a todo app based on a yaml file (now csv)
104
+ * testmenu.rb : popup menu with multiple levels
105
+ * testtabp.rb tabbed pane
106
+ * test1.rb various kinds of messageboxes (input, list, custom)
107
+ pass 1,2,3,4, or 5 as argument on command line
108
+ ruby test1.rb 1
109
+ ruby test1.rb 2
110
+ * test2.rb most widgets (including menus)
111
+ - partially tested, many widgets, needs thorough testing.
112
+
113
+ * testscroll*.rb - various demos of scrollpanes with listboxes, text areas, tables etc
114
+
115
+ * testsplit*.rb - various splitpanes with scrollpanes and other objects placed inside
116
+ See screenshots on blog.
117
+
118
+ * testtpane.rb - tabbedpane sample with a scrollpane and a textobject.
119
+
120
+ ## PROBLEMS, ISSUES
121
+
122
+
123
+ ## General terminal related issues.
124
+
125
+ The following are issues with terminals (or with ncurses-ruby in some cases) not with rbcurse.
126
+
127
+ * Some terminals may not show underlines (e.g screen).
128
+
129
+ * Some terminals (xterm-color) do not process Function keys, avoid declaring F1 etc if
130
+ unsure of client terminals. I have put in fixes for xterm-color F1 and
131
+ backtab.
132
+
133
+ * To use ALT/META keys on a Mac OS X, in Terminal preferences, under
134
+ Keyboard, select
135
+ "use Option as Meta key". All hotkeys are automatically, ALT combinations.
136
+
137
+ * Some screens do not display window background color under spaces.
138
+ This is okay under "screen" and "xterm-color" but not under "xterm". You will notice
139
+ this in the message box samples.
140
+
141
+ I am developing and testing under "screen" under OS X Leopard 10.5.8 PPC.
142
+
143
+ ## SYNOPSIS:
144
+
145
+ See lib/rbcurse/rwidgets.rb.
146
+ For test programs, see test1, test2, testcombo etc in examples folder.
147
+
148
+ This depends only on "window" provided by ncurses. Does not use forms
149
+ and fields. Minor changes and improvements may have happened to sample
150
+ code below. **See test programs for latest, working code.**
151
+
152
+ THE following samples are only demonstrative of how widgets are built. See samples in examples folder for initialization of ncurses etc which is necessary before the following code can be run. The following samples may be slightly obsolete.
153
+
154
+ ### create a window and a form based on window
155
+
156
+ @layout = { :height => 0, :width => 0, :top => 0, :left => 0 }
157
+ @win = VER::Window.new(@layout)
158
+
159
+ @form = Form.new @win
160
+
161
+
162
+ ### create a bunch of fields with dependent labels
163
+
164
+ r = 1; c = 22;
165
+ %w[ name age company].each do |w|
166
+ field = Field.new @form do
167
+ name w
168
+ row r
169
+ col c
170
+ display_length 30
171
+ set_buffer "abcd #{w}"
172
+ set_label Label.new @form, {'text' => w}
173
+ end
174
+ r += 1
175
+ end
176
+
177
+ ### create a variable (like TkVariable) and tie a label to it.
178
+
179
+ $results = Variable.new
180
+ $results.value = "A variable"
181
+ var = RubyCurses::Label.new @form, {'text_variable' => $results, "row" => r, "col" => 22}
182
+ r += 1
183
+
184
+ ### create a list and a list box based on the list.
185
+
186
+ mylist = []
187
+ 0.upto(100) { |v| mylist << "#{v} scrollable data" }
188
+
189
+ field = Listbox.new @form do
190
+ name "mylist"
191
+ row r
192
+ col 1
193
+ width 40
194
+ height 10
195
+ list mylist
196
+ end
197
+ field.insert 5, "hello ruby", "so long python", "farewell java", "RIP .Net"
198
+
199
+ ### create a textarea for entry
200
+
201
+ texta = TextArea.new @form do
202
+ name "mytext"
203
+ row 1
204
+ col 52
205
+ width 40
206
+ height 20
207
+ end
208
+ texta << "hello there" << "Some text to go into textarea."
209
+ texta << "HELLO ruby" << "Some text to go into textarea."
210
+
211
+ ### create a check box, updates a Variable
212
+
213
+ checkbutton = CheckBox.new @form do
214
+ text_variable $results
215
+ #value = true
216
+ onvalue "selected cb"
217
+ offvalue "UNselected cb"
218
+ text "Please click me"
219
+ row 17
220
+ col 22
221
+ end
222
+
223
+ ### change field properties at any time by referring to them by name
224
+
225
+ @form.by_name["age"].display_length = 3
226
+ @form.by_name["age"].maxlen = 3
227
+ @form.by_name["age"].set_buffer "24"
228
+ @form.by_name["name"].set_buffer "Not focusable"
229
+ @form.by_name["age"].chars_allowed = /\d/
230
+ @form.by_name["company"].type(:ALPHA)
231
+ @form.by_name["name"].set_focusable(false)
232
+
233
+ @form.by_name["password"].color 'red'
234
+ @form.by_name["password"].bgcolor 'blue'
235
+
236
+ # restrict entry to some values
237
+ password.values(%w[ scotty tiger secret qwerty])
238
+
239
+ # validation using ruby's regular expressions
240
+
241
+ field.valid_regex(/^[A-Z]\d+/)
242
+
243
+ ### bind events to forms, and fields
244
+
245
+ @form.bind(:ENTER) { |f| f.label.bgcolor = $promptcolor if f.instance_of? RubyCurses::Field}
246
+ @form.bind(:LEAVE) { |f| f.label.bgcolor = $datacolor if f.instance_of? RubyCurses::Field}
247
+
248
+ ### create buttons
249
+
250
+ ok_button = Button.new @form do
251
+ text "OK"
252
+ name "OK"
253
+ row 18
254
+ col 22
255
+ end
256
+ ok_button.command { |form| $results.value = "OK PRESS:";form.printstr(@window, 23,45, "OK CALLED") }
257
+ #text "Cancel"
258
+ cancel_button = Button.new @form do
259
+ text_variable $results
260
+ row 18
261
+ col 28
262
+ end
263
+ cancel_button.command { |form| form.printstr(@window, 23,45, "Cancel CALLED"); throw(:close); }
264
+
265
+ ### create radio buttons
266
+
267
+ colorlabel = Label.new @form, {'text' => "Select a color:", "row" => 20,
268
+ "col" => 22, "color"=> "cyan"}
269
+ $radio = Variable.new
270
+ radio1 = RadioButton.new @form do
271
+ text_variable $radio
272
+ text "red"
273
+ value "red"
274
+ color "red"
275
+ row 21
276
+ col 22
277
+ end
278
+ radio2 = RadioButton.new @form do
279
+ text_variable $radio
280
+ text "green"
281
+ value "green"
282
+ color "green"
283
+ row 22
284
+ col 22
285
+ end
286
+
287
+ ### create a messagebox
288
+
289
+ @mb = RubyCurses::MessageBox.new do
290
+ title "Enter your name"
291
+ message "Enter your name"
292
+ type :input
293
+ default_value "rahul"
294
+ default_button 0
295
+ end
296
+ #title "Color selector"
297
+ #type :custom
298
+ #buttons %w[red green blue yellow]
299
+ #underlines [0,0,0,0]
300
+
301
+ $log.debug "MBOX : #{@mb.selected_index} "
302
+ $log.debug "MBOX : #{@mb.input_value} "
303
+
304
+ ### create a read-only scrollable view of data
305
+
306
+ @textview = TextView.new @form do
307
+ name "myView"
308
+ row 16
309
+ col 52
310
+ width 40
311
+ height 7
312
+ end
313
+ content = File.open("../../README.markdown","r").readlines
314
+ @textview.set_content content
315
+
316
+ ## set it to point to row 21
317
+ @textview.top_row 21
318
+
319
+
320
+ # lets scroll the text view as we scroll the listbox
321
+
322
+ listb.bind(:ENTER_ROW, @textview) { |arow, tview| tview.top_row arow }
323
+
324
+ # lets scroll the text view to the line you enter in the numeric
325
+ # field
326
+ @form.by_name["line"].bind(:LEAVE, @textview) { |fld, tv| tv.top_row(fld.getvalue.to_i) }
327
+
328
+ # lets scroll the text view to the first match of the regex you
329
+ # enter
330
+ @form.by_name["regex"].bind(:LEAVE, @textview) { |fld, tv| tv.top_row(tv.find_first_match(fld.getvalue)) }
331
+
332
+ # change the value of colorlabel to the selected radiobutton
333
+ # (red or green)
334
+
335
+ $radio.update_command(colorlabel) {|tv, label| label.color tv.value}
336
+
337
+ # change the attribute of colorlabel to bold or normal
338
+
339
+ $results.update_command(colorlabel,checkbutton) {|tv, label, cb|
340
+ attrs = cb.value ? 'bold' : nil; label.attrs(attrs)}
341
+
342
+ # during menu creation, create a checkboxmenuitem
343
+
344
+ item = RubyCurses::CheckBoxMenuItem.new "CheckMe"
345
+
346
+ # when selected, make colorlabel attribute reverse.
347
+
348
+ item.command(colorlabel){|it, label| att = it.getvalue ? 'reverse' :
349
+ nil; label.attrs(att); label.repaint}
350
+
351
+ ## REQUIREMENTS:
352
+
353
+ * ruby 1.9.1 (I believe it is working on 1.8.7 as well).
354
+
355
+ * ncurses-ruby (1.2.4)
356
+
357
+ (Note: 1.8.6 users: pls report any issues and suggest a fix or alternative if you encounter a method_missing)
358
+
359
+
360
+ ## INSTALL:
361
+
362
+ STEP 1.
363
+
364
+ `sudo gem install ncurses-ruby`
365
+
366
+ If the above fails, then do as follows:
367
+
368
+ Somehow at the time of writing the above installs a version that does
369
+ not work with 1.9. So you have to download ncurses-ruby (1.2.4) tgz from
370
+ <http://ncurses-ruby.berlios.de/> as follows:
371
+
372
+ 1. Download <http://prdownload.berlios.de/ncurses-ruby/ncurses-ruby-1.2.4.tar.bz2>
373
+ 2. unzip the file, cd into dir
374
+ 2. run install commands as per README (`ruby extconf.rb && make`)
375
+ 3. Create a gemspec ... use this file <http://gist.github.com/201877>
376
+ Save it as ncurses.gemspec
377
+ 4. `sudo gem build ncurses.gemspec`
378
+ 5. `sudo gem install --local ncurses-1.2.4.gem`
379
+ 6. **uninstall** any previous ncurses or ncurses-ruby version otherwise
380
+ errors will persist at runtime.
381
+ 7. check with `gem list --local` and you should see ncurses (1.2.4). The
382
+ examples in the ncurses-ruby/examples folder should work. (Check the
383
+ first line regarding interpreter first).
384
+ 8. As a last resort, I've put up a copy of the gem [here](http://www.benegal.org/files/ncurses-1.2.4.gem).
385
+
386
+ (edit: I am told that step 2 installs ncurses-ruby locally, so you don't need to create a gem)
387
+
388
+ STEP 2.
389
+
390
+ `sudo gem install rbcurse`
391
+
392
+ Now go to the the `examples` folder and execute some examples.
393
+
394
+ cd examples
395
+ ruby test2.rb
396
+
397
+
398
+ Note: Please use gem version 1.1.1 or higher. I have just created this gem, so let me know if there are missing files.
399
+
400
+ ### Installing ncurses on Mac OS X Snow Leopard
401
+
402
+ STEP 1.
403
+
404
+ ncurses-ruby 1.2.4 is not installing, errors in `make`. I have not found a working solution. Finally, I used ncurses-0.9.1 and made some changes and it is working. Needs to be tested out. I am not sure how I got ncurses-0.9.1 in my gems folder, possible I had done a `sudo port install ncurses`.
405
+
406
+ http://trickyco.de/tag/ncurses has a similar procedure. I made the changes based on my working copy of 1.2.4 from my OS X PPC Machine. Will upload the gem and code.
407
+
408
+ trickyco's procedure is as follows:
409
+
410
+ gem fetch ncurses
411
+ gem unpack ncurses-0.9.1.gem
412
+ ruby extconf.rb
413
+ patch -p1 < ~/ncurses_ruby_1.9.patch
414
+ make
415
+ sudo make install
416
+
417
+ See the patch file from http://trickyco.de/tag/ncurses . See other steps as above.
418
+
419
+ ## LICENSE:
420
+
421
+ Copyright (c) 2008 -2010 rkumar
422
+
423
+ Same as ruby license.