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,178 +0,0 @@
1
- require 'rbcurse/rwidget'
2
- #include Ncurses # FFI 2011-09-8
3
- include RubyCurses
4
- module RubyCurses
5
- #
6
- # This paints labels for various keys at the bottom of the screen, in 2 rows.
7
- # This is based on alpines last 2 rows. Modes are supported so that the
8
- # labels change as you enter a widget.
9
- # For an example, see dbdemo.rb or rfe.rb
10
- # NOTE: applications using 'App' use a shortcut "dock" to create this.
11
- #
12
- # The most minimal keylabel to print one label in first row, and none in second is:
13
- # [["F1", "Help"], nil]
14
- # To print 2 labels, one over the other:
15
- # [["F1", "Help"], ["F10", "Quit"]]
16
- #
17
- class KeyLabelPrinter < Widget
18
- attr_reader :key_labels
19
- # the current mode (labels are based on mode, changing the mode, changes the labels
20
- # displayed)
21
- dsl_property :mode
22
- # set the color of the labels, overriding the defaults
23
- dsl_accessor :footer_color_pair
24
- # set the color of the mnemonic, overriding the defaults
25
- dsl_accessor :footer_mnemonic_color_pair
26
-
27
- def initialize form, key_labels, config={}, &block
28
-
29
- case key_labels
30
- when Hash
31
- raise "KeyLabelPrinter: KeyLabels cannot be a hash, Array of key labels required. Perhaps you did not pass labels"
32
- when Array
33
- else
34
- raise "KeyLabelPrinter: Array of key labels required. Perhaps you did not pass labels"
35
- end
36
- super form, config, &block
37
- @mode ||= :normal
38
- #@key_labels = key_labels
39
- @key_hash = {}
40
- @key_hash[@mode] = key_labels
41
- @editable = false
42
- @focusable = false
43
- @cols ||= Ncurses.COLS-1
44
- @row ||= Ncurses.LINES-2
45
- @col ||= 0
46
- @repaint_required = true
47
- @footer_color_pair ||= $bottomcolor
48
- @footer_mnemonic_color_pair ||= $reversecolor #2
49
- end
50
- def key_labels mode=@mode
51
- @key_hash[mode]
52
- end
53
- # returns the keys as printed. these may or may not help
54
- # in validation depedign on what you passed as zeroth index
55
- def get_current_keys
56
- a = []
57
- @key_hash[@mode].each do |arr|
58
- a << arr[0] unless arr.nil?
59
- end
60
- return a
61
- end
62
- def getvalue
63
- @key_hash
64
- end
65
- def set_key_labels _key_labels, mode=:normal
66
- @key_hash[mode] = _key_labels
67
- end
68
-
69
- ##
70
- # XXX need to move wrapping etc up and done once.
71
- def repaint
72
- return unless @repaint_required
73
- r,c = rowcol
74
- arr = key_labels()
75
- print_key_labels(arr, mode=@mode)
76
- @repaint_required = false
77
- end
78
- # ?? does not use mode, i think key_labels is unused. a hash is now used 2011-10-11 XXX FIXME
79
- # WARNING, i have not tested this after changing it.
80
- def append_key_label key, label, mode=@mode
81
- #@key_labels << [key, label] if !@key_labels.include? [key, label]
82
- @key_hash[mode] << [key, label] if !@key_hash[mode].include? [key, label]
83
- @repaint_required = true
84
- end
85
- def print_key_labels(arr = key_labels(), mode=@mode)
86
- #return if !@show_key_labels # XXX
87
- @win ||= @form.window
88
- $log.debug "XXX: PKL #{arr.length}, #{arr}"
89
- @padding = @cols / (arr.length/2)
90
- posx = 0
91
- even = []
92
- odd = []
93
- arr.each_index { |i|
94
- if i % 2 == 0
95
- #arr[i+1] = ['',''] if arr[i+1].nil?
96
- nextarr = arr[i+1] || ['', '']
97
- keyw = [arr[i][0].length, nextarr[0].length].max
98
- labelw = [arr[i][1].length, nextarr[1].length].max
99
-
100
- even << [ sprintf("%*s", keyw, arr[i][0]), sprintf("%-*s", labelw, arr[i][1]) ]
101
- odd << [ sprintf("%*s", keyw, nextarr[0]), sprintf("%-*s", labelw, nextarr[1]) ]
102
- #$log.debug("loop even: #{even.inspect}")
103
- else
104
- end
105
- }
106
- #$log.debug("even: #{even.inspect}")
107
- #$log.debug("odd : #{odd.inspect}")
108
- #posy = @barrow-1
109
- posy = @row
110
- print_key_labels_row(posy, posx, even)
111
- posy = @row+1
112
- print_key_labels_row(posy, posx, odd)
113
- # uncommented next line after ffi-ncurses else not showing till key press FFI 2011-09-17
114
- @win.wrefresh # needed else secod row not shown after askchoice XXX
115
- end
116
- def print_key_labels_row(posy, posx, arr)
117
- # FIXME: this logic of padding needs to take into account
118
- # width of window
119
- padding = 8
120
- padding = 4 if arr.length > 5
121
- padding = 2 if arr.length > 7
122
- padding = 0 if arr.length > 9
123
- #padding = @padding # XXX 2008-11-13 23:01
124
- my_form_win = @win
125
- @win.printstring(posy,0, "%-*s" % [@cols," "], @footer_color_pair, @attr)
126
- arr.each do |kl|
127
- key = kl[0]
128
- lab = kl[1]
129
- if key !="" # don't print that white blank space for fillers
130
- color_pair= @footer_mnemonic_color_pair # $reversecolor #2
131
- x = posx + (key.length - key.strip.length)
132
- my_form_win.attron(Ncurses.COLOR_PAIR(color_pair))
133
- my_form_win.mvprintw(posy, x, "%s" % kl[0].strip );
134
- my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair))
135
- end
136
- color_pair=@footer_color_pair
137
- posx = posx + kl[0].length
138
- my_form_win.attron(Ncurses.COLOR_PAIR(color_pair))
139
-
140
- #lab = sprintf(" %s %*s" , kl[1], padding, " ");
141
- lab = sprintf(" %s %s" , kl[1], " "*padding);
142
- my_form_win.mvprintw(posy, posx, lab)
143
- my_form_win.attroff(Ncurses.COLOR_PAIR(color_pair))
144
- posx = posx + lab.length
145
- end
146
- end
147
- ##
148
- # updates existing label with a new one.
149
- # @return true if updated, else false
150
- # @example update "C-x", "C-x", "Disable"
151
- def update_application_key_label(display_code, new_display_code, text)
152
- @repaint_required = true
153
- labels = key_labels()
154
- raise "labels are nil !!!" unless labels
155
- labels.each_index do |ix|
156
- lab = labels[ix]
157
- next if lab.nil?
158
- if lab[0] == display_code
159
- labels[ix] = [new_display_code , text]
160
- $log.debug("updated #{labels[ix]}")
161
- return true
162
- end
163
- end
164
- return false
165
- end
166
- alias :update :update_application_key_label
167
- ##
168
- # inserts an application label at given index
169
- # to add the key, use create_datakeys to add bindings
170
- # remember to call restore_application_key_labels after updating/inserting
171
- def insert_application_key_label(index, display_code, text)
172
- @repaint_required = true
173
- labels = key_labels()
174
- labels.insert(index, [display_code , text] )
175
- end
176
- # ADD HERE KEYLABEL
177
- end
178
- end
@@ -1,140 +0,0 @@
1
- require 'rbcurse/rwidget'
2
- module RubyCurses
3
-
4
- ##
5
- # 2010-09-27 11:06 : i have modified this quite a bit, to calculate some stuff
6
- # once in the init, to reduce work in repaint
7
- # This is a basic list cell renderer that will render the to_s value of anything.
8
- # Using alignment one can use for numbers too.
9
- # However, for booleans it will print true and false. If editing, you may want checkboxes
10
- # NOTE: this class is being extended by many other classes. Careful while making
11
- # sweeping changes.
12
- class ListCellRenderer
13
- include RubyCurses::ConfigSetup
14
- include RubyCurses::Utils
15
- dsl_accessor :justify # :right, :left, :center # added 2008-12-22 19:02
16
- dsl_accessor :display_length # please give this to ensure the we only print this much
17
- dsl_accessor :height # if you want a multiline label.
18
- dsl_accessor :text # text of label
19
- dsl_accessor :color, :bgcolor
20
- dsl_accessor :row, :col
21
- dsl_accessor :parent #usuall the table to get colors and other default info
22
-
23
- def initialize text="", config={}, &block
24
- @text = text
25
- @editable = false
26
- @focusable = false
27
- config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
28
- instance_eval &block if block_given?
29
- init_vars
30
- end
31
- # NOTE: please call super() if you override this
32
- def init_vars #:nodoc:
33
- # omg, some classes won't have justify !!
34
- #@justify ||= (@parent.justify || :left)
35
- unless @justify
36
- if @parent.respond_to? :justify
37
- @justify ||= (@parent.justify || :left)
38
- else
39
- @justify ||= :left
40
- end
41
- end
42
- @format = @justify.to_sym == :right ? "%*s" : "%-*s"
43
- @display_length ||= 10
44
- # create color pairs once for this 2010-09-26 20:53
45
- end
46
- # creates pairs of colors at start
47
- # since often classes are overriding init_vars, so not gettin created
48
- def create_color_pairs
49
- @color_pair = get_color $datacolor
50
- @pairs = Hash.new(@color_pair)
51
- @attrs = Hash.new(Ncurses::A_NORMAL)
52
- color_pair = get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor
53
- @pairs[:normal] = @color_pair
54
- @pairs[:selected] = color_pair
55
- @pairs[:focussed] = @pairs[:normal]
56
- @attrs[:selected] = $row_selected_attr
57
- @attrs[:focussed] = $row_focussed_attr
58
-
59
- end
60
- def getvalue
61
- @text
62
- end
63
- ##
64
- # sets @color_pair and @attr
65
- def select_colors focussed, selected
66
- create_color_pairs unless @pairs
67
- raise ArgumentError, "pairs hash is null. Changes have happened in listcellrenderer" unless @pairs
68
- @color_pair = @pairs[:normal]
69
- #@attr = $row_attr
70
- @attr = @row_attr || $row_attr # changed 2011-10-15 since we seem to be ignoring row_attr changes
71
- # give precedence to a selected row
72
- if selected
73
- @color_pair = @pairs[:selected]
74
- @attr = @attrs[:selected]
75
- elsif focussed
76
- @color_pair = @pairs[:focussed]
77
- @attr = @attrs[:focussed]
78
- end
79
- end
80
-
81
- ##
82
- # paint a list box cell
83
- #
84
- # @param [Buffer] window or buffer object used for printing
85
- # @param [Fixnum] row
86
- # @param [Fixnum] column
87
- # @param [Fixnum] actual index into data, some lists may have actual data elsewhere and
88
- # display data separate. e.g. rfe_renderer (directory listing)
89
- # @param [String] text to print in cell
90
- # @param [Boolean, cell focussed, not focussed
91
- # @param [Boolean] cell selected or not
92
- def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false
93
-
94
- select_colors focussed, selected
95
- # if listboxes width is reduced, display_len remains the same
96
- # XXX FIXME parent may not be the list but a container like rfe !!
97
- # maybe caller should update at start of repain loop.
98
- #@display_length = @parent.width - 2 - @parent.left_margin
99
-
100
- value=value.to_s
101
- if !@display_length.nil?
102
- if value.length > @display_length
103
- value = value[0..@display_length-1]
104
- end
105
- # added 2010-09-27 11:05 TO UNCOMMENT AND TEST IT OUT
106
- if @justify == :center
107
- value = value.center(@display_length)
108
- end
109
- end
110
- len = @display_length || value.length
111
- #$log.debug " XXX @display_length: #{@display_length}, #{value.length}, L:#{len}, pw:#{@parent.width} ::attr:: #{@attr} "
112
- graphic.printstring r, c, @format % [len, value], @color_pair, @attr
113
- end # repaint
114
-
115
- # @deprecated
116
- # only for older code that may have extended this.
117
- def prepare_default_colors focussed, selected
118
- @color_pair = get_color $datacolor
119
- @attr = @row_attr || Ncurses::A_NORMAL
120
-
121
-
122
- ## determine bg and fg and attr
123
- if selected
124
- @attr = Ncurses::A_BOLD if selected
125
- @color_pair =get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor unless @parent.nil?
126
- end
127
- case focussed
128
- when :SOFT_FOCUS
129
- @attr |= Ncurses::A_BOLD
130
- when true
131
- @attr |= Ncurses::A_REVERSE
132
- when false
133
- end
134
- #if focussed
135
- #@attr |= Ncurses::A_REVERSE
136
- #end
137
- end
138
- end # class
139
-
140
- end # module
@@ -1,310 +0,0 @@
1
- # Some methods for manipulating lists
2
- # Different components may bind different keys to these
3
- # Currently will be called by TextArea and the editable version
4
- # of TextView (vieditable).
5
- #
6
- require 'rbcurse/rinputdataevent'
7
- module ListEditable
8
-
9
- def remove_all
10
- @list = []
11
- set_modified # added 2009-02-13 22:28 so repaints
12
- end
13
- # current behav is a mix of vim's D and C-k from alpine, i don;t know how i screwed it up like this
14
- # Should be:
15
- # 1. do not take cursor back by 1 (this is vims D behavior)
16
- # 2. retain EOL, we need to evaluate at undo
17
- # 3. if nothing coming in delete buffer then join next line here
18
- # 4. if line is blank, it will go to delete line (i think).
19
- # Earlier, a C-k at pos 0 would blank the line and not delete it (copied from alpine).
20
- # The next C-k would delete. emacs deletes if C-k at pos 0.
21
- def delete_eol
22
- return -1 unless @editable
23
- pos = @curpos -1 # retain from 0 till prev char
24
- @delete_buffer = @buffer[@curpos..-1]
25
- # currently eol is there in delete_buff often. Should i maintain it ? 2010-03-08 18:29 UNDO
26
- #@delete_buffer.chomp! # new 2010-03-08 18:29 UNDO - this worked but hope does not have othe impact
27
-
28
- # if pos is 0, pos-1 becomes -1, end of line!
29
- @list[@current_index] = pos == -1 ? "" : @buffer[0..pos]
30
- $log.debug "delete EOL :pos=#{pos}, #{@delete_buffer}: row: #{@list[@current_index]}:"
31
- @buffer = @list[@current_index]
32
- if @delete_buffer == ""
33
- $log.debug " TA: DELETE going to join next "
34
- join_next_line # pull next line in
35
- end
36
- oldcur = @curpos
37
- #x cursor_backward if @curpos > 0 # this was vims behavior -- knoecked off
38
- #fire_handler :CHANGE, self # 2008-12-09 14:56
39
- fire_handler :CHANGE, InputDataEvent.new(oldcur,oldcur+@delete_buffer.length, self, :DELETE, @current_index, @delete_buffer) # 2008-12-24 18:34
40
- set_modified
41
- return @delete_buffer
42
- end
43
- def join_next_line
44
- # return if last line TODO
45
- buff = @list.delete_at(@current_index + 1)
46
- if buff
47
- $log.debug " TA: DELETE inside to join next #{buff} "
48
- fire_handler :CHANGE, InputDataEvent.new(0,0+buff.length, self, :DELETE_LINE, @current_index+1, buff)
49
- @buffer << buff
50
- end
51
- end
52
- # deletes given line or current
53
- # now fires DELETE_LINE so no guessing by undo manager
54
- def delete_line line=@current_index
55
- return -1 unless @editable
56
- if !$multiplier or $multiplier == 0
57
- @delete_buffer = @list.delete_at line
58
- else
59
- @delete_buffer = @list.slice!(line, $multiplier)
60
- end
61
- $multiplier = 0
62
- add_to_kill_ring @delete_buffer
63
- @buffer = @list[@current_index]
64
- if @buffer.nil?
65
- up
66
- setrowcol @row + 1, nil # @form.col
67
- end
68
- # warning: delete buffer can now be an array
69
- fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE_LINE, line, @delete_buffer) # 2008-12-24 18:34
70
- set_modified
71
- end
72
- def delete_curr_char num=($multiplier == 0 ? 1 : $multiplier)
73
- return -1 unless @editable
74
- delete_at @curpos, num # changed so only one event, and one undo
75
- set_modified
76
- $multiplier = 0
77
- end
78
- #
79
- # 2010-03-08 23:30 does not seem to be working well when backspacing at first char of line
80
- # FIXME should work as a unit, so one undo and one fire_handler, at least if on one line.
81
- def delete_prev_char num=($multiplier == 0 ? 1 : $multiplier)
82
- return -1 if !@editable
83
- num.times do
84
- if @curpos <= 0
85
- join_to_prev_line
86
- return
87
- end
88
- @curpos -= 1 if @curpos > 0
89
- delete_at
90
- set_modified
91
- addcol -1
92
- end
93
- $multiplier = 0
94
- end
95
- # open a new line and add chars to it.
96
- # FIXME does not fire handler, thus won't undo
97
- def append_row lineno=@current_index, chars=""
98
- $log.debug "append row sapce:#{chars}."
99
- @list.insert lineno+1, chars
100
- end
101
- ##
102
- # delete character/s on current line
103
- def delete_at index=@curpos, howmany=1
104
- return -1 if !@editable
105
- $log.debug "delete_at (characters) : #{@current_index} #{@buffer} #{index}"
106
- char = @buffer.slice!(@curpos,howmany) # changed added ,1 and take char for event
107
- # if no newline at end of this then bring up prev character/s till maxlen
108
- # NO WE DON'T DO THIS ANYLONGER 2008-12-26 21:09 lets see
109
- =begin
110
- if @buffer[-1,1]!="\r"
111
- @buffer[-1]=" " if @buffer[-1,1]=="\n"
112
- if !next_line.nil? and next_line.length > 0
113
- move_chars_up
114
- end
115
- end
116
- =end
117
- set_modified true
118
- fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+howmany, self, :DELETE, @current_index, char) # 2008-12-24 18:34
119
- end
120
- def undo_handler(uh)
121
- @undo_handler = uh
122
- end
123
- ## THIS ONE SHOULD BE IN TEXTVIEW ALSO
124
- # saves current or n lines into kill ring, appending to earlier contents
125
- # Use yank (paste) or yank-pop to retrieve
126
- def kill_ring_save
127
- pointer = @current_index
128
- list = []
129
- repeatm {
130
- line = @list[pointer]
131
- list << line unless line.nil?
132
- pointer += 1
133
- }
134
- add_to_kill_ring list
135
- end
136
- ## THIS ONE SHOULD BE IN TEXTVIEW ALSO
137
- # add given line or lines to kill_ring
138
- def add_to_kill_ring list
139
- # directly referenceing kill_ring. We need to OO it a bit, so we can change internals w'o breaking all.
140
- # FIXME
141
- if $append_next_kill
142
- # user requested this kill to be appened to last kill, so it can be yanked as one
143
- #$kill_ring.last << list
144
- last = $kill_ring.pop
145
- $log.debug "YANK: addto : last= #{last} , list= #{list} "
146
- case list
147
- when Array
148
- #list.insert 0, last
149
- list.insert 0, *last # 2011-10-10 changed as it was wrong in textarea
150
- $kill_ring << list
151
- when String
152
- $kill_ring << [last, list]
153
- end
154
- else
155
- $kill_ring << list
156
- end
157
- $kill_ring_pointer = $kill_ring.size
158
- $append_next_kill = false
159
- $log.debug "YANK: kill_ring: #{$kill_ring} "
160
- end
161
-
162
- # pastes recent (last) entry of kill_ring.
163
- # This can be one or more lines. Please note that for us vimmer's yank means copy
164
- # but for emacsers it seems to mean paste. Aargh!!
165
- def yank where=@current_index
166
- return -1 if !@editable
167
- return if $kill_ring.empty?
168
- row = $kill_ring.last
169
- $log.debug "YANK: row #{row} "
170
- index = where
171
- case row
172
- when Array
173
- #index = @current_index
174
- row.each{ |r|
175
- @list.insert index, r.dup
176
- index += 1
177
- }
178
- $kill_last_pop_size = row.size
179
- when String
180
- #@list[@current_index].insert row.dup
181
- #@list.insert @current_index, row.dup
182
- @list.insert index, row.dup
183
- $kill_last_pop_size = 1
184
- else
185
- raise "textarea yank got uncertain datatype from kill_ring #{row.class} "
186
- end
187
- $kill_ring_pointer = $kill_ring.size - 1
188
- $kill_ring_index = @current_index # pops will replace data in this row, never an insert
189
- @repaint_required = true
190
- # XXX not firing anything here, so i can't undo. yet, i don't know whether a yank will
191
- # be followed by a yank-pop, in which case it will not be undone.
192
- # object row can be string or array - time to use INSERT_LINE so we are clear
193
- # row.length can be array's size or string length - beware
194
- fire_handler :CHANGE, InputDataEvent.new(0,row.length, self, :INSERT_LINE, @current_index, row)
195
- end
196
-
197
- # paste previous entries from kill ring
198
- # I am not totally clear on this, not being an emacs user. but seems you have to do C-y
199
- # once (yank) before you can do a yank pop.
200
- def yank_pop
201
- return -1 if !@editable
202
- return if $kill_ring.empty?
203
- mapped_key = @current_key # we are mapped to this
204
- # checking that user has done a yank on this row. We only replace on the given row, never
205
- # insert. But what if user edited after yank, Sheesh ! XXX
206
- if $kill_ring_index != @current_index
207
- Ncurses.beep
208
- return # error message required that user must yank first
209
- end
210
- # the real reason i put this into a loop is so that i can properly undo the
211
- # action later if required. I only need to store the final selection.
212
- # This also ensures the user doesn't wander off in between and come back.
213
- row = nil
214
- while true
215
- # remove lines from last replace, then insert
216
- index = @current_index
217
- $kill_last_pop_size.times {
218
- del = @list.delete_at index
219
- }
220
- row = $kill_ring[$kill_ring_pointer-$multiplier]
221
- $multiplier = 0
222
- index = @current_index
223
- case row
224
- when Array
225
- row.each{ |r|
226
- @list.insert index, r.dup
227
- index += 1
228
- }
229
- $kill_last_pop_size = row.size
230
- when String
231
- @list.insert index, row.dup
232
- $kill_last_pop_size = 1
233
- else
234
- raise "textarea yank_pop got uncertain datatype from kill_ring #{row.class} "
235
- end
236
-
237
- $kill_ring_pointer -= 1
238
- if $kill_ring_pointer < 0
239
- # should be size, but that'll give an error. need to find a way!
240
- $kill_ring_pointer = $kill_ring.size - 1
241
- end
242
- @repaint_required = true
243
- my_win = @form || @parent_component.form # 2010-02-12 12:51
244
- my_win.repaint
245
- ch = @graphic.getchar
246
- if ch != mapped_key
247
- @graphic.ungetch ch # seems to work fine
248
- return ch # XXX to be picked up by handle_key loop and processed
249
- end
250
- end
251
- # object row can be string or array - time to use INSERT_LINE so we are clear
252
- # row.length can be array's size or string length - beware
253
- fire_handler :CHANGE, InputDataEvent.new(0,row.length, self, :INSERT_LINE, @current_index, row)
254
- return 0
255
- end
256
- def append_next_kill
257
- $append_next_kill = true
258
- end
259
- # deletes count words on current line
260
- # Does not at this point go beyond the line
261
- def delete_word
262
- return -1 unless @editable
263
- $multiplier = 1 if !$multiplier or $multiplier == 0
264
- line = @current_index
265
- pos = @curpos
266
- @delete_buffer = ""
267
- # currently only look in current line
268
- $multiplier.times {
269
- found = @buffer.index(/[[:punct:][:space:]]/, pos)
270
- break if !found
271
- $log.debug " delete_word: pos #{pos} found #{found} buff: #{@buffer} "
272
- @delete_buffer << @buffer.slice!(pos..found)
273
- }
274
- return if @delete_buffer == ""
275
- $log.debug " delete_word: delbuff #{@delete_buffer} "
276
- add_to_kill_ring @delete_buffer
277
- fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, line, @delete_buffer) # 2008-12-24 18:34
278
- set_modified
279
- end
280
- ##
281
- # deletes forward till the occurence of a character
282
- # it gets the char from the user
283
- # Should we pass in the character (and accept it as a separate func) ???
284
- def delete_forward
285
- return -1 unless @editable
286
- ch = @graphic.getchar
287
- return if ch < 0 || ch > 255
288
- char = ch.chr
289
- $multiplier = 1 if !$multiplier or $multiplier == 0
290
- line = @current_index
291
- pos = @curpos
292
- tmpbuf = ""
293
- # currently only look in current line
294
- $multiplier.times {
295
- found = @buffer.index(char, pos)
296
- break if !found
297
- #$log.debug " delete_forward: pos #{pos} found #{found} buff: #{@buffer} "
298
- # ideally do this in one shot outside loop, but its okay here for now
299
- tmpbuf << @buffer.slice!(pos..found)
300
- }
301
- return if tmpbuf == ""
302
- @delete_buffer = tmpbuf
303
- $log.debug " delete_forward: delbuff #{@delete_buffer} "
304
- add_to_kill_ring @delete_buffer
305
- fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, line, @delete_buffer) # 2008-12-24 18:34
306
- set_modified
307
- $multiplier = 0
308
- end
309
-
310
- end # end module