rbcurse 1.4.1 → 1.5.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/CHANGELOG +31 -0
  2. data/README.markdown +69 -11
  3. data/VERSION +1 -1
  4. data/lib/rbcurse.rb +5 -5
  5. metadata +10 -198
  6. data/Makefile +0 -21
  7. data/Manifest.txt +0 -91
  8. data/TODO +0 -372
  9. data/TODO2.txt +0 -118
  10. data/examples/README.txt +0 -67
  11. data/examples/abasiclist.rb +0 -33
  12. data/examples/alpmenu.rb +0 -42
  13. data/examples/app.rb +0 -859
  14. data/examples/app.sample +0 -10
  15. data/examples/appdirtree.rb +0 -75
  16. data/examples/appemail.rb +0 -191
  17. data/examples/appemaillb.rb +0 -308
  18. data/examples/appgcompose.rb +0 -315
  19. data/examples/atree.rb +0 -64
  20. data/examples/common/file.rb +0 -40
  21. data/examples/common/rmail.rb +0 -257
  22. data/examples/data.txt +0 -683
  23. data/examples/data/README.markdown +0 -9
  24. data/examples/data/brew.txt +0 -38
  25. data/examples/data/color.2 +0 -37
  26. data/examples/data/gemlist.txt +0 -60
  27. data/examples/data/lotr.txt +0 -12
  28. data/examples/data/ports.txt +0 -136
  29. data/examples/data/tasks.txt +0 -27
  30. data/examples/data/todocsv.csv +0 -28
  31. data/examples/data/unix1.txt +0 -21
  32. data/examples/data/unix2.txt +0 -11
  33. data/examples/dbdemo.rb +0 -495
  34. data/examples/deprecated/appgmail.rb +0 -952
  35. data/examples/deprecated/splitp.rb +0 -56
  36. data/examples/deprecated/testscrolllb.rb +0 -86
  37. data/examples/deprecated/testscrollp.rb +0 -88
  38. data/examples/deprecated/testscrollta.rb +0 -80
  39. data/examples/deprecated/testscrolltable.rb +0 -165
  40. data/examples/deprecated/testsplit.rb +0 -87
  41. data/examples/deprecated/testsplit2.rb +0 -123
  42. data/examples/deprecated/testsplit3.rb +0 -215
  43. data/examples/deprecated/testsplit3_1.rb +0 -244
  44. data/examples/deprecated/testsplit3a.rb +0 -215
  45. data/examples/deprecated/testsplit3b.rb +0 -237
  46. data/examples/deprecated/testsplitta.rb +0 -148
  47. data/examples/deprecated/testsplittv.rb +0 -142
  48. data/examples/deprecated/testsplittvv.rb +0 -144
  49. data/examples/deprecated/testtpane.rb +0 -215
  50. data/examples/deprecated/testtpane2.rb +0 -145
  51. data/examples/deprecated/testtpanetable.rb +0 -203
  52. data/examples/dirtree.rb +0 -88
  53. data/examples/experimental/resultsetdemo.rb +0 -280
  54. data/examples/experimental/testmform.rb +0 -35
  55. data/examples/experimental/testscroller.rb +0 -117
  56. data/examples/experimental/teststackflow.rb +0 -111
  57. data/examples/menu1.rb +0 -112
  58. data/examples/multispl.rb +0 -86
  59. data/examples/newmessagebox.rb +0 -130
  60. data/examples/newtabbedwindow.rb +0 -100
  61. data/examples/newtesttabp.rb +0 -121
  62. data/examples/qdfilechooser.rb +0 -68
  63. data/examples/rfe.rb +0 -1195
  64. data/examples/rfe_renderer.rb +0 -121
  65. data/examples/sqlc.rb +0 -454
  66. data/examples/sqlm.rb +0 -437
  67. data/examples/sqlt.rb +0 -408
  68. data/examples/status.txt +0 -68
  69. data/examples/table1.rb +0 -24
  70. data/examples/term2.rb +0 -84
  71. data/examples/test1.rb +0 -239
  72. data/examples/test2.rb +0 -674
  73. data/examples/testapp.rb +0 -44
  74. data/examples/testapp2.rb +0 -58
  75. data/examples/testchars.rb +0 -137
  76. data/examples/testcombo.rb +0 -91
  77. data/examples/testkeypress.rb +0 -66
  78. data/examples/testlistbox.rb +0 -113
  79. data/examples/testmenu.rb +0 -101
  80. data/examples/testmulticomp.rb +0 -70
  81. data/examples/testmulticontainer.rb +0 -94
  82. data/examples/testmultispl.rb +0 -199
  83. data/examples/testree.rb +0 -106
  84. data/examples/testtable.rb +0 -263
  85. data/examples/testtabp.rb +0 -107
  86. data/examples/testtodo.rb +0 -584
  87. data/examples/testvimsplit.rb +0 -112
  88. data/examples/testwsshortcuts.rb +0 -64
  89. data/examples/testwsshortcuts2.rb +0 -126
  90. data/examples/todo.db +0 -0
  91. data/examples/todo.yml +0 -191
  92. data/examples/viewtodo.rb +0 -574
  93. data/lib/rbcurse/action.rb +0 -40
  94. data/lib/rbcurse/app.rb +0 -1374
  95. data/lib/rbcurse/applicationheader.rb +0 -102
  96. data/lib/rbcurse/celleditor.rb +0 -112
  97. data/lib/rbcurse/checkboxcellrenderer.rb +0 -57
  98. data/lib/rbcurse/colormap.rb +0 -159
  99. data/lib/rbcurse/comboboxcellrenderer.rb +0 -30
  100. data/lib/rbcurse/common/ansiparser.rb +0 -117
  101. data/lib/rbcurse/common/appmethods.rb +0 -112
  102. data/lib/rbcurse/common/basestack.rb +0 -407
  103. data/lib/rbcurse/common/bordertitle.rb +0 -41
  104. data/lib/rbcurse/common/chunk.rb +0 -177
  105. data/lib/rbcurse/common/colorparser.rb +0 -71
  106. data/lib/rbcurse/common/keydefs.rb +0 -30
  107. data/lib/rbcurse/common/widgetshortcuts.rb +0 -302
  108. data/lib/rbcurse/defaultlistselectionmodel.rb +0 -79
  109. data/lib/rbcurse/deprecated/README.markdown +0 -12
  110. data/lib/rbcurse/deprecated/rscrollpane.rb +0 -512
  111. data/lib/rbcurse/deprecated/rsplitpane.rb +0 -894
  112. data/lib/rbcurse/deprecated/rsplitpane2.rb +0 -1009
  113. data/lib/rbcurse/deprecated/rviewport.rb +0 -204
  114. data/lib/rbcurse/experimental/README.markdown +0 -14
  115. data/lib/rbcurse/experimental/resultsettextview.rb +0 -585
  116. data/lib/rbcurse/experimental/stackflow.rb +0 -478
  117. data/lib/rbcurse/extras/bottomline.rb +0 -1850
  118. data/lib/rbcurse/extras/box.rb +0 -58
  119. data/lib/rbcurse/extras/directorylist.rb +0 -467
  120. data/lib/rbcurse/extras/directorytree.rb +0 -69
  121. data/lib/rbcurse/extras/divider.rb +0 -310
  122. data/lib/rbcurse/extras/focusmanager.rb +0 -31
  123. data/lib/rbcurse/extras/horizlist.rb +0 -203
  124. data/lib/rbcurse/extras/listselectable.rb +0 -264
  125. data/lib/rbcurse/extras/masterdetail.rb +0 -166
  126. data/lib/rbcurse/extras/menutree.rb +0 -63
  127. data/lib/rbcurse/extras/multiform.rb +0 -330
  128. data/lib/rbcurse/extras/multilinelabel.rb +0 -142
  129. data/lib/rbcurse/extras/newmessagebox.rb +0 -328
  130. data/lib/rbcurse/extras/newtabbedpane.rb +0 -612
  131. data/lib/rbcurse/extras/newtabbedwindow.rb +0 -68
  132. data/lib/rbcurse/extras/padreader.rb +0 -189
  133. data/lib/rbcurse/extras/rcomboedit.rb +0 -256
  134. data/lib/rbcurse/extras/resultsetbrowser.rb +0 -281
  135. data/lib/rbcurse/extras/rlink.rb +0 -27
  136. data/lib/rbcurse/extras/rmenulink.rb +0 -21
  137. data/lib/rbcurse/extras/scrollbar.rb +0 -143
  138. data/lib/rbcurse/extras/statusline.rb +0 -94
  139. data/lib/rbcurse/extras/stdscrwindow.rb +0 -309
  140. data/lib/rbcurse/extras/tableextended.rb +0 -40
  141. data/lib/rbcurse/extras/tabular.rb +0 -264
  142. data/lib/rbcurse/extras/tabularwidget.rb +0 -1150
  143. data/lib/rbcurse/extras/textpad.rb +0 -516
  144. data/lib/rbcurse/extras/viewer.rb +0 -136
  145. data/lib/rbcurse/io.rb +0 -850
  146. data/lib/rbcurse/keylabelprinter.rb +0 -178
  147. data/lib/rbcurse/listcellrenderer.rb +0 -140
  148. data/lib/rbcurse/listeditable.rb +0 -310
  149. data/lib/rbcurse/listkeys.rb +0 -37
  150. data/lib/rbcurse/listscrollable.rb +0 -564
  151. data/lib/rbcurse/listselectable.rb +0 -142
  152. data/lib/rbcurse/mapper.rb +0 -130
  153. data/lib/rbcurse/orderedhash.rb +0 -77
  154. data/lib/rbcurse/ractionevent.rb +0 -67
  155. data/lib/rbcurse/rbasiclistbox.rb +0 -768
  156. data/lib/rbcurse/rchangeevent.rb +0 -27
  157. data/lib/rbcurse/rcombo.rb +0 -238
  158. data/lib/rbcurse/rcommandwindow.rb +0 -587
  159. data/lib/rbcurse/rcontainer.rb +0 -415
  160. data/lib/rbcurse/rdialogs.rb +0 -451
  161. data/lib/rbcurse/rinputdataevent.rb +0 -47
  162. data/lib/rbcurse/rlistbox.rb +0 -1196
  163. data/lib/rbcurse/rmenu.rb +0 -939
  164. data/lib/rbcurse/rmessagebox.rb +0 -348
  165. data/lib/rbcurse/rmulticontainer.rb +0 -304
  166. data/lib/rbcurse/rmultisplit.rb +0 -722
  167. data/lib/rbcurse/rmultitextview.rb +0 -306
  168. data/lib/rbcurse/rpopupmenu.rb +0 -755
  169. data/lib/rbcurse/rprogress.rb +0 -118
  170. data/lib/rbcurse/rscrollform.rb +0 -418
  171. data/lib/rbcurse/rtabbedpane.rb +0 -1158
  172. data/lib/rbcurse/rtabbedwindow.rb +0 -167
  173. data/lib/rbcurse/rtable.rb +0 -1718
  174. data/lib/rbcurse/rtextarea.rb +0 -920
  175. data/lib/rbcurse/rtextview.rb +0 -761
  176. data/lib/rbcurse/rtree.rb +0 -780
  177. data/lib/rbcurse/rvimsplit.rb +0 -763
  178. data/lib/rbcurse/rwidget.rb +0 -2915
  179. data/lib/rbcurse/scrollable.rb +0 -301
  180. data/lib/rbcurse/table/tablecellrenderer.rb +0 -86
  181. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -98
  182. data/lib/rbcurse/tree/treecellrenderer.rb +0 -150
  183. data/lib/rbcurse/tree/treemodel.rb +0 -428
  184. data/lib/rbcurse/undomanager.rb +0 -188
  185. data/lib/rbcurse/vieditable.rb +0 -144
  186. data/lib/ver/keyboard.rb +0 -150
  187. data/lib/ver/keyboard2.rb +0 -170
  188. data/lib/ver/ncurses.rb +0 -218
  189. data/lib/ver/panel.rb +0 -162
  190. data/lib/ver/rpad.rb +0 -375
  191. data/lib/ver/window.rb +0 -882
  192. data/test/test_rbcurse.rb +0 -0
