rbcurse 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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/lib/ver/window.rb ADDED
@@ -0,0 +1,369 @@
1
+ require 'ver/ncurses'
2
+ module VER
3
+ # Responsibilities:
4
+ # * Interface to Ncurses::WINDOW and Ncurses::Panel
5
+ # * behave IO like: (print puts write read readline)
6
+ # * hide and show itself
7
+
8
+ # There's a very strange bug when i tried subclassing this, as Ncurses seems
9
+ # to overwrite WINDOW::new, which will not return the Window instance we
10
+ # want. So we have to wrap instead of subclass.
11
+ class Window # < Ncurses::WINDOW
12
+ attr_reader :width, :height, :top, :left
13
+ attr_accessor :layout
14
+ attr_reader :panel # XXX reader requires so he can del it in end
15
+
16
+ def initialize(layout)
17
+ @visible = true
18
+ reset_layout(layout)
19
+
20
+ @window = Ncurses::WINDOW.new(height, width, top, left)
21
+ @panel = Ncurses::Panel.new_panel(@window)
22
+ ## eeks XXX next line will wreak havoc when multiple windows opened like a mb or popup
23
+ $error_message_row = $status_message_row = Ncurses.LINES-1
24
+
25
+ Ncurses::keypad(@window, true)
26
+ @stack = []
27
+ end
28
+ def self.root_window(layout = { :height => 0, :width => 0, :top => 0, :left => 0 })
29
+ #VER::start_ncurses
30
+ @layout = layout
31
+ @window = Window.new(@layout)
32
+ @window.wrefresh
33
+ Ncurses::Panel.update_panels
34
+ return @window
35
+ end
36
+
37
+ def resize_with(layout)
38
+ reset_layout(layout)
39
+ @window.wresize(height, width)
40
+ @window.mvwin(top, left)
41
+ end
42
+
43
+ %w[width height top left].each do |side|
44
+ eval(
45
+ "def #{side}=(n)
46
+ return if n == #{side}
47
+ @layout[:#{side}] = n
48
+ resize_with @layout
49
+ end"
50
+ )
51
+ end
52
+
53
+ def resize
54
+ resize_with(@layout)
55
+ end
56
+
57
+ # Ncurses
58
+
59
+ def pos
60
+ return y, x
61
+ end
62
+
63
+ def y
64
+ Ncurses.getcury(@window)
65
+ end
66
+
67
+ def x
68
+ Ncurses.getcurx(@window)
69
+ end
70
+
71
+ def x=(n) move(y, n) end
72
+ def y=(n) move(n, x) end
73
+
74
+ def move(y, x)
75
+ return unless @visible
76
+ # Log.debug([y, x] => caller[0,4])
77
+ @window.move(y, x)
78
+ end
79
+
80
+ def method_missing(meth, *args)
81
+ @window.send(meth, *args)
82
+ end
83
+
84
+ def print(string, width = width)
85
+ return unless visible?
86
+ @window.waddnstr(string.to_s, width)
87
+ end
88
+
89
+ def print_yx(string, y = 0, x = 0)
90
+ @window.mvwaddnstr(y, x, string, width)
91
+ end
92
+
93
+ def print_empty_line
94
+ return unless visible?
95
+ @window.printw(' ' * width)
96
+ end
97
+
98
+ def print_line(string)
99
+ print(string.ljust(width))
100
+ end
101
+
102
+ def show_colored_chunks(chunks)
103
+ return unless visible?
104
+ chunks.each do |color, chunk|
105
+ color_set(color)
106
+ print_line(chunk)
107
+ end
108
+ end
109
+
110
+ def puts(*strings)
111
+ print(strings.join("\n") << "\n")
112
+ end
113
+
114
+ def refresh
115
+ return unless visible?
116
+ @window.refresh
117
+ end
118
+
119
+ def wnoutrefresh
120
+ return unless visible?
121
+ @window.wnoutrefresh
122
+ end
123
+
124
+ def color=(color)
125
+ @color = color
126
+ @window.color_set(color, nil)
127
+ end
128
+
129
+ def highlight_line(color, y, x, max)
130
+ @window.mvchgat(y, x, max, Ncurses::A_NORMAL, color, nil)
131
+ end
132
+
133
+ def getch
134
+ @window.getch
135
+ rescue Interrupt => ex
136
+ 3 # is C-c
137
+ end
138
+
139
+ # returns control, alt, alt+ctrl, alt+control+shift, F1 .. etc
140
+ # ALT combinations also send a 27 before the actual key
141
+ # Please test with above combinations before using on your terminal
142
+ # added by rkumar 2008-12-12 23:07
143
+ def getchar
144
+ while 1
145
+ ch = getch
146
+ #$log.debug "window getchar() GOT: #{ch}" if ch != -1
147
+ if ch == -1
148
+ # the returns escape 27 if no key followed it, so its SLOW if you want only esc
149
+ if @stack.first == 27
150
+ #$log.debug " -1 stack sizze #{@stack.size}: #{@stack.inspect}, ch #{ch}"
151
+ case @stack.size
152
+ when 1
153
+ @stack.clear
154
+ return 27
155
+ when 2 # basically a ALT-O, this will be really slow since it waits for -1
156
+ ch = 128 + @stack.last
157
+ @stack.clear
158
+ return ch
159
+ when 3
160
+ $log.debug " SHOULD NOT COME HERE getchar()"
161
+ end
162
+ end
163
+ @stack.clear
164
+ next
165
+ end
166
+ # this is the ALT combination
167
+ if @stack.first == 27
168
+ # experimental. 2 escapes in quick succession to make exit faster
169
+ if ch == 27
170
+ @stack.clear
171
+ return ch
172
+ end
173
+ # possible F1..F3 on xterm-color
174
+ if ch == 79 or ch == 91
175
+ #$log.debug " got 27, #{ch}, waiting for one more"
176
+ @stack << ch
177
+ next
178
+ end
179
+ #$log.debug "stack SIZE #{@stack.size}, #{@stack.inspect}, ch: #{ch}"
180
+ if @stack == [27,79]
181
+ # xterm-color
182
+ case ch
183
+ when 80
184
+ ch = KEY_F1
185
+ when 81
186
+ ch = KEY_F2
187
+ when 82
188
+ ch = KEY_F3
189
+ when 83
190
+ ch = KEY_F4
191
+ end
192
+ @stack.clear
193
+ return ch
194
+ elsif @stack == [27, 91]
195
+ if ch == 90
196
+ @stack.clear
197
+ return 353 # backtab
198
+ end
199
+ end
200
+ # the usual Meta combos. (alt)
201
+ ch = 128 + ch
202
+ @stack.clear
203
+ return ch
204
+ end
205
+ # append a 27 to stack, actually one can use a flag too
206
+ if ch == 27
207
+ @stack << 27
208
+ next
209
+ end
210
+ return ch
211
+ end
212
+ end
213
+
214
+ def clear
215
+ # return unless visible?
216
+ move 0, 0
217
+ puts *Array.new(height){ ' ' * (width - 1) }
218
+ end
219
+
220
+ # setup and reset
221
+
222
+ def reset_layout(layout)
223
+ @layout = layout
224
+
225
+ [:height, :width, :top, :left].each do |name|
226
+ instance_variable_set("@#{name}", layout_value(name))
227
+ end
228
+ end
229
+
230
+ def layout_value(name)
231
+ value = @layout[name]
232
+ default = default_for(name)
233
+
234
+ value = value.call(default) if value.respond_to?(:call)
235
+ return (value || default).to_i
236
+ end
237
+
238
+ def default_for(name)
239
+ case name
240
+ when :height, :top
241
+ Ncurses.stdscr.getmaxy
242
+ when :width, :left
243
+ Ncurses.stdscr.getmaxx
244
+ else
245
+ 0
246
+ end
247
+ end
248
+
249
+ # Ncurses panel
250
+
251
+ def hide
252
+ Ncurses::Panel.hide_panel @panel
253
+ Ncurses.refresh # wnoutrefresh
254
+ @visible = false
255
+ end
256
+
257
+ def show
258
+ Ncurses::Panel.show_panel @panel
259
+ Ncurses.refresh # wnoutrefresh
260
+ @visible = true
261
+ end
262
+
263
+ def on_top
264
+ Ncurses::Panel.top_panel @panel
265
+ wnoutrefresh
266
+ end
267
+
268
+ def visible?
269
+ @visible
270
+ end
271
+ ##
272
+ #added by rk 2008-11-29 18:48
273
+ #to see if we can clean up from within
274
+ def destroy
275
+ # typically the ensure block should have this
276
+ # @panel = @window.panel if @window
277
+ #Ncurses::Panel.del_panel(@panel) if !@panel.nil?
278
+ #@window.delwin if !@window.nil?
279
+
280
+ #@panel = @window.panel if @window
281
+ Ncurses::Panel.del_panel(@panel) if !@panel.nil?
282
+ @window.delwin if !@window.nil?
283
+ end
284
+ ##
285
+ # added by rk 2008-11-29 19:01
286
+ # I usually use this, not the others ones here
287
+ # @param r - row
288
+ # @param c - col
289
+ # @param string - text to print
290
+ # @param color - color pair
291
+ # @ param att - ncurses attribute: normal, bold, reverse, blink,
292
+ # underline
293
+ def printstring(r,c,string, color, att = Ncurses::A_NORMAL)
294
+
295
+ ## XXX check if row is exceeding height and don't print
296
+ att = Ncurses::A_NORMAL if att.nil?
297
+ case att.to_s.downcase
298
+ when 'underline'
299
+ att = Ncurses::A_UNDERLINE
300
+ when 'bold'
301
+ att = Ncurses::A_BOLD
302
+ when 'blink'
303
+ att = Ncurses::A_BLINK # unlikely to work
304
+ when 'reverse'
305
+ att = Ncurses::A_REVERSE
306
+ end
307
+
308
+ attron(Ncurses.COLOR_PAIR(color) | att)
309
+ # we should not print beyond window coordinates
310
+ # trying out on 2009-01-03 19:29
311
+ width = Ncurses.COLS
312
+ # the next line won't ensure we don't write outside some bounds like table
313
+ #string = string[0..(width-c)] if c + string.length > width
314
+ #$log.debug "PRINT #{string.length}, #{Ncurses.COLS}, #{c} "
315
+ mvprintw(r, c, "%s", string);
316
+ attroff(Ncurses.COLOR_PAIR(color) | att)
317
+ end
318
+ # added by rk 2008-11-29 19:01
319
+ def print_error_message text=$error_message
320
+ r = $error_message_row || Ncurses.LINES-1
321
+ $log.debug "got ERROR MEASSAGE #{text} row #{r} "
322
+ clear_error r, $datacolor
323
+ # print it in centre
324
+ printstring r, (Ncurses.COLS-text.length)/2, text, color = $promptcolor
325
+ end
326
+ # added by rk 2008-11-29 19:01
327
+ def print_status_message text=$status_message
328
+ r = $status_message_row || Ncurses.LINES-1
329
+ clear_error r, $datacolor
330
+ # print it in centre
331
+ printstring r, (Ncurses.COLS-text.length)/2, text, color = $promptcolor
332
+ end
333
+ # added by rk 2008-11-29 19:01
334
+ def clear_error r = $error_message_row, color = $datacolor
335
+ printstring(r, 0, "%-*s" % [Ncurses.COLS," "], color)
336
+ end
337
+ def print_border_mb row, col, height, width, color, attr
338
+ mvwaddch row, col, ACS_ULCORNER
339
+ mvwhline( row, col+1, ACS_HLINE, width-6)
340
+ mvwaddch row, col+width-5, Ncurses::ACS_URCORNER
341
+ mvwvline( row+1, col, ACS_VLINE, height-4)
342
+
343
+ mvwaddch row+height-3, col, Ncurses::ACS_LLCORNER
344
+ mvwhline(row+height-3, col+1, ACS_HLINE, width-6)
345
+ mvwaddch row+height-3, col+width-5, Ncurses::ACS_LRCORNER
346
+ mvwvline( row+1, col+width-5, ACS_VLINE, height-4)
347
+ end
348
+ def print_border row, col, height, width, color, att=Ncurses::A_NORMAL
349
+ att ||= Ncurses::A_NORMAL
350
+
351
+ (row+1).upto(row+height-1) do |r|
352
+ printstring( r, col+1," "*(width-2) , color, att)
353
+ end
354
+ attron(Ncurses.COLOR_PAIR(color) | att)
355
+
356
+
357
+ mvwaddch row, col, ACS_ULCORNER
358
+ mvwhline( row, col+1, ACS_HLINE, width-2)
359
+ mvwaddch row, col+width-1, Ncurses::ACS_URCORNER
360
+ mvwvline( row+1, col, ACS_VLINE, height-1)
361
+
362
+ mvwaddch row+height-0, col, Ncurses::ACS_LLCORNER
363
+ mvwhline(row+height-0, col+1, ACS_HLINE, width-2)
364
+ mvwaddch row+height-0, col+width-1, Ncurses::ACS_LRCORNER
365
+ mvwvline( row+1, col+width-1, ACS_VLINE, height-1)
366
+ attroff(Ncurses.COLOR_PAIR(color) | att)
367
+ end
368
+ end
369
+ end
File without changes
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbcurse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rahul Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-11 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.3
24
+ version:
25
+ description: Ruby curses widgets for easy application development
26
+ email: sentinel.2001@gmx.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - CHANGELOG
40
+ - Rakefile
41
+ - lib/rbcurse.rb
42
+ - test/test_rbcurse.rb
43
+ - lib/rbcurse/action.rb
44
+ - lib/rbcurse/applicationheader.rb
45
+ - lib/rbcurse/celleditor.rb
46
+ - lib/rbcurse/checkboxcellrenderer.rb
47
+ - lib/rbcurse/colormap.rb
48
+ - lib/rbcurse/comboboxcellrenderer.rb
49
+ - lib/rbcurse/defaultlistselectionmodel.rb
50
+ - lib/rbcurse/keylabelprinter.rb
51
+ - lib/rbcurse/listcellrenderer.rb
52
+ - lib/rbcurse/listkeys.rb
53
+ - lib/rbcurse/listscrollable.rb
54
+ - lib/rbcurse/listselectable.rb
55
+ - lib/rbcurse/mapper.rb
56
+ - lib/rbcurse/orderedhash.rb
57
+ - lib/rbcurse/rcombo.rb
58
+ - lib/rbcurse/rdialogs.rb
59
+ - lib/rbcurse/rform.rb
60
+ - lib/rbcurse/rinputdataevent.rb
61
+ - lib/rbcurse/rlistbox.rb
62
+ - lib/rbcurse/rmenu.rb
63
+ - lib/rbcurse/rmessagebox.rb
64
+ - lib/rbcurse/rpopupmenu.rb
65
+ - lib/rbcurse/rtabbedpane.rb
66
+ - lib/rbcurse/rtable.rb
67
+ - lib/rbcurse/rtextarea.rb
68
+ - lib/rbcurse/rtextview.rb
69
+ - lib/rbcurse/rwidget.rb
70
+ - lib/rbcurse/scrollable.rb
71
+ - lib/rbcurse/selectable.rb
72
+ - lib/rbcurse/table/tablecellrenderer.rb
73
+ - lib/rbcurse/table/tabledatecellrenderer.rb
74
+ - lib/ver/keyboard.rb
75
+ - lib/ver/keyboard2.rb
76
+ - lib/ver/ncurses.rb
77
+ - lib/ver/window.rb
78
+ - examples/qdfilechooser.rb
79
+ - examples/rfe.rb
80
+ - examples/rfe_renderer.rb
81
+ - examples/test1.rb
82
+ - examples/test2.rb
83
+ - examples/testcombo.rb
84
+ - examples/testkeypress.rb
85
+ - examples/testmenu.rb
86
+ - examples/testtable.rb
87
+ - examples/testtabp.rb
88
+ - examples/testtodo.rb
89
+ - examples/viewtodo.rb
90
+ has_rdoc: true
91
+ homepage: http://rbcurse.rubyforge.org/
92
+ post_install_message:
93
+ rdoc_options:
94
+ - --main
95
+ - README.txt
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
109
+ version:
110
+ requirements: []
111
+
112
+ rubyforge_project: rbcurse
113
+ rubygems_version: 1.3.1
114
+ signing_key:
115
+ specification_version: 2
116
+ summary: Ruby curses widgets.
117
+ test_files:
118
+ - test/test_rbcurse.rb