rbcurse 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/CHANGELOG +33 -0
  2. data/README.markdown +7 -1
  3. data/TODO2.txt +21 -15
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +2 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +0 -1
  8. data/examples/appdirtree.rb +4 -2
  9. data/examples/appemail.rb +7 -3
  10. data/examples/appemaillb.rb +1 -1
  11. data/examples/appgcompose.rb +2 -2
  12. data/examples/appgmail.rb +1 -1
  13. data/examples/appmethods.rb +20 -2
  14. data/examples/atree.rb +9 -1
  15. data/examples/dbdemo.rb +460 -0
  16. data/examples/dirtree.rb +1 -1
  17. data/examples/menu1.rb +37 -5
  18. data/examples/multispl.rb +1 -1
  19. data/examples/rfe.rb +9 -2
  20. data/examples/splitp.rb +1 -1
  21. data/examples/sqlc.rb +6 -10
  22. data/examples/sqlm.rb +2 -20
  23. data/examples/sqlt.rb +408 -0
  24. data/examples/term2.rb +1 -1
  25. data/examples/test2.rb +169 -97
  26. data/examples/testapp.rb +1 -1
  27. data/examples/testapp2.rb +1 -1
  28. data/examples/testkeypress.rb +4 -2
  29. data/examples/testtable.rb +6 -0
  30. data/examples/testtpane.rb +35 -23
  31. data/examples/testvimsplit.rb +3 -2
  32. data/lib/rbcurse.rb +1 -1
  33. data/lib/rbcurse/action.rb +8 -0
  34. data/lib/rbcurse/app.rb +39 -23
  35. data/lib/rbcurse/extras/bottomline.rb +101 -13
  36. data/lib/rbcurse/extras/directorylist.rb +14 -5
  37. data/lib/rbcurse/extras/divider.rb +1 -1
  38. data/lib/rbcurse/extras/listselectable.rb +42 -8
  39. data/lib/rbcurse/extras/masterdetail.rb +2 -2
  40. data/lib/rbcurse/extras/scrollbar.rb +11 -2
  41. data/lib/rbcurse/extras/statusline.rb +56 -0
  42. data/lib/rbcurse/extras/stdscrwindow.rb +11 -0
  43. data/lib/rbcurse/extras/tabular.rb +2 -1
  44. data/lib/rbcurse/extras/tabularwidget.rb +60 -17
  45. data/lib/rbcurse/extras/viewer.rb +16 -4
  46. data/lib/rbcurse/keylabelprinter.rb +34 -4
  47. data/lib/rbcurse/listeditable.rb +5 -1
  48. data/lib/rbcurse/listkeys.rb +1 -1
  49. data/lib/rbcurse/listscrollable.rb +15 -8
  50. data/lib/rbcurse/rbasiclistbox.rb +44 -23
  51. data/lib/rbcurse/rcommandwindow.rb +8 -14
  52. data/lib/rbcurse/rdialogs.rb +187 -2
  53. data/lib/rbcurse/rlistbox.rb +38 -19
  54. data/lib/rbcurse/rmenu.rb +313 -93
  55. data/lib/rbcurse/rmessagebox.rb +3 -2
  56. data/lib/rbcurse/rmulticontainer.rb +5 -3
  57. data/lib/rbcurse/rmultisplit.rb +2 -11
  58. data/lib/rbcurse/rmultitextview.rb +4 -5
  59. data/lib/rbcurse/rtabbedpane.rb +223 -69
  60. data/lib/rbcurse/rtable.rb +6 -10
  61. data/lib/rbcurse/rtextarea.rb +57 -36
  62. data/lib/rbcurse/rtextview.rb +12 -15
  63. data/lib/rbcurse/rtree.rb +79 -22
  64. data/lib/rbcurse/rvimsplit.rb +16 -25
  65. data/lib/rbcurse/rwidget.rb +376 -523
  66. data/lib/rbcurse/tree/treecellrenderer.rb +24 -11
  67. data/lib/rbcurse/tree/treemodel.rb +1 -1
  68. data/lib/ver/window.rb +130 -66
  69. metadata +5 -3
  70. data/examples/term.rb +0 -48