@@ -1,94 +0,0 @@
1
- require 'rbcurse'
2
-
3
- module RubyCurses
4
-
5
- #
6
- # A vim-like application status bar that can display time and various other statuses
7
- # at the bottom, typically above the dock (3rd line from last).
8
- #
9
- class StatusLine < Widget
10
-
11
- def initialize form, config={}, &block
12
- if form.window.height == 0
13
- @row = Ncurses.LINES-3 # fix, what about smaller windows, use window dimensions and watch out for 0,0
14
- else
15
- @row = form.window.height-3 # fix, what about smaller windows, use window dimensions and watch out for 0,0
16
- end
17
- # in root windows FIXME
18
- @col = 0
19
- super
20
- @focusable = false
21
- @editable = false
22
- @command = nil
23
- @repaint_required = true
24
- bind(:PROPERTY_CHANGE) { |e| @color_pair = nil ; }
25
- end
26
- #
27
- # command that returns a string that populates the status line (left aligned)
28
- # @see :right
29
- # See dbdemo.rb
30
- # e.g.
31
- # @l.command { "%-20s [DB: %-s | %-s ]" % [ Time.now, $current_db || "None", $current_table || "----"] }
32
- #
33
- def command *args, &blk
34
- @command = blk
35
- @args = args
36
- end
37
- alias :left :command
38
-
39
- #
40
- # Procudure for text to be right aligned in statusline
41
- def right *args, &blk
42
- @right_text = blk
43
- @right_args = args
44
- end
45
-
46
- # NOTE: I have not put a check of repaint_required, so this will print on each key-stroke OR
47
- # rather whenever form.repaint is called.
48
- def repaint
49
- @color_pair ||= get_color($datacolor, @color, @bgcolor)
50
- len = @form.window.width
51
- len = Ncurses.COLS if len == 0
52
-
53
- # first print dashes through
54
- @form.window.printstring @row, @col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE
55
-
56
- # now call the block to get current values
57
- if @command
58
- ftext = @command.call(self, @args)
59
- else
60
- status = $status_message ? $status_message.value : ""
61
- #ftext = " %-20s | %s" % [Time.now, status] # should we print a default value just in case user doesn't
62
- ftext = status # should we print a default value just in case user doesn't
63
- end
64
- if ftext =~ /#\[/
65
- @form.window.printstring_formatted @row, @col, ftext, $datacolor, Ncurses::A_REVERSE
66
- else
67
- @form.window.printstring @row, @col, ftext, $datacolor, Ncurses::A_REVERSE
68
- end
69
- # move this to formatted FIXME
70
- #@form.window.printstring_or_chunks @row, @col, ftext, $datacolor, Ncurses::A_REVERSE
71
-
72
- if @right_text
73
- ftext = @right_text.call(self, @right_args)
74
- if ftext =~ /#\[/
75
- @form.window.printstring_formatted_right @row, nil, ftext, $datacolor, Ncurses::A_REVERSE
76
- else
77
- c = len - ftext.length
78
- @form.window.printstring @row, c, ftext, $datacolor, Ncurses::A_REVERSE
79
- end
80
- else
81
- t = Time.now
82
- tt = t.strftime "%F %H:%M:%S"
83
- ftext = "#[fg=green,bg=blue] %-20s" % [tt] # print a default
84
- @form.window.printstring_formatted_right @row, nil, ftext, $datacolor, Ncurses::A_REVERSE
85
- end
86
-
87
- @repaint_required = false
88
- end
89
- def handle_keys ch
90
- return :UNHANDLED
91
- end
92
-
93
- end # class
94
- end # module
@@ -1,309 +0,0 @@
1
- require 'ver/ncurses'
2
- module RubyCurses
3
- #
4
- # an attempt to make a window based on stdscr for bottom line printing so the entire
5
- # application can have one pointer, regardless of whether through App
6
- # or otherwise. This still provides the full getchar operation, copied from
7
- # Window class which is the main purpose of this. So as to provide ask, agree and say.
8
- #
9
- # We should be able to pass this window to bottomline and have one global bottomline
10
- # created once (by window class ?)
11
- #
12
- # FFI: 2011-09-9 The change to FFI has affected this a lot since I do not get window
13
- # methods in rbcurse for stdscr whereas suprisingly if i run the samples, i get them
14
- # all.
15
- #
16
- # NOTE:
17
- # WARNING: Pls do not use this class. This was just experimentation. Using stdscr
18
- # mucks up the display and overwrites objects on the screen. I will remove this class
19
- # at some time.
20
- #
21
- class StdscrWindow
22
- attr_reader :width, :height, :top, :left
23
-
24
- def initialize
25
-
26
- #@window_pointer = FFI::NCurses.initscr
27
- @window_pointer = Ncurses.initscr # FFIWINDOW
28
- $log.debug "STDSCR window pointer is #{@window_pointer.class}"
29
- #$log.debug "STDSCR window pointer mehtods #{@window_pointer.public_methods}"
30
- $error_message_row ||= Ncurses.LINES-1
31
- $error_message_col ||= 1
32
- init_vars
33
-
34
-
35
- end
36
- def init_vars
37
- #Ncurses::keypad(@window_pointer, true)
38
- Ncurses.keypad(@window_pointer.pointer, true)
39
- @stack = []
40
- end
41
- ##
42
-
43
- # Ncurses
44
-
45
-
46
- # taken from Window
47
- def method_missing(name, *args)
48
- name = name.to_s
49
- if (name[0,2] == "mv")
50
- test_name = name.dup
51
- test_name[2,0] = "w" # insert "w" after"mv"
52
- if (@window_pointer.respond_to?(test_name)) # FFIPOINTER
53
- return @window_pointer.send(test_name,*args)
54
- end
55
-
56
- if (FFI::NCurses.respond_to?(test_name))
57
- return FFI::NCurses.send(test_name, @window_pointer, *args)
58
- end
59
- end
60
- test_name = "w" + name
61
- # FFI responds but the pointer does not !!! bottomline 1045
62
- if (@window_pointer.respond_to?(test_name)) # FFIPOINTER
63
- return @window_pointer.send(test_name,*args)
64
- end
65
- if (FFI::NCurses.respond_to?(test_name))
66
- return FFI::NCurses.send(test_name, @window_pointer, *args)
67
- end
68
- # what if it does not respond, can go into loop and give stack overflow
69
- FFI::NCurses.send(name, @window_pointer, *args)
70
- end
71
- def respond_to?(name)
72
- name = name.to_s
73
- if (name[0,2] == "mv" && FFI::NCurses.respond_to?("mvw" + name[2..-1]))
74
- return true
75
- end
76
- FFI::NCurses.respond_to?("w" + name) || FFI::NCurses.respond_to?(name)
77
- end
78
- #@window.send(meth, *args)
79
-
80
- # FFI WARNING XXX I think these methods one window_pointer will fail
81
- # since somehow stdscr is not getting these methods here.
82
- def print(string, width = width)
83
- return unless visible?
84
- @window_pointer.waddnstr(string.to_s, width)
85
- end
86
-
87
- def print_yx(string, y = 0, x = 0)
88
- @window_pointer.mvwaddnstr(y, x, string, width)
89
- end
90
-
91
- def print_empty_line
92
- return unless visible?
93
- @window_pointer.printw(' ' * width)
94
- end
95
-
96
- def print_line(string)
97
- print(string.ljust(width))
98
- end
99
-
100
- def puts(*strings)
101
- print(strings.join("\n") << "\n")
102
- end
103
-
104
- # FFI 2011-09-9 commented off so it goes to method missing
105
- def XXXrefresh
106
- @window_pointer.refresh
107
- end
108
-
109
-
110
- def color=(color)
111
- @color = color
112
- @window_pointer.color_set(color, nil)
113
- end
114
-
115
- def highlight_line(color, y, x, max)
116
- @window_pointer.mvchgat(y, x, max, FFI::NCurses::A_NORMAL, color, nil)
117
- end
118
-
119
- def ungetch(ch)
120
- FFI::NCurses.ungetch(ch)
121
- end
122
-
123
- # this used to work fine in ncursesruby
124
- # but somehow in ffi, stdscr does not have most methods, i am unable to figure
125
- # this out. C-c will crash this.
126
- def getch
127
- c = @window_pointer.getch # FFI NW stdscr must get key not some window
128
- #raise "Ncurses.stdscr does not have getch" if !Ncurses.stdscr.respond_to? :getch
129
- #$log.debug " XXXX before calling getch"
130
- #c = Ncurses.stdscr.getch # FFIW if you use the FFIWINDOW
131
- #c = FFI::NCurses.getch # FFI 2011-09-9 # without FFIWINDOW
132
- #$log.debug " XXXX after calling getch #{c}"
133
- #if c == FFI::NCurses::KEY_RESIZE
134
- return c
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
- FFI::NCurses.raw # FFI required so that getch does not crash on C-c
145
- while 1
146
- ch = getch
147
- #$log.debug "window getchar() GOT: #{ch}" if ch != -1
148
- if ch == -1
149
- # the returns escape 27 if no key followed it, so its SLOW if you want only esc
150
- if @stack.first == 27
151
- #$log.debug " -1 stack sizze #{@stack.size}: #{@stack.inspect}, ch #{ch}"
152
- case @stack.size
153
- when 1
154
- @stack.clear
155
- return 27
156
- when 2 # basically a ALT-O, this will be really slow since it waits for -1
157
- ch = 128 + @stack.last
158
- @stack.clear
159
- return ch
160
- when 3
161
- $log.debug " SHOULD NOT COME HERE getchar()"
162
- end
163
- end
164
- @stack.clear
165
- next
166
- end
167
- # this is the ALT combination
168
- if @stack.first == 27
169
- # experimental. 2 escapes in quick succession to make exit faster
170
- if ch == 27
171
- @stack.clear
172
- return ch
173
- end
174
- # possible F1..F3 on xterm-color
175
- if ch == 79 or ch == 91
176
- #$log.debug " got 27, #{ch}, waiting for one more"
177
- @stack << ch
178
- next
179
- end
180
- #$log.debug "stack SIZE #{@stack.size}, #{@stack.inspect}, ch: #{ch}"
181
- if @stack == [27,79]
182
- # xterm-color
183
- case ch
184
- when 80
185
- ch = KEY_F1
186
- when 81
187
- ch = KEY_F2
188
- when 82
189
- ch = KEY_F3
190
- when 83
191
- ch = KEY_F4
192
- end
193
- @stack.clear
194
- return ch
195
- elsif @stack == [27, 91]
196
- if ch == 90
197
- @stack.clear
198
- return KEY_BTAB # backtab
199
- end
200
- end
201
- # the usual Meta combos. (alt)
202
- ch = 128 + ch
203
- @stack.clear
204
- return ch
205
- end
206
- # append a 27 to stack, actually one can use a flag too
207
- if ch == 27
208
- @stack << 27
209
- next
210
- end
211
- return ch
212
- end
213
- end
214
-
215
- def clear
216
- # return unless visible?
217
- move 0, 0
218
- puts *Array.new(height){ ' ' * (width - 1) }
219
- end
220
-
221
-
222
- def visible?
223
- @visible
224
- end
225
- ##
226
- # added by rk 2008-11-29 19:01
227
- # I usually use this, not the others ones here
228
- # @param r - row
229
- # @param c - col
230
- # @param string - text to print
231
- # @param color - color pair
232
- # @ param att - ncurses attribute: normal, bold, reverse, blink,
233
- # underline
234
- def printstring(r,c,string, color, att = FFI::NCurses::A_NORMAL)
235
- prv_printstring(r,c,string, color, att )
236
- end
237
-
238
- ## name changed from printstring to prv_prinstring
239
- def prv_printstring(r,c,string, color, att = FFI::NCurses::A_NORMAL)
240
-
241
- #$log.debug " #{@name} inside window printstring r #{r} c #{c} #{string} "
242
- att = FFI::NCurses::A_NORMAL if att.nil?
243
- case att.to_s.downcase
244
- when 'normal'
245
- att = FFI::NCurses::A_NORMAL
246
- when 'underline'
247
- att = FFI::NCurses::A_UNDERLINE
248
- when 'bold'
249
- att = FFI::NCurses::A_BOLD
250
- when 'blink'
251
- att = FFI::NCurses::A_BLINK # unlikely to work
252
- when 'reverse'
253
- att = FFI::NCurses::A_REVERSE
254
- end
255
-
256
- attron(Ncurses.COLOR_PAIR(color) | att)
257
- # we should not print beyond window coordinates
258
- # trying out on 2009-01-03 19:29
259
- width = Ncurses.COLS
260
- # the next line won't ensure we don't write outside some bounds like table
261
- #string = string[0..(width-c)] if c + string.length > width
262
- #$log.debug "PRINT len:#{string.length}, #{Ncurses.COLS}, #{r}, #{c} w: #{@window} "
263
- mvprintw(r, c, "%s", string);
264
- attroff(Ncurses.COLOR_PAIR(color) | att)
265
- end
266
- # added by rk 2008-11-29 19:01
267
- # Since these methods write directly to window they are not advised
268
- # since clearing previous message we don't know how much to clear.
269
- # Best to map error_message to a label.
270
- # 2010-09-13 00:22 WE should not use these any longer.
271
- # Application should create a label and map a Variable named
272
- # $errormessage to it. We should only update the Variable
273
- # CLEANUP DEPRECATED
274
- def print_error_message text=$error_message
275
- raise "DEPRECATED CLEANUP use global method of same name"
276
- r = $error_message_row || Ncurses.LINES-1
277
- c = $error_message_col || (Ncurses.COLS-text.length)/2
278
-
279
- $log.debug "got ERROR MESSAGE #{text} row #{r} "
280
- clear_error r, $datacolor
281
- printstring r, c, text, color = $promptcolor
282
- $error_message_clear_pending = true
283
- end
284
- # added by rk 2008-11-29 19:01
285
- # CLEANUP DEPRECATED
286
- def print_status_message text=$status_message
287
- raise "DEPRECATED CLEANUP use global method of same name"
288
- r = $status_message_row || Ncurses.LINES-1
289
- clear_error r, $datacolor
290
- # print it in centre
291
- printstring r, (Ncurses.COLS-text.length)/2, text, color = $promptcolor
292
- end
293
- # Clear error message printed
294
- # I am not only clearing if something was printed. This is since
295
- # certain small forms like TabbedForm top form throw an error on printstring.
296
- #
297
- #raise "DEPRECATED CLEANUP use global method of same name"
298
- def clear_error r = $error_message_row, color = $datacolor
299
- return unless $error_message_clear_pending
300
- c = $error_message_col || (Ncurses.COLS-text.length)/2
301
- sz = $error_message_size || Ncurses.COLS
302
- printstring(r, c, "%-*s" % [sz, " "], color)
303
- $error_message_clear_pending = false
304
- end
305
- ##
306
- def get_window; @window_pointer; end
307
- def to_s; @name || self; end
308
- end
309
- end
@@ -1,40 +0,0 @@
1
- # Provides extended abilities to a table
2
- # so user does not need to code it into his app.
3
- # At the same time, i don't want to weigh down Table with too much functionality/
4
- # I am putting in some stuff, so that table columns can be resized, using multipliers.
5
- # That allows us to redistribute the space taken or released across rows.
6
- # Other options: dd, C, . (repeat) and how about range operations
7
- #
8
- module TableExtended
9
-
10
- ##
11
- # increase the focused column
12
- # If no size passed, then use numeric multiplier, else 1
13
- # Typically, one would bind a key such as + to this method
14
- # e.g. atable.bind_key(?+) { atable.increase_column ; }
15
- # See examples/viewtodo.rb for usage
16
- def increase_column num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
17
-
18
- acolumn = column focussed_col()
19
- #num = $multiplier || 1
20
- $multiplier = 0
21
- w = acolumn.width + num
22
- acolumn.width w
23
- #atable.table_structure_changed
24
- end
25
- # decrease the focused column
26
- # If no size passed, then use numeric multiplier, else 1
27
- # Typically, one would bind a key such as - to this method
28
- def decrease_column num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
29
- acolumn = column focussed_col()
30
- w = acolumn.width - num
31
- $multiplier = 0
32
- if w > 3
33
- acolumn.width w
34
- #atable.table_structure_changed
35
- end
36
- end
37
-
38
-
39
-
40
- end
@@ -1,264 +0,0 @@
1
- #!/usr/bin/env ruby -w
2
- =begin
3
- * Name : A Quick take on tabular data. Readonly.
4
- * Description : To show tabular data inside a control, rather than going by the huge
5
- Table object, I want to create a simple, minimal table data generator.
6
- This will be thrown into a TextView for the user to navigate, select
7
- etc.
8
- I would use this applications where the tabular data is fairly fixed
9
- not where i want the user to select columns, move them, expand etc.
10
- * :
11
- * Author : rkumar
12
- * Date :
13
- * License :
14
- Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
15
-
16
- =end
17
-
18
- #
19
- # A simple tabular data generator. Given table data in arrays and a column heading row in arrays, it
20
- # quickely generates tabular data. It only takes left and right alignment of columns into account.
21
- # You may specify individual column widths. Else it will take the widths of the column names you supply
22
- # in the startup array. You are encouraged to supply column widths.
23
- # If no columns are specified, and no widths are given, it take the widths of the first row
24
- # as a model to determine column widths.
25
- #
26
- module RubyCurses
27
-
28
- class Tabular
29
- GUESSCOLUMNS = 20
30
-
31
- def yield_or_eval &block
32
- return unless block
33
- if block.arity > 0
34
- yield self
35
- else
36
- self.instance_eval(&block)
37
- end
38
- end
39
- # stores column info internally
40
- class ColumnInfo < Struct.new(:name, :w, :align)
41
- end
42
- # an array of column titles
43
- attr_reader :columns
44
- # boolean, does user want lines numbered
45
- attr_accessor :numbering
46
- # x is the + character used a field delim in separators
47
- # y is the field delim used in data rows, default is pipe or bar
48
- attr_accessor :x, :y
49
-
50
- # takes first optional argument as array of column names
51
- # second optional argument as array of data arrays
52
- # @yield self
53
- #
54
- def initialize cols=nil, *args, &block
55
- @chash = {}
56
- @cw = {}
57
- @calign = {}
58
- @separ = @columns = @numbering = nil
59
- @y = '|'
60
- @x = '+'
61
- self.columns = cols if cols
62
- if !args.empty?
63
- puts "ARGS after shift #{args} "
64
- if !args.empty?
65
- self.data = args
66
- end
67
- end
68
- yield_or_eval(&block) if block_given?
69
- end
70
- #
71
- # set columns names
72
- # @param [Array<String>] column names, preferably padded out to width for column
73
- def columns=(array)
74
- $log.debug "tabular got columns #{array.count} #{array.inspect} " if $log
75
- @columns = array
76
- @columns.each_with_index { |c,i|
77
- @chash[i] = ColumnInfo.new(c, c.to_s.length)
78
- @cw[i] ||= c.to_s.length
79
- #@calign[i] ||= :left # 2011-09-27 prevent setting later on
80
- }
81
- end
82
- alias :headings= :columns=
83
- #
84
- # set data as an array of arrays
85
- # @param [Array<Array>] data as array of arrays
86
- def data=(list)
87
- puts "got data: #{list.size} " if !$log
88
- puts list if !$log
89
- @list = list
90
- end
91
-
92
- # add a row of data
93
- # @param [Array] an array containing entries for each column
94
- def add array
95
- $log.debug "tabular got add #{array.count} #{array.inspect} " if $log
96
- @list ||= []
97
- @list << array
98
- end
99
- alias :<< :add
100
- alias :add_row :add
101
-
102
- # set width of a given column
103
- # @param [Number] column offset, starting 0
104
- # @param [Number] width
105
- def column_width colindex, width
106
- @cw[colindex] ||= width
107
- if @chash[colindex].nil?
108
- @chash[colindex] = ColumnInfo.new("", width)
109
- else
110
- @chash[colindex].w = width
111
- end
112
- @chash
113
- end
114
-
115
- # set alignment of given column offset
116
- # @param [Number] column offset, starting 0
117
- # @param [Symbol] :left, :right
118
- def align_column colindex, lrc
119
- raise ArgumentError, "wrong alignment value sent" if ![:right, :left, :center].include? lrc
120
- @calign[colindex] ||= lrc
121
- if @chash[colindex].nil?
122
- @chash[colindex] = ColumnInfo.new("", nil, lrc)
123
- else
124
- @chash[colindex].align = lrc
125
- end
126
- @chash
127
- end
128
-
129
- #
130
- # Now returns an array with formatted data
131
- # @return [Array<String>] array of formatted data
132
- def render
133
- buffer = []
134
- _guess_col_widths
135
- rows = @list.size.to_s.length
136
- @rows = rows
137
- _prepare_format
138
-
139
- str = ""
140
- if @numbering
141
- str = " "*(rows+1)+@y
142
- end
143
- str << @fmstr % @columns
144
- buffer << str
145
- #puts "-" * str.length
146
- buffer << separator
147
- if @list
148
- if @numbering
149
- @fmstr = "%#{rows}d "+ @y + @fmstr
150
- end
151
- #@list.each { |e| puts e.join(@y) }
152
- count = 0
153
- @list.each_with_index { |r,i|
154
- value = convert_value_to_text r, count
155
- buffer << value
156
- count += 1
157
- }
158
- end
159
- buffer
160
- end
161
- def convert_value_to_text r, count
162
- if r == :separator
163
- return separator
164
- end
165
- if @numbering
166
- r.insert 0, count+1
167
- end
168
- return @fmstr % r;
169
- end
170
- # use this for printing out on terminal
171
- # @example
172
- # puts t.to_s
173
- def to_s
174
- render().join "\n"
175
- end
176
- def add_separator
177
- @list << :separator
178
- end
179
- def separator
180
- return @separ if @separ
181
- str = ""
182
- if @numbering
183
- str = "-"*(@rows+1)+@x
184
- end
185
- @cw.each_pair { |k,v| str << "-" * (v+1) + @x }
186
- @separ = str.chop
187
- end
188
- private
189
- def _guess_col_widths #:nodoc:
190
- @list.each_with_index { |r, i|
191
- break if i > GUESSCOLUMNS
192
- next if r == :separator
193
- r.each_with_index { |c, j|
194
- x = c.to_s.length
195
- if @cw[j].nil?
196
- @cw[j] = x
197
- else
198
- @cw[j] = x if x > @cw[j]
199
- end
200
- }
201
- }
202
- end
203
- def _prepare_format #:nodoc:
204
- @fmtstr = nil
205
- fmt = []
206
- @cw.each_with_index { |c, i|
207
- w = @cw[i]
208
- case @calign[i]
209
- when :right
210
- fmt << "%#{w}s "
211
- else
212
- fmt << "%-#{w}s "
213
- end
214
- }
215
- @fmstr = fmt.join(@y)
216
- puts "format: #{@fmstr} "
217
- end
218
- end
219
- end
220
-
221
- if __FILE__ == $PROGRAM_NAME
222
- include RubyCurses
223
- $log = nil
224
- t = Tabular.new(['a', 'b'], [1, 2], [3, 4])
225
- puts t.to_s
226
- puts
227
- t = Tabular.new([" Name ", " Number ", " Email "])
228
- t.add %w{ rahul 32 r@ruby.org }
229
- t << %w{ _why 133 j@gnu.org }
230
- t << %w{ Jane 1331 jane@gnu.org }
231
- t.column_width 1, 10
232
- t.align_column 1, :right
233
- puts t.to_s
234
- puts
235
-
236
- s = Tabular.new do |b|
237
- b.columns = %w{ country continent text }
238
- b << ["india","asia","a warm country" ]
239
- b << ["japan","asia","a cool country" ]
240
- b << ["russia","europe","a hot country" ]
241
- b.column_width 2, 30
242
- end
243
- puts s.to_s
244
- puts
245
- puts "::::"
246
- puts
247
- s = Tabular.new do |b|
248
- b.columns = %w{ place continent text }
249
- b << ["india","asia","a warm country" ]
250
- b << ["japan","asia","a cool country" ]
251
- b << ["russia","europe","a hot country" ]
252
- b << ["sydney","australia","a dry country" ]
253
- b << ["canberra","australia","a dry country" ]
254
- b << ["ross island","antarctica","a dry country" ]
255
- b << ["mount terror","antarctica","a windy country" ]
256
- b << ["mt erebus","antarctica","a cold place" ]
257
- b << ["siberia","russia","an icy city" ]
258
- b << ["new york","USA","a fun place" ]
259
- b.column_width 0, 12
260
- b.column_width 1, 12
261
- b.numbering = true
262
- end
263
- puts s.to_s
264
- end