rbcurse 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
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
@@ -163,6 +163,14 @@ module RubyCurses
163
163
  return nil
164
164
  #return find_match @last_regex, start, @search_end_ix
165
165
  end
166
+ ##
167
+ # added 2010-05-23 12:10 for listeditable
168
+ def slice!(line, howmany)
169
+ ret = @list.slice!(line, howmany)
170
+ lde = ListDataEvent.new(line, line+howmany-1, self, :INTERVAL_REMOVED)
171
+ fire_handler :LIST_DATA_EVENT, lde
172
+ return ret
173
+ end
166
174
 
167
175
  alias :to_array :values
168
176
  end # class ListDataModel
@@ -113,6 +113,16 @@ module RubyCurses
113
113
  bind_key(@KEY_ASK_FIND_BACKWARD) { ask_search_backward }
114
114
  bind_key(@KEY_FIND_NEXT) { find_next }
115
115
  bind_key(@KEY_FIND_PREV) { find_prev }
116
+ # added 2010-05-12 21:41 for vim keys, will work if cell editing allowed is false
117
+ # user should be able to switch to editable and off so he can use keys TODO
118
+ # TODO vim_editable mode: C dd etc . to repeat change, how about range commands like vim
119
+ # TODO use numeric to widen, so we can distribute spacing
120
+ bind_key(?j){ next_row() }
121
+ bind_key(?k){ previous_row() }
122
+ bind_key(?G){ goto_bottom() }
123
+ bind_key([?g,?g]){ goto_top() }
124
+ bind_key(?l) { next_column }
125
+ bind_key(?h) { previous_column }
116
126
  end
117
127
 
118
128
  def focussed_row
@@ -538,7 +548,7 @@ module RubyCurses
538
548
  when ?\C-p.getbyte(0)
539
549
  editing_stopped if @is_editing # 2009-01-16 16:06
540
550
  scroll_backward
541
- when 48, @KEY_GOTO_TOP
551
+ when @KEY_GOTO_TOP # removed 48 (0) from here so we can trap numbers
542
552
  # please note that C-[ gives 27, same as esc so will respond after ages
543
553
  editing_stopped if @is_editing # 2009-01-16 16:06
544
554
  goto_top
@@ -551,9 +561,14 @@ module RubyCurses
551
561
  when @KEY_SCROLL_LEFT
552
562
  editing_stopped if @is_editing # dts 2009-02-17 00:35
553
563
  scroll_left
564
+ when ?0.getbyte(0)..?9.getbyte(0)
565
+ $multiplier *= 10 ; $multiplier += (ch-48)
566
+ #$log.debug " setting mult to #{$multiplier} in list "
567
+ return 0
554
568
  else
555
569
  # there could be a case of editing here too!
556
570
  ret = process_key ch, self
571
+ $multiplier = 0
557
572
  return :UNHANDLED if ret == :UNHANDLED
558
573
  end
559
574
  return 0 # added 2010-03-14 13:27
@@ -607,26 +622,40 @@ module RubyCurses
607
622
  cancel_editor
608
623
  end
609
624
  ##
610
- def previous_row
625
+ #def previous_row
626
+ def previous_row num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
611
627
  @oldrow = @current_index
612
- @current_index -= 1 if @current_index > 0
628
+ # @current_index -= 1 if @current_index > 0
629
+ num.times {
630
+ @current_index -= 1 if @current_index > 0
631
+ }
632
+ $multiplier = 0
613
633
  bounds_check
614
634
  end
615
- def next_row
635
+ #def next_row
636
+ # goto next row
637
+ # added multipler 2010-05-12 20:51
638
+ def next_row num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
616
639
  rc = row_count
617
640
  @oldrow = @current_index
618
641
  # don't go on if rc 2009-01-16 19:55 XXX
619
642
  if @current_index < rc
620
- @current_index += 1
643
+ #@current_index += 1
644
+ @current_index += 1*num if @current_index < rc
621
645
  bounds_check
622
646
  end
647
+ $multiplier = 0
623
648
  end
624
649
  # move focus to next column
625
650
  # 2009-10-07 12:47 behavior change. earlier this would move to next row