@@ -20,11 +20,14 @@ module RubyCurses
20
20
  dsl_accessor :color, :bgcolor
21
21
  dsl_accessor :row, :col
22
22
  dsl_accessor :parent #usuall the table to get colors and other default info
23
+ attr_reader :actual_length
24
+ attr_accessor :pcol
23
25
 
24
26
  def initialize text="", config={}, &block
25
27
  @text = text
26
28
  @editable = false
27
29
  @focusable = false
30
+ @actual_length = 0
28
31
  config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
29
32
  instance_eval &block if block_given?
30
33
  init_vars
@@ -86,17 +89,6 @@ module RubyCurses
86
89
  prepare_default_colors focussed, selected
87
90
 
88
91
  value=value.to_s # ??
89
- if @height && @height > 1
90
- else
91
- # ensure we do not exceed
92
- if !@display_length.nil?
93
- if value.length > @display_length
94
- value = value[0..@display_length-1]
95
- end
96
- end
97
- #lablist << value
98
- end
99
- len = @display_length || value.length
100
92
  #icon = object.is_leaf? ? "-" : "+"
101
93
  #icon = leaf ? "-" : "+"
102
94
 
@@ -116,7 +108,28 @@ module RubyCurses
116
108
  end
117
109
  end
118
110
  # adding 2 to level, that's the size of icon
111
+ # XXX FIXME if we put the icon here, then when we scroll right, the icon will show, it shoud not
112
+ # FIXME we ignore truncation etc on previous level and take the object as is !!!
119
113
  _value = "%*s %s" % [ level+2, icon, node.user_object ]
114
+ @actual_length = _value.length
115
+ pcol = @pcol
116
+ if pcol > 0
117
+ _len = @display_length || @parent.width-2
118
+ _value = _value[@pcol..@pcol+_len-1]
119
+ end
120
+ _value ||= ""
121
+ if @height && @height > 1
122
+ else
123
+ # ensure we do not exceed
124
+ if !@display_length.nil?
125
+ if _value.length > @display_length
126
+ @actual_length = _value.length
127
+ _value = _value[0..@display_length-1]
128
+ end
129
+ end
130
+ #lablist << value
131
+ end
132
+ len = @display_length || _value.length
120
133
  graphic.printstring r, c, "%-*s" % [len, _value], @color_pair,@attr
121
134
  #_height = @height || 1
122
135
  #0.upto(_height-1) { |i|
@@ -147,7 +147,7 @@ module RubyCurses
147
147
  end
148
148
  ##
149
149
  # added 2009-01-17 21:36
150
- # Use with caution, does not call events per row
150
+ # Use with caution, does not call events per row
151
151
  def delete_all
152
152
  raise "not yet used"
153
153
  len = @data.length-1
data/lib/ver/window.rb CHANGED
@@ -3,23 +3,36 @@ require 'ver/panel'
3
3
  module VER
4
4
  class Window
5
5
  attr_reader :width, :height, :top, :left
6
- attr_accessor :layout
6
+ attr_accessor :layout # hash containing hwtl
7
7
  attr_reader :panel # reader requires so he can del it in end
8
8
  attr_reader :window_type # window or pad to distinguish 2009-11-02 23:11
9
9
  attr_accessor :name # more for debugging log files. 2010-02-02 19:58
10
10
  attr_accessor :modified # has it been modified and may need a refresh
11
11
  attr_reader :bottomline # experimental here 2010-11-03 22:19
12
12
 
13
- def initialize(layout)
13
+ # @param [Array, Hash] window coordinates (ht, w, top, left)
14
+ # or
15
+ # @param [int, int, int, int] window coordinates (ht, w, top, left)
16
+ # 2011-09-21 allowing array, or 4 ints, in addition to hash @since 1.3.1
17
+ def initialize(*args)
18
+
19
+ case args.size
20
+ when 1
21
+ case args[0]
22
+ when Array, Hash
23
+ layout = args[0]
24
+ else
25
+ raise ArgumentError, "Window expects 4 ints, array of 4 ints, or Hash in constructor"
26
+ end
27
+ when 4
28
+ layout = { :height => args[0], :width => args[1], :top => args[2], :left => args[3] }
29
+ end
30
+
14
31
  @visible = true
