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/Rakefile CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
 
4
4
  #
5
- require 'rubygems'
5
+ #require 'rubygems'
6
6
  require 'hoe'
7
7
  $:.unshift(File.dirname(__FILE__) + "/lib")
8
8
  require 'rbcurse'
9
9
  #require './lib/rbcurse.rb'
10
10
 
11
11
  Hoe.new('rbcurse', Rbcurse::VERSION) do |p|
12
+ #Hoe.spec('rbcurse', Rbcurse::VERSION) do |p|
13
+ #Hoe.spec('rbcurse') do
12
14
  p.name = "rbcurse"
13
15
  p.author = "Rahul Kumar"
14
16
  p.description = "Ruby curses widgets for easy application development"
@@ -0,0 +1,177 @@
1
+ $LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
+ require 'rubygems'
3
+ require 'ncurses'
4
+ require 'logger'
5
+ require 'rbcurse'
6
+ #require 'lib/ver/ncurses'
7
+ #require 'lib/ver/window'
8
+ require 'lib/rbcurse/rwidget'
9
+ require 'lib/ver/keyboard2'
10
+ #require 'lib/rbcurse/mapper'
11
+
12
+ # Using mapper with keyboard2 which gives numeric keys
13
+ # The error messages are not so pretty, otherwise its okay... error messages need a little work
14
+ # Use C-q or q to quit
15
+ ## C-s starts a new mode :cx, 'i' gets back to normal
16
+ #include Ncurses
17
+
18
+
19
+ def printstr(pad, r,c,string, color, att = Ncurses::A_NORMAL)
20
+
21
+ #att = bold ? Ncurses::A_BLINK|Ncurses::A_BOLD : Ncurses::A_NORMAL
22
+ # att = bold ? Ncurses::A_BOLD : Ncurses::A_NORMAL
23
+ pad.attrset(Ncurses.COLOR_PAIR(color) | att)
24
+ #pad.mvprintw(r, c, "%s", string);
25
+ pad.mvaddstr(r, c, "%s" % string);
26
+ pad.attroff(Ncurses.COLOR_PAIR(color) | att)
27
+ end
28
+ class KeyTest
29
+ attr_reader :window # needed by keyboard to do getch
30
+ attr_accessor :mode # needed by handler
31
+ def initialize win
32
+ @window = win
33
+ @color = $datacolor
34
+ @mode = :normal
35
+ map_keys
36
+ VER::Keyboard2.focus = self
37
+ end
38
+ def down
39
+ printstr(@window, 12,1,"GOT Down ", @color, att = Ncurses::A_NORMAL)
40
+ end
41
+ def up
42
+ printstr(@window, 12,1,"GOT Up ", @color, att = Ncurses::A_REVERSE)
43
+ end
44
+ def do_select
45
+ printstr(@window, 12,1,"GOT do_select", @color, att = Ncurses::A_BOLD)
46
+ end
47
+
48
+ def map_keys
49
+ @mapper = Mapper.new(self)
50
+ @keyhandler = @mapper # i don't want a separate handler, this will do
51
+
52
+ # view refers to the object passed to constrcutor of Mapper, here it is self
53
+ @mapper.let :normal do
54
+ map(?\C-x, ?\C-d){ view.down }
55
+ map(?\C-x, ?\C-u){ view.up }
56
+ map(?\C-x, ?q){ view.stop }
57
+ map(?\C-x, ?\C-s){ view.do_search_ask }
58
+ map(?\C-x, ?\C-x){ view.do_select }
59
+ map(?q){ view.stop }
60
+ map(?q){ view.stop }
61
+ map(32){ view.space }
62
+ map(?n){ view.space }
63
+ map(?j){ :down }
64
+ map(?k){ view.up }
65
+ map(?p){ view.minus }
66
+ map(?[) { view.goto_start }
67
+ map(?]) { view.goto_end }
68
+ map(?-) { view.minus }
69
+
70
+ map('right') { view.right}
71
+ map(?l) { view.right}
72
+ map('left') {view.left}
73
+ map(?h) {view.left}
74
+ map(KEY_DOWN) { view.down }
75
+ map(?j) { view.down }
76
+ map(KEY_UP) { view.up }
77
+ map(KEY_ENTER) { view.enter }
78
+ map(?g) { view.handle_goto_ask }
79
+ map(?/) { view.do_search_ask }
80
+ map(?\C-n) { view.do_search_next }
81
+ map(?\C-p) { view.do_search_prev }
82
+ map(?x) { view.do_select }
83
+ map(?\') { view.do_next_selection }
84
+ map(?") { view.do_prev_selection }
85
+ map(?\C-e) { view.do_clear_selection }
86
+ ## C-s starts a new mode, i gets back to normal
87
+ map(?\C-s){ view.mode = :cx }
88
+ # all printable chars not trapped above are caught here
89
+ map(/^([[:print:]])$/){ view.show("Got printable: #{@arg} ") }
90
+
91
+
92
+ map(?\C-q){ view.stop }
93
+ end
94
+
95
+ ## a mode, started by C-s, use i to go back, q to quit
96
+ @mapper.let :cx do
97
+ map(?c.getbyte(0)){ view.show(:c) }
98
+ map(?a.getbyte(0)){ view.show(:a) }
99
+ map(?r.getbyte(0)){ view.show(:r) }
100
+ map(?q.getbyte(0)){ view.stop }
101
+ map(?i.getbyte(0)){ view.mode = :normal }
102
+ end
103
+ end
104
+ def press(key)
105
+ # I can intercept printable keys here
106
+ $log.debug("press key: %s" % key)
107
+ begin
108
+ @keyhandler.press(key)
109
+ #break if stopping?
110
+ return if stopping?
111
+ if !@message.nil?
112
+ printstr(@window, 18,1,"%40s" % @message, $promptcolor, att = Ncurses::A_NORMAL)
113
+ @message = nil
114
+ end
115
+
116
+ rescue ::Exception => ex
117
+ $log.debug ex
118
+ show(ex.message)
119
+ end
120
+ end # press
121
+
122
+ # from VER
123
+ def stopping?
124
+ @stop
125
+ end
126
+ def show string
127
+ @message = string
128
+ end
129
+
130
+ # without this system hangs if unknown key presed
131
+ def info(message)
132
+ @message = message
133
+ end
134
+
135
+ def stop
136
+ @stop = true
137
+ throw(:close)
138
+ end
139
+ end
140
+ if $0 == __FILE__
141
+ include RubyCurses
142
+ include RubyCurses::Utils
143
+ begin
144
+ # Initialize curses
145
+ VER::start_ncurses
146
+ $reversecolor = 2
147
+ $errorcolor = 7
148
+ $promptcolor = $selectedcolor = 4
149
+ $normalcolor = $datacolor = 5
150
+ $bottomcolor = $topcolor = 6
151
+
152
+ # Create the window to be associated with the form
153
+ # Un post form and free the memory
154
+ $log = Logger.new("view.log")
155
+ $log.level = Logger::DEBUG
156
+
157
+ catch(:close) do
158
+ @layout = { :height => 0, :width => 0, :top => 0, :left => 0 }
159
+ @window = VER::Window.new(@layout)
160
+ @window.bkgd(Ncurses.COLOR_PAIR(5));
161
+ @panel = @window.panel
162
+ @window.wrefresh
163
+ Ncurses::Panel.update_panels
164
+ $log.debug "START ---------"
165
+ kt = KeyTest.new @window
166
+ end
167
+ rescue => ex
168
+ ensure
169
+ Ncurses::Panel.del_panel(@panel) if !@panel.nil?
170
+ @window.delwin if !@window.nil?
171
+ VER::stop_ncurses
172
+ p ex if ex
173
+ p(ex.backtrace.join("\n")) if ex
174
+ $log.debug( ex) if ex
175
+ $log.debug(ex.backtrace.join("\n")) if ex
176
+ end
177
+ end
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # REQUIRES A FILE NAMED "TODO" in current folder, to display and page
4
+ # a basic file pager to check out ncurses ruby pad
5
+ # working in 1.8.7 but not showing anything when i hit a key in 1.9.1
6
+ require 'rubygems'
7
+ require 'ncurses'
8
+ require 'logger'
9
+
10
+ include Ncurses
11
+ include Ncurses::Form
12
+
13
+ class Fixnum
14
+ def ord
15
+ self
16
+ end
17
+ ## mostly for control and meta characters
18
+ def getbyte(n)
19
+ self
20
+ end
21
+ end unless "a"[0] == "a"
22
+
23
+
24
+ # Initialize curses
25
+ begin
26
+ stdscr = Ncurses.initscr();
27
+ Ncurses.start_color();
28
+ Ncurses.cbreak();
29
+ Ncurses.noecho();
30
+ Ncurses.keypad(stdscr, true);
31
+
32
+ # Initialize few color pairs
33
+ Ncurses.init_pair(1, COLOR_RED, COLOR_BLACK);
34
+ Ncurses.init_pair(2, COLOR_BLACK, COLOR_WHITE);
35
+ Ncurses.init_pair(3, COLOR_BLACK, COLOR_BLUE);
36
+ Ncurses.init_pair(4, COLOR_YELLOW, COLOR_RED); # for selected item
37
+ Ncurses.init_pair(5, COLOR_WHITE, COLOR_BLACK); # for unselected menu items
38
+ Ncurses.init_pair(6, COLOR_WHITE, COLOR_BLUE); # for bottom/top bar
39
+ Ncurses.init_pair(7, COLOR_WHITE, COLOR_RED); # for error messages
40
+ #stdscr.bkgd(Ncurses.COLOR_PAIR(6)); ## DO NOT TOUCH stdscr please
41
+
42
+ $log = Logger.new("view.log")
43
+ $log.level = Logger::DEBUG
44
+ # Create the window to be associated with the form
45
+ @screenrows = Ncurses.LINES-3
46
+ screencols = 80
47
+ @startrow = 1
48
+ my_form_win = WINDOW.new(0,0,0,0)
49
+ x = Array.new
50
+ y = Array.new
51
+ Ncurses.getmaxyx(my_form_win, y, x)
52
+ $log.debug " x = #{x[0]}, y = #{y[0]}"
53
+ screencols = 99; x[0]-15
54
+ my_panel = my_form_win.new_panel
55
+ textary = File.open("../TODO","r").readlines
56
+ my_pad = Ncurses.newpad(textary.count,100)
57
+ pad = my_pad.new_panel
58
+ Ncurses::Panel.update_panels
59
+
60
+ my_form_win.bkgd(Ncurses.COLOR_PAIR(5));
61
+ my_pad.keypad(TRUE);
62
+
63
+ # Set main window and sub window
64
+
65
+ # Print a border around the main window and print a title */
66
+ #my_form_win.box(0, 0);
67
+ #print_in_middle(my_form_win, 1, 0, cols[0] + 14, "Main Menu", Ncurses.COLOR_PAIR(6));
68
+ Ncurses.refresh();
69
+
70
+ textary.each_index { |ix|
71
+ my_pad.mvaddstr(ix, 0, textary[ix])
72
+ }
73
+
74
+ # Print field types
75
+
76
+ #my_pad.prefresh(0,0, 0,0, Ncurses.LINES,Ncurses.COLS-1);
77
+ #my_form_win.wrefresh();
78
+ @prow = 0; @pcol = 0;
79
+ #my_pad.prefresh(0,0, @startrow ,0, @screenrows,Ncurses.COLS-1);
80
+ # trying out overwrite since copywin retuns ERR -1
81
+ #ret = Ncurses.copywin(my_pad, my_form_win, 0,0,@startrow,0, @screenrows, Ncurses.COLS-1, 0)
82
+ ### ret = Ncurses.overwrite(my_pad, my_form_win) # worked
83
+ ### $log.debug("overwrite #{ret}")
84
+ # ret = Ncurses.overwrite(my_form_win, my_pad)
85
+ #my_form_win.wrefresh(); << this line clears what pad has put, but needed by copywin etc i think
86
+
87
+
88
+ # Loop through to get user requests
89
+ # # XXX Need to clear pad so earlier data in last line does not still remain
90
+ while((ch = my_pad.getch()) != KEY_F1 )
91
+ case ch
92
+ when ?j.getbyte(0)
93
+ @prow += 1
94
+ #next
95
+ # disallow
96
+ if @prow > textary.count
97
+ @prow = textary.count
98
+ Ncurses.beep
99
+ next
100
+ end
101
+ #when KEY_UP
102
+ when ?k.getbyte(0)
103
+ @prow -= 1
104
+ #next
105
+ # disallow
106
+ if @prow <= 0
107
+ Ncurses.beep
108
+ @prow = 0
109
+ next
110
+ end
111
+ when 32
112
+ @prow += @screenrows
113
+ if @prow > textary.count
114
+ @prow = textary.count
115
+ Ncurses.beep
116
+ next
117
+ end
118
+ when ?-.getbyte(0)
119
+ if @prow <= 0
120
+ Ncurses.beep
121
+ @prow = 0
122
+ next
123
+ end
124
+ @prow -= @screenrows
125
+ when ?t.getbyte(0)
126
+ @pcol = @prow = 0
127
+ when ?h.getbyte(0)
128
+ @pcol += 1
129
+ when ?l.getbyte(0)
130
+ @pcol -= 1
131
+ when ?r.getbyte(0)
132
+ my_form_win.wclear # 2009-10-10 17:46
133
+ when KEY_ENTER, 10
134
+ # selection
135
+ when ?q.getbyte(0), ?\,
136
+ break
137
+ end
138
+ @pcol = 0 if @pcol < 0
139
+ # clear is required but in 1.9.1 there is no prefresh after a clear. screen blanks out totally
140
+ #my_form_win.wclear # 2009-10-10 17:46
141
+ #my_form_win.werase # 2009-10-10 17:46
142
+ # my_pad.prefresh(@prow,@pcol, @startrow,0, @screenrows,Ncurses.COLS-1);
143
+ #ret = Ncurses.copywin(my_pad, my_form_win, @prow,@pcol,@startrow,0, @screenrows, Ncurses.COLS-1, 0)
144
+ #ret = my_pad.copywin( my_form_win, @prow,@pcol,@startrow,0, @screenrows, Ncurses.COLS-1, 0)
145
+ ret = my_pad.copywin( my_form_win, @prow,@pcol,0,0, @screenrows, screencols, 0)
146
+ $log.debug("copywin #{ret} : cols:#{screencols}")
147
+ my_form_win.wrefresh # if i don't put this then upon return the other screen is still shown
148
+ # till i press a key
149
+ Ncurses::Panel.update_panels
150
+ end
151
+ # Un post form and free the memory
152
+
153
+
154
+ ensure
155
+ Ncurses.endwin();
156
+ end
@@ -0,0 +1,121 @@
1
+ # this is a test program, tests out tabbed panes. type F1 to exit
2
+ #
3
+ #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
4
+ require 'rubygems'
5
+ require 'ncurses'
6
+ require 'logger'
7
+ require 'rbcurse'
8
+ #require 'rbcurse/newtabbedpane'
9
+ require 'rbcurse/rtabbedpane'
10
+
11
+ class TestTabbedPane
12
+ def initialize
13
+ acolor = $reversecolor
14
+ #$config_hash ||= {}
15
+ end
16
+ def run
17
+ $config_hash ||= Variable.new Hash.new
18
+ #configvar.update_command(){ |v| $config_hash[v.source()] = v.value }
19
+ @window = VER::Window.root_window
20
+ @form = Form.new @window
21
+ r = 1; c = 30;
22
+ @tp = RubyCurses::TabbedPane.new @form do
23
+ height 12
24
+ width 50
25
+ row 13
26
+ col 10
27
+ button_type :ok
28
+ end
29
+ @tab1 = @tp.add_tab "&Language"
30
+ f1 = @tab1.form
31
+ #$radio = Variable.new
32
+ radio1 = RadioButton.new f1 do
33
+ #variable $radio
34
+ variable $config_hash
35
+ name "radio1"
36
+ text "ruby"
37
+ value "ruby"
38
+ color "red"
39
+ row 4
40
+ col 5
41
+ end
42
+ radio2 = RadioButton.new f1 do
43
+ #variable $radio
44
+ variable $config_hash
45
+ name "radio1"
46
+ text "jruby"
47
+ value "jruby"
48
+ color "green"
49
+ row 5
50
+ col 5
51
+ end
52
+ radio3 = RadioButton.new f1 do
53
+ #variable $radio
54
+ variable $config_hash
55
+ name "radio1"
56
+ text "macruby"
57
+ value "macruby"
58
+ color "cyan"
59
+ row 6
60
+ col 5
61
+ end
62
+ @tab2 = @tp.add_tab "&Settings"
63
+ f2 = @tab2.form
64
+ r = 4
65
+ butts = [ "Use &HTTP/1.0", "Use &frames", "&Use SSL" ]
66
+ bcodes = %w[ HTTP, FRAMES, SSL ]
67
+ butts.each_with_index do |t, i|
68
+ RubyCurses::CheckBox.new f2 do
69
+ text butts[i]
70
+ variable $config_hash
71
+ name bcodes[i]
72
+ row r+i
73
+ col 5
74
+ end
75
+ end
76
+ @tab3 = @tp.add_tab "&Editors"
77
+ f3 = @tab3.form
78
+ butts = %w[ &Vim E&macs &Jed &Other ]
79
+ bcodes = %w[ VIM EMACS JED OTHER]
80
+ row = 4
81
+ butts.each_with_index do |name, i|
82
+ RubyCurses::CheckBox.new f3 do
83
+ text name
84
+ variable $config_hash
85
+ name bcodes[i]
86
+ row row+i
87
+ col 5
88
+ end
89
+ end
90
+ @help = "q to quit. Use any key of key combination to see what's caught. Check logger too"
91
+ RubyCurses::Label.new @form, {'text' => @help, "row" => 11, "col" => 2, "color" => "yellow"}
92
+ @form.repaint
93
+ @window.wrefresh
94
+ Ncurses::Panel.update_panels
95
+ while((ch = @window.getchar()) != ?q.getbyte(0) )
96
+ # @tp.repaint
97
+ @form.handle_key(ch)
98
+ @window.wrefresh
99
+ end
100
+ #@tp.show
101
+ #@tp.handle_keys
102
+ end
103
+ end
104
+ if $0 == __FILE__
105
+ # Initialize curses
106
+ begin
107
+ # XXX update with new color and kb
108
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
109
+ $log = Logger.new("view.log")
110
+ $log.level = Logger::DEBUG
111
+ n = TestTabbedPane.new
112
+ n.run
113
+ rescue => ex
114
+ ensure
115
+ VER::stop_ncurses
116
+ p ex if ex
117
+ p(ex.backtrace.join("\n")) if ex
118
+ $log.debug( ex) if ex
119
+ $log.debug(ex.backtrace.join("\n")) if ex
120
+ end
121
+ end