626
651
  # if focus was on last visible field. Now it scrolls so that first invisible
627
652
  # field becomes the first column.
628
- def next_column
629
- v = @current_column+1
653
+ # # 2010-05-13 12:42 added multiplier
654
+ #def next_column
655
+ def next_column num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
656
+ $multiplier = 0 # so not used again in next row
657
+ #v = @current_column+1
658
+ v = @current_column + num
630
659
  # normal situation, there is a next column go to
631
660
  if v < @table_column_model.column_count
632
661
  if v <= @_last_column_print
@@ -647,7 +676,7 @@ module RubyCurses
647
676
  @current_column = 0
648
677
  #@current_column = @_first_column_print # added 2009-02-17 00:01
649
678
  @_first_column_print = 0 # added 2009-10-07 11:25
650
- next_row
679
+ next_row 1
651
680
  set_form_col
652
681
  @repaint_required = true
653
682
  @table_changed = true # so columns are modified by print_header
@@ -659,8 +688,9 @@ module RubyCurses
659
688
  # move focus to previous column
660
689
  # if you are on first column, check if scrolling required, else move up to
661
690
  # last *visible* column of prev row
662
- def previous_column
663
- v = @current_column-1
691
+ #def previous_column
692
+ def previous_column num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
693
+ v = @current_column - num # 2010-05-13 12:44 1 to num
664
694
  # returning unhandled so focus can go to prev field auto
665
695
  if v < @_first_column_print and @current_index <= 0
666
696
  return :UNHANDLED
@@ -674,7 +704,7 @@ module RubyCurses
674
704
  @current_column = @_last_column_print # added 2009-02-17 00:01
675
705
  $log.debug " XXXXXX prev col #{@current_column}, las #{@_last_column_print}, fi: #{@_first_column_print}"
676
706
  set_form_col
677
- previous_row
707
+ previous_row 1
678
708
  end
679
709
  else
680
710
  current_column v
@@ -1090,8 +1120,12 @@ module RubyCurses
1090
1120
  end
1091
1121
  end
1092
1122
  total = 0
1093
- colwidths.each_pair do |k,v|
1123
+ # crashing in 1.9.2 due to hash key no insert in iteration 2010-08-22 20:09
1124
+ #colwidths.each_pair do |k,v|
1125
+ tkeys = colwidths.keys
1126
+ tkeys.each do |k|
1094
1127
  name = columns[k.to_i]
1128
+ v = colwidths[k]
1095
1129
  colwidths[name] = v
1096
1130
  total += v
1097
1131
  end
@@ -348,7 +348,12 @@ module RubyCurses
348
348
  # this bypasses our methods and sets directly !
349
349
  def config_setup aconfig
350
350
  @config = aconfig
351
- @config.each_pair { |k,v| variable_set(k,v) }
351
+ # this creates a problem in 1.9.2 since variable_set sets @config 2010-08-22 19:05 RK
352
+ #@config.each_pair { |k,v| variable_set(k,v) }
353
+ keys = @config.keys
354
+ keys.each do |e|
355
+ variable_set(e, @config[e])
356
+ end
352
357
  end
353
358
  end # module config
354
359
  ##
@@ -1041,7 +1046,7 @@ module RubyCurses
1041
1046
  @rows_panned = @cols_panned = 0 # how many rows were panned, typically at a higher level
1042
1047
  @firsttime = true; # added on 2010-01-02 19:21 to prevent scrolling crash !
1043
1048
  @name ||= ""
1044
- $kill_ring ||= [] # 2010-03-09 22:42 so textarea and others can copy and paste
1049
+ $kill_ring ||= [] # 2010-03-09 22:42 so textarea and others can copy and paste emacs EMACS
1045
1050
  $kill_ring_pointer = 0 # needs to be incremented with each append, moved with yank-pop
1046
1051
  $append_next_kill = false
1047
1052
  $kill_last_pop_size = 0 # size of last pop which has to be cleared
@@ -1548,7 +1553,7 @@ module RubyCurses
1548
1553
  return 0 if ret == 0