15
32
  reset_layout(layout)
16
33
 
17
- #@window = Ncurses::WINDOW.new(height, width, top, left)
18
- #@window = Ncurses.newwin(height, width, top, left) # added FFI 2011-09-6
19
- @window = FFI::NCurses.newwin(height, width, top, left) # added FFI 2011-09-6
20
- #@panel = Ncurses::Panel.new_panel(@window)
34
+ @window = FFI::NCurses.newwin(@height, @width, @top, @left) # added FFI 2011-09-6
21
35
  @panel = Ncurses::Panel.new(@window) # added FFI 2011-09-6
22
- ## eeks XXX next line will wreak havoc when multiple windows opened like a mb or popup
23
36
  #$error_message_row = $status_message_row = Ncurses.LINES-1
24
37
  $error_message_row ||= Ncurses.LINES-1
25
38
  $error_message_col ||= 1 # ask (bottomline) uses 0 as default so you can have mismatch. XXX
@@ -34,7 +47,7 @@ module VER
34
47
  @name ||="#{self}"
35
48
  @modified = true
36
49
  $catch_alt_digits ||= false # is this where is should put globals ? 2010-03-14 14:00 XXX
37
- init_bottomline
50
+ #init_bottomline # bottomline to creates its own window 2011-10-8
38
51
  end
39
52
  ##
40
53
  # this is an alternative constructor
@@ -51,6 +64,7 @@ module VER
51
64
  # not used as yet
52
65
  # this is an alternative constructor
53
66
  # created if you don't want to create a hash first
67
+ # 2011-09-21 V1.3.1 You can now send an array to Window constructor
54
68
  def self.create_window(h=0, w=0, t=0, l=0)
55
69
  layout = { :height => h, :width => w, :top => t, :left => l }
56
70
  @window = Window.new(layout)
@@ -175,22 +189,23 @@ module VER
175
189
  end
176
190
  def print(string, width = width)
177
191
  return unless visible?
178
- @window.waddnstr(string.to_s, width)
192
+ waddnstr(string.to_s, width) # changed 2011 dts
179
193
  end
180
194
 
181
195
  def print_yx(string, y = 0, x = 0)
182
- @window.mvwaddnstr(y, x, string, width)
196
+ mvwaddnstr(y, x, string, width) # changed 2011 dts
183
197
  end
184
198
 
185
199
  def print_empty_line
186
200
  return unless visible?
187
- @window.printw(' ' * width)
201
+ printw(' ' * width)
188
202
  end
189
203
 
190
204
  def print_line(string)
191
205
  print(string.ljust(width))
192
206
  end
193
207
 
208
+ # @unused, pls remove
194
209
  def show_colored_chunks(chunks)
195
210
  return unless visible?
196
211
  chunks.each do |color, chunk|
@@ -235,10 +250,22 @@ module VER
235
250
  3 # is C-c
236
251
  end
237
252
 
253
+ # 2011-09-23 @since 1.3.1
254
+ # Added more combinations here. These 2 are just indicative
255
+ SPECIAL_KEYS = {
256
+ [27, 79, 50, 81] => 20014, # 'F14',
257
+ [27, 79, 50, 82] => 20015 # 'F15',
258
+ }
259
+
238
260
  # returns control, alt, alt+ctrl, alt+control+shift, F1 .. etc
239
261
  # ALT combinations also send a 27 before the actual key
240
262
  # Please test with above combinations before using on your terminal
241
263
  # added by rkumar 2008-12-12 23:07
264
+ # 2011-09-23 Redone Control-left, right, and Shift-F5..F10.
265
+ # Checking for quick press of Alt-Sh-O followed by Alt or printable char
266
+ # Checking for quick press of Alt-[ followed by Alt or printable char
267
+ # I attempted keeping a hash of combination arrays but it fails in the above
268
+ # 2 cases, so abandoned.
242
269
  def getchar
243
270
  while 1
244
271
  ch = getch
@@ -252,21 +279,16 @@ module VER
252
279
  when 1
253
280
  @stack.clear
254
281
  return 27
255
- when 2 # basically a ALT-O, this will be really slow since it waits for -1
282
+ when 2 # basically a ALT-O, or alt-[ (79 or 91) this will be really slow since it waits for -1
256
283
  ch = 128 + @stack.last
