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
@@ -0,0 +1,69 @@
1
+ module RubyCurses
2
+
3
+ ##
4
+ # This is a basic list cell renderer that will render the to_s value of anything.
5
+ # Using alignment one can use for numbers too.
6
+ # However, for booleans it will print true and false. If editing, you may want checkboxes
7
+ class RfeRenderer < ListCellRenderer
8
+ def initialize text="", config={}, &block
9
+ super
10
+ @orig_bgcolor = @bgcolor
11
+ @orig_color = @color
12
+ @orig_attr = @attr
13
+ end
14
+ ##
15
+ ##
16
+ #
17
+ def repaint graphic, r=@row,c=@col, row_index=-1, value=@text, focussed=false, selected=false
18
+
19
+ @bgcolor = @orig_bgcolor
20
+ @color = @orig_color
21
+ @row_attr = @orig_attr
22
+ value = @parent.entries[row_index]
23
+ if value[0,1]=="/"
24
+ path = value.dup
25
+ else
26
+ path = @parent.cur_dir()+"/"+value
27
+ end
28
+ stat = File.stat(path)
29
+ if File.directory? path
30
+ @row_attr = Ncurses::A_BOLD
31
+ #@color = 'yellow'
32
+ end
33
+ value = format_string(value, path, stat)
34
+ super
35
+
36
+ end
37
+ GIGA_SIZE = 1073741824.0
38
+ MEGA_SIZE = 1048576.0
39
+ KILO_SIZE = 1024.0
40
+
41
+ # Return the file size with a readable style.
42
+ def readable_file_size(size, precision)
43
+ case
44
+ #when size == 1 : "1 B"
45
+ when size < KILO_SIZE : "%d B" % size
46
+ when size < MEGA_SIZE : "%.#{precision}f K" % (size / KILO_SIZE)
47
+ when size < GIGA_SIZE : "%.#{precision}f M" % (size / MEGA_SIZE)
48
+ else "%.#{precision}f G" % (size / GIGA_SIZE)
49
+ end
50
+ end
51
+ def date_format t
52
+ t.strftime "%Y/%m/%d"
53
+ end
54
+ def format_string fn, path,stat
55
+ max_len = 30
56
+ f = fn.dup
57
+ if File.directory? path
58
+ #"%-*s\t(dir)" % [max_len,f]
59
+ #f = "/"+f # disallows search on keypress
60
+ f = "/"+f
61
+ end
62
+ if f.size > max_len
63
+ f = f[0..max_len-1]
64
+ end
65
+ "%-*s %10s %s" % [max_len,f, readable_file_size(stat.size,1), date_format(stat.mtime)]
66
+ end
67
+ # ADD HERE
68
+ end
69
+ end
data/examples/test1.rb ADDED
@@ -0,0 +1,242 @@
1
+ # this is a test program, tests out messageboxes. type F1 to exit
2
+ # 2008-12-17 22:13 tried out the listdatamodel
3
+ # Certain terminals are not displaying background colors correctly.
4
+ # TERM=screen does but does not show UNDERLINES.
5
+ # TERM=xterm-color does but does not trap F1, f2 etc
6
+ # TERM=xterm does not but other things are fine.
7
+ #
8
+ #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
9
+ require 'rubygems'
10
+ require 'ncurses'
11
+ require 'logger'
12
+ #require 'lib/rbcurse/mapper'
13
+ #require 'lib/rbcurse/keylabelprinter'
14
+ require 'rbcurse'
15
+ require 'rbcurse/rmessagebox'
16
+
17
+ if $0 == __FILE__
18
+ # Initialize curses
19
+ begin
20
+ # XXX update with new color and kb
21
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
22
+ $log = Logger.new("view.log")
23
+ $log.level = Logger::DEBUG
24
+
25
+ # @window = VER::Window.root_window
26
+
27
+
28
+ catch(:close) do
29
+ choice = ARGV[0] && ARGV[0].to_i || 3
30
+ $log.debug "START MESSAGE BOX TEST #{ARGV[0]}. choice==#{choice} ---------"
31
+ # need to pass a form, not window.
32
+ case choice
33
+ when 1:
34
+ @mb = RubyCurses::MessageBox.new do
35
+ title "Enter your name"
36
+ message "Enter your name"
37
+ type :list
38
+ button_type :ok_cancel
39
+ list %w[john tim lee wong rahul edward why chad andy]
40
+ list_selection_mode 'multiple'
41
+ default_values %w[ lee why ]
42
+
43
+ default_button 0
44
+ end
45
+ when 2:
46
+ @mb = RubyCurses::MessageBox.new do
47
+ title "Color selector"
48
+ message "Select a color"
49
+ type :custom
50
+ button_type :custom
51
+ buttons %w[&red &green &blue &yellow]
52
+ underlines [0,0,0,0]
53
+ default_button 0
54
+ end
55
+ when 3
56
+ config = {}
57
+ config["input_config"] = {}
58
+ config["input_config"]["chars_allowed"]=/[^xzq]/
59
+ config["input_config"]["valid_regex"]=/[A-Z][a-z]*/
60
+ @mb = RubyCurses::MessageBox.new nil, config do
61
+ title "Enter your name"
62
+ #message "Enter your first name. You are not permitted to enter x z or q and must enter a capital first"
63
+ message "Enter your first name. "
64
+ type :input
65
+ button_type :ok_cancel
66
+ default_value "Rahul"
67
+ end
68
+ when 4:
69
+ @form = RubyCurses::Form.new nil
70
+ field_list = []
71
+ titlelabel = RubyCurses::Label.new @form, {'text' => 'User', 'row'=>3, 'col'=>4, 'color'=>'black', 'bgcolor'=>'white', 'mnemonic'=>'U'}
72
+ field_list << titlelabel
73
+ field = RubyCurses::Field.new @form do
74
+ name "url"
75
+ row 3
76
+ col 10
77
+ display_length 30
78
+ # set_buffer "http://"
79
+ set_label titlelabel
80
+ end
81
+ checkbutton = RubyCurses::CheckBox.new @form do
82
+ # variable $results
83
+ #value = true
84
+ onvalue "Selected cb "
85
+ offvalue "UNselected cb"
86
+ color 'black'
87
+ bgcolor 'white'
88
+ text "No &frames"
89
+ row 4
90
+ col 4
91
+ end
92
+ field_list << field
93
+ field_list << checkbutton
94
+ checkbutton = RubyCurses::CheckBox.new @form do
95
+ # variable $results
96
+ value true
97
+ color 'black'
98
+ bgcolor 'white'
99
+ text "Use &HTTP/1.0"
100
+ row 5
101
+ col 4
102
+ end
103
+ field_list << checkbutton
104
+ checkbutton = RubyCurses::CheckBox.new @form do
105
+ # variable $results
106
+ color 'black'
107
+ bgcolor 'white'
108
+ text "Use &passive FTP"
109
+ row 6
110
+ col 4
111
+ end
112
+ field_list << checkbutton
113
+ titlelabel = RubyCurses::Label.new @form, {'text' => 'Language', 'row'=>8, 'col'=>4, 'color'=>'black', 'bgcolor'=>'white'}
114
+ field_list << titlelabel
115
+ $radio = RubyCurses::Variable.new
116
+ #$radio.update_command(colorlabel) {|tv, label| label.color tv.value}
117
+ radio1 = RubyCurses::RadioButton.new @form do
118
+ variable $radio
119
+ text "rub&y"
120
+ value "ruby"
121
+ color "red"
122
+ bgcolor 'white'
123
+ row 9
124
+ col 4
125
+ end
126
+ radio2 = RubyCurses::RadioButton.new @form do
127
+ variable $radio
128
+ text "python"
129
+ value "py&thon"
130
+ color "blue"
131
+ bgcolor 'white'
132
+ row 10
133
+ col 4
134
+ end
135
+ field_list << radio1
136
+ field_list << radio2
137
+ field.bind(:ENTER) do |f|
138
+ listconfig = {'bgcolor' => 'blue', 'color' => 'white'}
139
+ url_list= RubyCurses::ListDataModel.new(%w[john tim lee wong rahul edward _why chad andy])
140
+ pl = RubyCurses::PopupList.new do
141
+ # title "Enter URL "
142
+ row 4
143
+ col 10
144
+ width 30
145
+ #list url_list
146
+ list_data_model url_list
147
+ list_selection_mode 'single'
148
+ relative_to f
149
+ list_config listconfig
150
+ #default_values %w[ lee _why ]
151
+ bind :PRESS do |index|
152
+ field.set_buffer url_list[index]
153
+ end
154
+ end
155
+ end
156
+ @mb = RubyCurses::MessageBox.new @form do
157
+ #title "Color selector"
158
+ title "HTTP Configuration"
159
+ # message "Enter your name"
160
+ # type :custom
161
+ # buttons %w[red green blue yellow]
162
+ # underlines [0,0,0,0]
163
+ # type :input
164
+ # default_value "rahul"
165
+ #type :field_list
166
+ #field_list field_list
167
+ button_type :ok
168
+ default_button 0
169
+ end
170
+ when 5:
171
+ @form = RubyCurses::Form.new nil
172
+ label = RubyCurses::Label.new @form, {'text' => 'File', 'row'=>3, 'col'=>4, 'color'=>'black', 'bgcolor'=>'white', 'mnemonic'=>'F'}
173
+ field = RubyCurses::Field.new @form do
174
+ name "file"
175
+ row 3
176
+ col 10
177
+ display_length 40
178
+ set_label label
179
+ end
180
+ flist = Dir.glob("*.*")
181
+ listb = RubyCurses::Listbox.new @form do
182
+ name "mylist"
183
+ row 5
184
+ col 10
185
+ width 40
186
+ height 10
187
+ list flist
188
+ title "File list"
189
+ title_attrib 'bold'
190
+ end
191
+ #listb.list.bind(:ENTER_ROW) { field.set_buffer listb.selected_item }
192
+ field.bind(:CHANGE) do |f|
193
+ flist = Dir.glob(f.getvalue+"*")
194
+ l = listb.list
195
+ l.remove_all
196
+ l.insert 0, *flist
197
+ end
198
+ @mb = RubyCurses::MessageBox.new @form do
199
+ title "Sample File Selector"
200
+ type :override
201
+ height 20
202
+ width 60
203
+ top 5
204
+ left 20
205
+ default_button 0
206
+ button_type :ok_cancel
207
+
208
+ end
209
+ $log.debug "MBOX :selected #{listb.selected_item}"
210
+ end
211
+
212
+ $log.debug "MBOX :selected button index #{@mb.selected_index} "
213
+ $log.debug "MBOX :input val #{@mb.input_value} "
214
+ # $log.debug "row : #{@form.row} "
215
+ # $log.debug "col : #{@form.col} "
216
+ # $log.debug "Config : #{@form.config.inspect} "
217
+ # @form.configure "row", 23
218
+ # @form.configure "col", 83
219
+ # $log.debug "row : #{@form.row} "
220
+ # x = @form.row
221
+ # @form.depth 21
222
+ # @form.depth = 22
223
+ # @form.depth 24
224
+ # @form.depth = 25
225
+ # $log.debug "col : #{@form.col} "
226
+ # $log.debug "config : #{@form.config.inspect} "
227
+ # $log.debug "row : #{@form.configure('row')} "
228
+ #$log.debug "mrgods : #{@form.public_methods.sort.inspect}"
229
+ #while((ch = @window.getchar()) != ?q )
230
+ # @window.wrefresh
231
+ #end
232
+ end
233
+ rescue => ex
234
+ ensure
235
+ @window.destroy unless @window.nil?
236
+ VER::stop_ncurses
237
+ p ex if ex
238
+ p(ex.backtrace.join("\n")) if ex
239
+ $log.debug( ex) if ex
240
+ $log.debug(ex.backtrace.join("\n")) if ex
241
+ end
242
+ end