1549
1554
  ch = ret # unhandled char
1550
1555
  elsif ch >= ?\M-1.getbyte(0) && ch <= ?\M-9.getbyte(0)
1551
- if $catch_alt_digits
1556
+ if $catch_alt_digits # emacs EMACS
1552
1557
  ret = digit_argument ch
1553
1558
  $log.debug " FORM set MULT DA to #{$multiplier}, ret = #{ret} "
1554
1559
  return 0 if ret == 0 # don't see this happening
@@ -164,7 +164,14 @@ module RubyCurses
164
164
  @source.list[row].slice!(col,howmany)
165
165
  when :DELETE_LINE
166
166
  #$log.debug " UNDO redo got deleteline #{row} "
167
- @source.list.delete_at row
167
+ #@source.list.delete_at row
168
+ # changed on 2010-05-23 12:21 since was not handling mult delete
169
+ case act.text
170
+ when Array
171
+ act.text.size.times { @source.list.delete_at row }
172
+ when String
173
+ @source.list.delete_at row
174
+ end
168
175
  when :INSERT_LINE
169
176
  case act.text
170
177
  when Array
@@ -12,13 +12,14 @@ require 'rbcurse/listeditable'
12
12
  module ViEditable
13
13
  include ListEditable
14
14
 
15
- #def ViEditable.vieditable_init
16
15
  def vieditable_init
17
16
  $log.debug " inside vieditable_init "
18
17
  @editable = true
19
18
  bind_key( ?C, :edit_line)
20
- bind_key( ?o, :insert_line)
21
- bind_key( ?O) { insert_line(@current_index-1) }
19
+ #bind_key( ?o, :insert_line)
20
+ #bind_key( ?O) { insert_line(@current_index-1) }
21
+ bind_key( ?o) { insert_line(@current_index+1) }
22
+ bind_key( ?O) { insert_line(@current_index) }
22
23
  bind_key( ?D, :delete_eol)
23
24
  bind_key( [?d, ?$], :delete_eol)
24
25
  bind_key( [?d, ?d] , :delete_line )
@@ -35,25 +36,64 @@ module ViEditable
35
36
  bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
36
37
  bind_key(?\w, :forward_word)
37
38
  bind_key(?f, :forward_char)
39
+ bind_key(?\M-y, :yank_pop)
40
+ bind_key(?\M-w, :kill_ring_save)
41
+
42
+ end
43
+ ##
44
+ # Separate mappings for listboxes.
45
+ # Some methods don;'t make sense for listboxes and are crashing
46
+ # since not present for them. f was being overwritten, too.
47
+ # Sorry for duplication, need to clean this somehow.
48
+ def vieditable_init_listbox
49
+ $log.debug " inside vieditable_init_listbox "
50
+ @editable = true
51
+ bind_key( ?C, :edit_line)
52
+ bind_key( ?o) { insert_line(@current_index+1) }
53
+ bind_key( ?O) { insert_line(@current_index) }
54
+ #bind_key( ?D, :delete_eol)
55
+ #bind_key( [?d, ?$], :delete_eol)
56
+ bind_key( [?d, ?d] , :delete_line )
57
+ #bind_key( [?d, ?w], :delete_word )
58
+ #bind_key( [?d, ?t], :delete_till )
59
+ #bind_key( [?d, ?f], :delete_forward )
60
+ bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
61
+ bind_key( ?u ) { @undo_handler.undo if @undo_handler }
62
+ bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
63
+ #bind_key( ?x, :delete_curr_char )
64
+ #bind_key( ?X, :delete_prev_char )
65
+ bind_key( [?y, ?y] , :kill_ring_save )
66
+ bind_key( ?p, :yank ) # paste after this line
67
+ bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
68
+ bind_key(?\w, :forward_word)
69
+ #bind_key(?f, :forward_char)
70
+ bind_key(?\M-y, :yank_pop)
71
+ bind_key(?\C-y, :yank)
72
+ bind_key(?\M-w, :kill_ring_save)
38
73
 
39
74
  end
40
75
 
41
76
  ##
42
77
  # edit current or given line