257
284
  @stack.clear
258
285
  return ch
259
- when 3
260
- $log.warn " SHOULD NOT COME HERE getchar():#{@stack}"
286
+ else
287
+ # check up a hash of special keys
288
+ ret = SPECIAL_KEYS(@stack)
289
+ return ret if ret
290
+ $log.warn "INVALID UNKNOWN KEY: SHOULD NOT COME HERE getchar():#{@stack}"
261
291
  end
262
- #elsif [181, 179, 178].include? @stack.first
263
- elsif @stack == [181] || @stack == [179] || @stack == [178]
264
- ch = @stack.first
265
- @stack.clear
266
- return ch
267
- elsif @stack == [179,49] # someone trying to spoof S-F9 with M3, 1
268
- ch = @stack.shift
269
- return ch
270
292
  end
271
293
  # possibly a 49 left over from M3-1
272
294
  unless @stack.empty?
@@ -284,7 +306,7 @@ module VER
284
306
  # this is the ALT combination
285
307
  if @stack.first == 27
286
308
  # experimental. 2 escapes in quick succession to make exit faster
287
- if ch == 27
309
+ if @stack.size == 1 && ch == 27
288
310
  @stack.clear
289
311
  return ch
290
312
  end
@@ -306,55 +328,72 @@ module VER
306
328
  ch = KEY_F3
307
329
  when 83
308
330
  ch = KEY_F4
331
+ #when 27 # another alt-char following Alt-Sh-O
332
+ else
333
+ @stack.clear
334
+ @stack << ch
335
+ return 128 + 79
336
+
309
337
  end
310
338
  @stack.clear
311
339
  return ch
312
340
  elsif @stack == [27, 91]
341
+ # XXX 27, 91 also is Alt-[
313
342
  if ch == 90
314
343
  @stack.clear
315
344
  return KEY_BTAB # backtab
345
+ elsif ch == 53 || ch == 50 || ch == 51
346
+ # control left, right and shift function
347
+ @stack << ch
348
+ next
349
+ elsif ch == 27 # another alt-char immediately after Alt-[
350
+ $log.debug "getchar in 27, will return 128+91 " if $log.debug?
351
+ @stack.clear
352
+ @stack << ch
353
+ return 128 + 91
354
+ else
355
+ $log.debug "getchar in other, will return 128+91: #{ch} " if $log.debug?
356
+ # other cases Alt-[ followed by some char or key - merge with previous
357
+ @stack.clear
358
+ @stack << ch
359
+ return 128 + 91
360
+ end
361
+ elsif @stack == [27, 91, 53]
362
+ if ch == 68
363
+ @stack.clear
364
+ return C_LEFT # control-left
365
+ elsif ch == 67
366
+ @stack.clear
367
+ return C_RIGHT # -control-rt
368
+ end
369
+ elsif @stack == [27, 91, 51]
370
+ if ch == 49 && getch()== 126
371
+ @stack.clear
372
+ return 20009 # sh_f9
373
+ end
374
+ elsif @stack == [27, 91, 50]
375
+ if ch == 50 && getch()== 126
376
+ @stack.clear
377
+ return 20010 # sh-F10
378
+ end
379
+ if ch == 57 && getch()== 126
380
+ @stack.clear
381
+ return 20008 # sh-F8
382
+ elsif ch == 56 && getch()== 126
383
+ @stack.clear
384
+ return 20007 # sh-F7
385
+ elsif ch == 54 && getch()== 126
386
+ @stack.clear
387
+ return 20006 # sh-F6
388
+ elsif ch == 53 && getch()== 126
389
+ @stack.clear
390
+ return 20005 # sh-F5
316
391
  end
317
392
  end
318
- # the usual Meta combos. (alt)
393
+ # the usual Meta combos. (alt) - this is screwing it up, just return it in some way
319
394
  ch = 128 + ch
320
395
  @stack.clear
321
- # these correspond to M-5, M2 and M3 but can also be C-left. C-rt. S-F5-S-F10
322
- if ch == 181 || ch == 178 || ch == 179
323
- @stack << ch
324
- next
325
- end
326
396
  return ch