78
+ # FIXME needs to fire handler 2010-05-23 11:40
43
79
  def edit_line lineno=@current_index
44
80
  line = @list[lineno]
45
81
  prompt = "Edit: "
46
82
  maxlen = 80
47
83
  config={};
84
+ oldline = line.dup
48
85
  config[:default] = line
49
86
  ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
50
87
  $log.debug " rbgetstr returned #{ret} , #{str} "
51
88
  return if ret != 0
52
89
  @list[lineno].replace(str)
90
+ fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline) # 2008-12-24 18:34
91
+ fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
53
92
  @repaint_required = true
54
93
  end
55
94
  ##
56
95
  # insert a line
96
+ # FIXME needs to fire handler 2010-05-23 11:40
57
97
  def insert_line lineno=@current_index
58
98
  prompt = "Insert: "
59
99
  maxlen = 80
@@ -65,6 +105,8 @@ module ViEditable
65
105
  $log.debug " rbgetstr returned #{ret} , #{str} "
66
106
  return if ret != 0
67
107
  @list.insert lineno, str
108
+ ## added handler on 2010-05-23 11:46 - undo works - tested in testlistbox.rb
109
+ fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
68
110
  @repaint_required = true
69
111
  end
70
112
  ##
data/rbcurse.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rbcurse}
8
- s.version = "1.1.3"
8
+ s.version = "1.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rahul Kumar"]
12
- s.date = %q{2010-05-10}
12
+ s.date = %q{2010-08-30}
13
13
  s.default_executable = %q{rbcurse}
14
14
  s.description = %q{Ruby curses widgets for easy application development on text terminals (ruby 1.9, 1.8)}
15
15
  s.email = %q{sentinel.2001@gmx.com}
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "VERSION",
32
32
  "bin/rbcurse",
33
33
  "examples/README.txt",
34
+ "examples/data.txt",
34
35
  "examples/keytest.rb",
35
36
  "examples/mpad2.rb",
36
37
  "examples/newtesttabp.rb",
@@ -46,6 +47,7 @@ Gem::Specification.new do |s|
46
47
  "examples/testchars.rb",
47
48
  "examples/testcombo.rb",
48
49
  "examples/testkeypress.rb",
50
+ "examples/testlistbox.rb",
49
51
  "examples/testmenu.rb",
50
52
  "examples/testmulticomp.rb",
51
53
  "examples/testscroller.rb",
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
69
71
  "examples/testtpane.rb",
70
72
  "examples/testtpane2.rb",
71
73
  "examples/testtpanetable.rb",
74
+ "examples/todo.db",
72
75
  "examples/todo.yml",
73
76
  "examples/todocsv.csv",
74
77
  "examples/viewtodo.rb",
@@ -80,6 +83,7 @@ Gem::Specification.new do |s|
80
83
  "lib/rbcurse/colormap.rb",
81
84
  "lib/rbcurse/comboboxcellrenderer.rb",
82
85
  "lib/rbcurse/defaultlistselectionmodel.rb",
86
+ "lib/rbcurse/extras/tableextended.rb",
83
87
  "lib/rbcurse/io.rb",
84
88
  "lib/rbcurse/keylabelprinter.rb",
85
89
  "lib/rbcurse/listcellrenderer.rb",