327
- elsif @stack.first == 181
328
- if ch == 68
329
- ch = C_LEFT
330
- @stack.clear; return ch
331
- elsif ch == 67
332
- ch = C_RIGHT
333
- @stack.clear; return ch
334
- else
335
- $log.error "We ate a key 181 M-5 expecting C-L or C-r, but got #{ch}. I can only return one "
336
- @stack.clear; # should we ungetch the ch FIXME
337
- return 181
338
- end
339
- elsif @stack == [179, 49]
340
- if ch == 126
341
- @stack.clear;
342
- return S_F9
343
- else
344
- # FIXME
345
- $log.error "getchar: We ate 2 keys 179 M-?, 49 expecting S-F9, but got #{ch}. I can only return one "
346
- end
347
- elsif sf == 179
348
- if ch == 49
349
- @stack << ch
350
- next
351
- else
352
- #@stack.clear; # should i ungetch FIXME
353
- @stack.shift # some combination like M-3 2
354
- @stack << ch
355
- return 179
356
- end
357
- elsif sf == 178
358
397
  end # stack.first == 27
359
398
  # append a 27 to stack, actually one can use a flag too
360
399
  if ch == 27
@@ -365,6 +404,7 @@ module VER
365
404
  end # while
366
405
  end # def
367
406
 
407
+ # doesn't seem to work, clears first line, not both
368
408
  def clear
369
409
  # return unless visible?
370
410
  move 0, 0
@@ -373,10 +413,13 @@ module VER
373
413
 
374
414
  # setup and reset
375
415
 
416
+ ## allow user to send an array
417
+ # I am tired of the hash layout (taken from ver).
376
418
  def reset_layout(layout)
377
419
  case layout
378
420
  when Array
379
421
  @height, @width, @top, @left = *layout
422
+ @layout = { :height => @height, :width => @width, :top => @top, :left => @top }
380
423
  when Hash
381
424
  @layout = layout
382
425
 
@@ -446,6 +489,7 @@ module VER
446
489
  Ncurses::Panel.del_panel(@panel.pointer) if !@panel.nil? # ADDED FFI pointer 2011-09-7
447
490
  #@window.delwin(@window) if !@window.nil? # added FFI 2011-09-7
448
491
  delwin() if !@window.nil? # added FFI 2011-09-7
492
+ Ncurses::Panel.update_panels # added so below window does not need to do this 2011-10-1
449
493
  $log.debug "win destroy end"
450
494
  end
451
495
  ##
@@ -489,6 +533,16 @@ module VER
489
533
  mvwprintw(r, c, "%s", :string, string);
490
534
  wattroff(Ncurses.COLOR_PAIR(color) | att)
491
535
  end
536
+ # @deprecated
537
+ def print_error_message text=$error_message.get_value
538
+ alert text
539
+ end
540
+ # added by rk 2008-11-29 19:01
541
+ # @deprecated. use global method of same name in rdialog
542
+ def print_status_message text=$status_message
543
+ #VER::print_status_message text
544
+ alert text
545
+ end
492
546
  # added by rk 2008-11-29 19:01
493
547
  # Since these methods write directly to window they are not advised
494
548
  # since clearing previous message we don't know how much to clear.
@@ -496,7 +550,7 @@ module VER
496
550
  # 2010-09-13 00:22 WE should not use these any longer.
497
551
  # Application should create a label and map a Variable named
498
552
  # $errormessage to it. We should only update the Variable
499
- def print_error_message text=$error_message.get_value
553
+ def DEPRECATED_print_error_message text=$error_message.get_value
500
554
  r = $error_message_row || Ncurses.LINES-1
501
555
  c = $error_message_col || (Ncurses.COLS-text.length)/2
502
556
 
@@ -506,7 +560,8 @@ module VER
506
560
  $error_message_clear_pending = true
507
561
  end
508
562
  # added by rk 2008-11-29 19:01
509
- def print_status_message text=$status_message
563
+ # @deprecated. use global method of same name
564
+ def DEPRECATED_print_status_message text=$status_message
510
565
  r = $status_message_row || Ncurses.LINES-1
511
566
  clear_error r, $datacolor
512
567
  # print it in centre