@@ -126,7 +130,7 @@ Gem::Specification.new do |s|
126
130
  s.homepage = %q{http://rbcurse.rubyforge.org/}
127
131
  s.rdoc_options = ["--charset=UTF-8"]
128
132
  s.require_paths = ["lib"]
129
- s.rubygems_version = %q{1.3.6}
133
+ s.rubygems_version = %q{1.3.7}
130
134
  s.summary = %q{Ruby Curses Toolkit}
131
135
  s.test_files = [
132
136
  "test/test_rbcurse.rb",
@@ -144,6 +148,7 @@ Gem::Specification.new do |s|
144
148
  "examples/testchars.rb",
145
149
  "examples/testcombo.rb",
146
150
  "examples/testkeypress.rb",
151
+ "examples/testlistbox.rb",
147
152
  "examples/testmenu.rb",
148
153
  "examples/testmulticomp.rb",
149
154
  "examples/testscroller.rb",
@@ -167,6 +172,7 @@ Gem::Specification.new do |s|
167
172
  "examples/testtpane.rb",
168
173
  "examples/testtpane2.rb",
169
174
  "examples/testtpanetable.rb",
175
+ "examples/todo.rb",
170
176
  "examples/viewtodo.rb"
171
177
  ]
172
178
 
@@ -174,7 +180,7 @@ Gem::Specification.new do |s|
174
180
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
175
181
  s.specification_version = 3
176
182
 
177
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
183
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
178
184
  else
179
185
  end
180
186
  else
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 3
9
- version: 1.1.3
8
+ - 4
9
+ version: 1.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rahul Kumar
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-10 00:00:00 +05:30
17
+ date: 2010-08-30 00:00:00 +05:30
18
18
  default_executable: rbcurse
19
19
  dependencies: []
20
20
 
@@ -40,6 +40,7 @@ files:
40
40
  - VERSION
41
41
  - bin/rbcurse
42
42
  - examples/README.txt
43
+ - examples/data.txt
43
44
  - examples/keytest.rb
44
45
  - examples/mpad2.rb
45
46
  - examples/newtesttabp.rb
@@ -55,6 +56,7 @@ files:
55
56
  - examples/testchars.rb
56
57
  - examples/testcombo.rb
57
58
  - examples/testkeypress.rb
59
+ - examples/testlistbox.rb
58
60
  - examples/testmenu.rb
59
61
  - examples/testmulticomp.rb
60
62
  - examples/testscroller.rb
@@ -78,6 +80,7 @@ files:
78
80
  - examples/testtpane.rb
79
81
  - examples/testtpane2.rb
80
82
  - examples/testtpanetable.rb
83
+ - examples/todo.db
81
84
  - examples/todo.yml
82
85
  - examples/todocsv.csv
83
86
  - examples/viewtodo.rb
@@ -89,6 +92,7 @@ files:
89
92
  - lib/rbcurse/colormap.rb
90
93
  - lib/rbcurse/comboboxcellrenderer.rb
91
94
  - lib/rbcurse/defaultlistselectionmodel.rb
95
+ - lib/rbcurse/extras/tableextended.rb
92
96
  - lib/rbcurse/io.rb
93
97
  - lib/rbcurse/keylabelprinter.rb
94
98
  - lib/rbcurse/listcellrenderer.rb
@@ -131,6 +135,7 @@ files:
131
135
  - lib/ver/window.rb
132
136
  - rbcurse.gemspec
133
137
  - test/test_rbcurse.rb
138
+ - examples/todo.rb
134
139
  has_rdoc: true
135
140
  homepage: http://rbcurse.rubyforge.org/
136
141
  licenses: []
@@ -141,6 +146,7 @@ rdoc_options:
141
146
  require_paths:
142
147
  - lib
143
148
  required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
144
150
  requirements:
145
151
  - - ">="
146
152
  - !ruby/object:Gem::Version
@@ -148,6 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
154
  - 0
149
155
  version: "0"
150
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
151
158
  requirements:
152
159
  - - ">="
153
160
  - !ruby/object:Gem::Version
@@ -157,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
164
  requirements: []
158
165
 
159
166
  rubyforge_project:
160
- rubygems_version: 1.3.6
167
+ rubygems_version: 1.3.7
161
168
  signing_key:
162
169
  specification_version: 3
163
170
  summary: Ruby Curses Toolkit
@@ -177,6 +184,7 @@ test_files:
177
184
  - examples/testchars.rb
178
185
  - examples/testcombo.rb
179
186
  - examples/testkeypress.rb
187
+ - examples/testlistbox.rb
180
188
  - examples/testmenu.rb
181
189
  - examples/testmulticomp.rb
182
190
  - examples/testscroller.rb
@@ -200,4 +208,5 @@ test_files:
200
208
  - examples/testtpane.rb
201
209
  - examples/testtpane2.rb
202
210
  - examples/testtpanetable.rb
211
+ - examples/todo.rb
203
212
  - examples/viewtodo.rb