@@ -515,7 +570,7 @@ module VER
515
570
  # Clear error message printed
516
571
  # I am not only clearing if something was printed. This is since
517
572
  # certain small forms like TabbedForm top form throw an error on printstring.
518
- #
573
+ # @deprecated
519
574
  def clear_error r = $error_message_row, color = $datacolor
520
575
  return unless $error_message_clear_pending
521
576
  c = $error_message_col || (Ncurses.COLS-text.length)/2
@@ -524,7 +579,7 @@ module VER
524
579
  $error_message_clear_pending = false
525
580
  end
526
581
  ##
527
- # CAUTION : FOR MESSAGEBOXES ONLY !!!! XXX
582
+ # NOTE : FOR MESSAGEBOXES ONLY !!!!
528
583
  def print_border_mb row, col, height, width, color, attr
529
584
  mvwaddch row, col, Ncurses::ACS_ULCORNER
530
585
  mvwhline( row, col+1, Ncurses::ACS_HLINE, width-6)
@@ -591,7 +646,7 @@ module VER
591
646
  wattroff(Ncurses.COLOR_PAIR(color) | att)
592
647
  end
593
648
  # added RK 2009-10-08 23:57 for tabbedpanes
594
- # THIS IS EXPERIMENTAL -
649
+ # THIS IS EXPERIMENTAL - XXX CLEANUP REMOVE
595
650
  # Acco to most sources, derwin and subwin are not thoroughly tested, avoid usage
596
651
  # subwin moving and resizing not functioning.
597
652
  def derwin(layout)
@@ -600,6 +655,7 @@ module VER
600
655
  $log.debug " #{self} EXP: returning a subwin in derwin: #{v} "
601
656
  return v
602
657
  end
658
+ ## REMOVE CLEANUP UNUSED
603
659
  def _subwin(layout)
604
660
  t = @layout[:top]
605
661
  l = @layout[:left]
@@ -641,12 +697,14 @@ module VER
641
697
  end
642
698
  end
643
699
  end
700
+ #-------------------------------- deprecated stuff ------------------ #
644
701
  ##
645
702
  # added RK 2009-10-08 23:57 for tabbedpanes
646
703
  # THIS IS EXPERIMENTAL -
647
704
  # I have not called super in the initializer so any methods you try on subwin
648
705
  # that exist in the superclass which use @window will bomb
649
- # @since 0.1.3
706
+ # @since 0.1.3 REMOVE UNUSED.
707
+ # @deprecated
650
708
  class SubWindow < VER::Window
651
709
  attr_reader :width, :height, :top, :left
652
710
  attr_accessor :layout
@@ -702,6 +760,7 @@ module VER
702
760
  # but we keep printing an extra row in copywin. so Pad needs to maintain comp height
703
761
  # and padheight.
704
762
  # @since 0.1.3
763
+ # NOTE used only by TabbedPane. If we rewrite without using it in 1.3.1 then scrap.
705
764
  class Pad < VER::Window
706
765
  # top and left correspond to screen's top and left wich will mostly be fixed
707
766
  attr_accessor :top, :left
@@ -857,6 +916,8 @@ module VER
857
916
  # also assuming only one win so, window not passed as param
858
917
  # @return return value of copywin which should be 0 (-1 is ERR)
859
918
  def copy_pad_to_win
919
+ $log.warn " DEPRECATED copy_pad_to_win" # CLEANUP
920
+ raise "DEPREC copy_pad_to_win deprecated. Will be removed. Let me know if it is needed"
860
921
  # check that we don't exceed other windows height/maxrow
861
922
  smr = smaxrow()
862
923
  # SHIT, this means the otherwin has to be a Pad, cannot be a window
@@ -930,7 +991,10 @@ module VER
930
991
  @modified = false
931
992
  return ret
932
993
  end
994
+ # @deprecated
933
995
  def copy_win_to_pad
996
+ $log.warn " DEPRECATED copy_win_to_pad" # CLEANUP 2011-09-29
997
+ raise "DEPREC copy_win_to_pad deprecated. Will be removed. Let me know if it is needed"
934
998
  smr = smaxrow()
935
999
  if smr >= @window.smaxrow()
936
1000
  smr = @window.smaxrow()-1