Class: RubyCurses::OldTextArea
- Includes:
- Scrollable
- Defined in:
- lib/rbcurse/rform.rb
Overview
a multiline text editing widget TODO - giving data to user - adding newlines, and withog adding.
- respect newlines for incoming data
Constant Summary
Constants included from Io
Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR
Instance Attribute Summary collapse
-
#modified ⇒ Object
boolean, value modified or not 2009-01-08 12:29.
-
#prow ⇒ Object
readonly
Returns the value of attribute prow.
-
#toprow ⇒ Object
readonly
Returns the value of attribute toprow.
-
#winrow ⇒ Object
readonly
Returns the value of attribute winrow.
Attributes inherited from Widget
#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #state
Instance Method Summary collapse
-
#<<(data) ⇒ Object
wraps line sent in if longer than maxlen Typically a line is sent in.
- #addcol(num) ⇒ Object
- #addrowcol(row, col) ⇒ Object
- #append_row(lineno = @prow, chars = "") ⇒ Object
- #buffer_len ⇒ Object
- #current_line ⇒ Object
- #cursor_backward ⇒ Object
- #cursor_bol ⇒ Object
- #cursor_bounds_check ⇒ Object
- #cursor_eol ⇒ Object
- #cursor_forward(num = 1) ⇒ Object
-
#delete_at(index = @curpos) ⇒ Object
DELETE func.
- #delete_curr_char(num = 1) ⇒ Object
- #delete_eol ⇒ Object
- #delete_line(line = @prow) ⇒ Object
- #delete_prev_char(num = 1) ⇒ Object
-
#do_current_row {|| ... } ⇒ Object
:yields current row.
- #do_relative_row(num) {|| ... } ⇒ Object
-
#get_content ⇒ Object
FOR scrollable ###.
- #get_window ⇒ Object
- #getvalue ⇒ Object
-
#handle_key(ch) ⇒ Object
textarea.
-
#initialize(form, config = {}, &block) ⇒ OldTextArea
constructor
A new instance of OldTextArea.
-
#insert(off0, data) ⇒ Object
trying to wrap and insert.
- #insert_break ⇒ Object
-
#insert_wrap(lineno, pos, lastchars) ⇒ Object
this attempts to recursively insert into a row, seeing that any stuff exceeding is pushed down further.
-
#join_to_prev_line ⇒ Object
private when backspace pressed in position zero if the previous line is filled we may have to bring down the last word and join, rather than go up.
-
#move_char_up ⇒ Object
move up one char from next row to current, used when deleting in a line should not be called if line ends in “r”.
-
#move_chars_up ⇒ Object
tries to move up as many as possible should not be called if line ends in “r”.
-
#next_line ⇒ Object
returns next line, does not move to it,.
-
#Oinsert(off0, *data) ⇒ Object
this avoids wrapping.
-
#print_borders ⇒ Object
private.
-
#print_foot ⇒ Object
text_area print footer.
-
#print_title ⇒ Object
private.
-
#push_last_word(lineno = @prow) ⇒ Object
push the last word from given line to next I have modified it to push all words that are exceeding maxlen.
- #putc(c) ⇒ Object
-
#putch(char) ⇒ Object
add one char.
- #remove_all ⇒ Object
-
#remove_last_word(lineno) ⇒ Object
removes and returns last word in given line number, or nil if no whitespace.
-
#repaint ⇒ Object
FOR scrollable ###.
- #rowcol ⇒ Object
-
#set_form_col(col1 = @curpos) ⇒ Object
set cursor on correct column.
-
#set_form_row ⇒ Object
puts cursor on correct row.
- #set_modified(tf = true) ⇒ Object
- #to_s ⇒ Object
- #undo_delete ⇒ Object
-
#words_in_length(buff, len) ⇒ Object
return as many words as fit into len for carrying up..
- #wrap_para(line = @prow) ⇒ Object
-
#wrap_text(txt, col = @maxlen) ⇒ Object
private.
Methods included from Scrollable
#down, #focussed_index, #goto_end, #goto_start, #init_scrollable, #left, #next_match, #paint, #post_key, #pre_key, #right, #scroll_backward, #scroll_forward, #scrollable_handle_key, #selected_item, #set_focus_on, #set_selection_for_char, #show_focus, #show_focus_on_row, #up
Methods inherited from Widget
#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #getvalue_for_paint, #height, #height=, #hide, #init_vars, #is_double_buffered?, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #safe_create_buffer, #set_buffer_modified, #set_buffering, #set_form, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Methods included from DSL
Constructor Details
#initialize(form, config = {}, &block) ⇒ OldTextArea
Returns a new instance of OldTextArea.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rbcurse/rform.rb', line 52 def initialize form, config={}, &block @focusable = true @editable = true @left_margin = 1 @row = 0 @col = 0 @curpos = 0 @show_focus = false @list = [] super @row_offset = @col_offset = 1 @orig_col = @col # this does result in a blank line if we insert after creating. That's required at # present if we wish to only insert if @list.empty? @list << "\r" end @scrollatrow = @height-2 @content_rows = @list.length @win = @form.window init_scrollable print_borders @maxlen ||= @width-2 end |
Instance Attribute Details
#modified ⇒ Object
boolean, value modified or not 2009-01-08 12:29
50 51 52 |
# File 'lib/rbcurse/rform.rb', line 50 def modified @modified end |
#prow ⇒ Object (readonly)
Returns the value of attribute prow.
45 46 47 |
# File 'lib/rbcurse/rform.rb', line 45 def prow @prow end |
#toprow ⇒ Object (readonly)
Returns the value of attribute toprow.
44 45 46 |
# File 'lib/rbcurse/rform.rb', line 44 def toprow @toprow end |
#winrow ⇒ Object (readonly)
Returns the value of attribute winrow.
46 47 48 |
# File 'lib/rbcurse/rform.rb', line 46 def winrow @winrow end |
Instance Method Details
#<<(data) ⇒ Object
wraps line sent in if longer than maxlen Typically a line is sent in. We wrap and put a hard return at end.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rbcurse/rform.rb', line 115 def << data if data.length > @maxlen $log.debug "wrapped append for #{data}" data = wrap_text data $log.debug "after wrap text for :#{data}" data = data.split("\n") # 2009-01-01 22:24 the \n was needed so we would put a space at time of writing. # we need a soft return so a space can be added when pushing down. # commented off 2008-12-28 21:59 #data.each {|line| @list << line+"\n"} data.each {|line| @list << line} @list[-1] << "\r" #XXXX else $log.debug "normal append for #{data}" data << "\r" if data[-1,1] != "\r" #XXXX @list << data end goto_end if @auto_scroll # to test out. self end |
#addcol(num) ⇒ Object
339 340 341 |
# File 'lib/rbcurse/rform.rb', line 339 def addcol num @form.addcol num end |
#addrowcol(row, col) ⇒ Object
342 343 344 |
# File 'lib/rbcurse/rform.rb', line 342 def addrowcol row,col @form.addrowcol row, col end |
#append_row(lineno = @prow, chars = "") ⇒ Object
519 520 521 522 |
# File 'lib/rbcurse/rform.rb', line 519 def append_row lineno=@prow, chars="" $log.debug "append row sapce:#{chars}." @list.insert lineno+1, chars end |
#buffer_len ⇒ Object
307 308 309 |
# File 'lib/rbcurse/rform.rb', line 307 def buffer_len @list[@prow].nil? ? 0 : @list[@prow].chomp().length end |
#current_line ⇒ Object
592 593 594 |
# File 'lib/rbcurse/rform.rb', line 592 def current_line @list[@prow] end |
#cursor_backward ⇒ Object
345 346 347 348 349 350 351 352 353 |
# File 'lib/rbcurse/rform.rb', line 345 def cursor_backward if @curpos > 0 @curpos -= 1 addcol -1 else # trying this out 2008-12-26 20:18 ret = up cursor_eol if ret != -1 end end |
#cursor_bol ⇒ Object
606 607 608 |
# File 'lib/rbcurse/rform.rb', line 606 def cursor_bol set_form_col 0 end |
#cursor_bounds_check ⇒ Object
303 304 305 306 |
# File 'lib/rbcurse/rform.rb', line 303 def cursor_bounds_check max = buffer_len() @curpos = max if @curpos > max # check 2008-12-27 00:02 end |
#cursor_eol ⇒ Object
602 603 604 605 |
# File 'lib/rbcurse/rform.rb', line 602 def cursor_eol $log.error "ERROR !!! bufferlen gt maxlen #{@buffer.length}, #{@maxlen}" if @buffer.length > @maxlen set_form_col current_line().chomp().length()-1 end |
#cursor_forward(num = 1) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/rbcurse/rform.rb', line 327 def cursor_forward num=1 $log.debug "next char cp #{@curpos}, #{@buffer.length}. wi: #{@width}" #if @curpos < @width and @curpos < @maxlen-1 # else it will do out of box if @curpos < buffer_len() @curpos += 1 addcol 1 else # trying this out 2008-12-26 20:18 @curpos = 0 down end cursor_bounds_check end |
#delete_at(index = @curpos) ⇒ Object
DELETE func
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/rbcurse/rform.rb', line 551 def delete_at index=@curpos return -1 if !@editable $log.debug "dele : #{@prow} #{@buffer} #{index}" char = @buffer.slice!(@curpos,1) # changed added ,1 and take char for event # if no newline at end of this then bring up prev character/s till maxlen # NO WE DON'T DO THIS ANYLONGER 2008-12-26 21:09 lets see =begin if @buffer[-1,1]!="\r" @buffer[-1]=" " if @buffer[-1,1]=="\n" if !next_line.nil? and next_line.length > 0 move_chars_up end end =end #@modified = true 2008-12-22 15:31 set_modified true #fire_handler :CHANGE, self # 2008-12-09 14:56 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, @prow, char) # 2008-12-24 18:34 end |
#delete_curr_char(num = 1) ⇒ Object
366 367 368 369 370 371 372 |
# File 'lib/rbcurse/rform.rb', line 366 def delete_curr_char num=1 return -1 unless @editable num.times do delete_at set_modified end end |
#delete_eol ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/rbcurse/rform.rb', line 314 def delete_eol return -1 unless @editable pos = @curpos-1 @delete_buffer = @buffer[@curpos..-1] # if pos is 0, pos-1 becomes -1, end of line! @list[@prow] = pos == -1 ? "" : @buffer[0..pos] $log.debug "delete EOL :pos=#{pos}, #{@delete_buffer}: row: #{@list[@prow]}:" @buffer = @list[@prow] cursor_backward if @curpos > 0 # now cursor back goes up to prev line #fire_handler :CHANGE, self # 2008-12-09 14:56 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, @prow, @delete_buffer) # 2008-12-24 18:34 return @delete_buffer end |
#delete_line(line = @prow) ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/rbcurse/rform.rb', line 354 def delete_line line=@prow return -1 unless @editable $log.debug "called delete line" @delete_buffer = @list.delete_at line @buffer = @list[@prow] if @buffer.nil? up @form.row = @row + 1 + @winrow end #fire_handler :CHANGE, self # 2008-12-09 14:56 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, @prow, @delete_buffer) # 2008-12-24 18:34 end |
#delete_prev_char(num = 1) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/rbcurse/rform.rb', line 373 def delete_prev_char num=1 return -1 if !@editable num.times do if @curpos <= 0 join_to_prev_line return end @curpos -= 1 if @curpos > 0 delete_at set_modified addcol -1 end end |
#do_current_row {|| ... } ⇒ Object
:yields current row
310 311 312 313 |
# File 'lib/rbcurse/rform.rb', line 310 def do_current_row # :yields current row yield @list[@prow] @buffer = @list[@prow] end |
#do_relative_row(num) {|| ... } ⇒ Object
595 596 597 |
# File 'lib/rbcurse/rform.rb', line 595 def do_relative_row num yield @list[@prow+num] end |
#get_content ⇒ Object
FOR scrollable ###
183 184 185 |
# File 'lib/rbcurse/rform.rb', line 183 def get_content @list end |
#get_window ⇒ Object
186 187 188 |
# File 'lib/rbcurse/rform.rb', line 186 def get_window @form.window end |
#getvalue ⇒ Object
194 195 196 |
# File 'lib/rbcurse/rform.rb', line 194 def getvalue @list end |
#handle_key(ch) ⇒ Object
textarea
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/rbcurse/rform.rb', line 199 def handle_key ch @buffer = @list[@prow] if @buffer.nil? and @list.length == 0 @list << "\n" # changed space to newline so wrapping puts a line. @buffer = @list[@prow] end return if @buffer.nil? $log.debug "TA: before: curpos #{@curpos} blen: #{@buffer.length}" # on any line if the cursor is ahead of buffer length, ensure its on last position # what if the buffer is somehow gt maxlen ?? if @curpos > @buffer.length addcol(@buffer.length-@curpos)+1 @curpos = @buffer.length end $log.debug "TA: after : curpos #{@curpos} blen: #{@buffer.length}, w: #{@width} max #{@maxlen}" pre_key case ch when ?\C-n.getbyte(0) scroll_forward when ?\C-p.getbyte(0) scroll_backward when ?\C-[.getbyte(0) goto_start #cursor_start of buffer when ?\C-].getbyte(0) goto_end # cursor_end of buffer when KEY_UP #select_prev_row ret = up when KEY_DOWN ret = down when KEY_ENTER, 10, 13 insert_break when KEY_LEFT cursor_backward when KEY_RIGHT cursor_forward when KEY_BACKSPACE, 127 if @editable # checking here means that i can programmatically bypass!! delete_prev_char #fire_handler :CHANGE, self # 2008-12-22 15:23 end when 330, ?\C-d.getbyte(0) # delete char if @editable delete_curr_char #fire_handler :CHANGE, self # 2008-12-22 15:23 end when ?\C-k.getbyte(0) # delete till eol if @editable if @buffer == "" delete_line #fire_handler :CHANGE, self # 2008-12-22 15:23 else delete_eol #fire_handler :CHANGE, self # 2008-12-22 15:23 end end when ?\C-u.getbyte(0) undo_delete when ?\C-a.getbyte(0) cursor_bol when ?\C-e.getbyte(0) cursor_eol #set_form_col @buffer.length else #$log.debug(" textarea ch #{ch}") ret = putc ch return ret if ret == :UNHANDLED end post_key set_form_row set_form_col # testing 2008-12-26 19:37 end |
#insert(off0, data) ⇒ Object
trying to wrap and insert
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbcurse/rform.rb', line 97 def insert off0, data if data.length > @maxlen data = wrap_text data # $log.debug "after wrap text done :#{data}" data = data.split("\n") data[-1] << "\r" #XXXX else data << "\r" if data[-1,1] != "\r" #XXXX end data.each do |row| @list.insert off0, row off0 += 1 end #$log.debug " AFTER INSERT: #{@list}" end |
#insert_break ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/rbcurse/rform.rb', line 276 def insert_break return -1 unless @editable # insert a blank row and append rest of this line to cursor $log.debug "ENTER PRESSED at #{@curpos}, on row #{@prow}" @delete_buffer = (delete_eol || "") @list[@prow] << "\r" $log.debug "DELETE BUFFER #{@delete_buffer}" @list.insert @prow+1, @delete_buffer @curpos = 0 down @form.col = @orig_col + @col_offset #addrowcol 1,0 @form.row = @row + 1 + @winrow #fire_handler :CHANGE, self # 2008-12-09 14:56 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, @prow, @delete_buffer) # 2008-12-24 18:34 end |
#insert_wrap(lineno, pos, lastchars) ⇒ Object
this attempts to recursively insert into a row, seeing that any stuff exceeding is pushed down further. Yes, it should check for a para end and insert. Currently it could add to next para.
479 480 481 482 483 484 485 |
# File 'lib/rbcurse/rform.rb', line 479 def insert_wrap lineno, pos, lastchars @list[lineno].insert pos, lastchars len = @list[lineno].length if len > @maxlen push_last_word lineno #- sometime i may push down 10 chars but the last word is less end end |
#join_to_prev_line ⇒ Object
private when backspace pressed in position zero if the previous line is filled we may have to bring down the last word and join, rather than go up
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/rbcurse/rform.rb', line 389 def join_to_prev_line return -1 unless @editable return if @prow == 0 oldcurpos = @curpos oldprow = @prow prev = @list[@prow-1].chomp prevlen = prev.length # 2008-12-26 21:37 delete previous line if nothing there. This moves entire buffer up. if prevlen == 0 delete_line @prow-1 up return end space_left = @maxlen - prev.length # BUG. carry full words up, or if no space then bring down last word of prev lien and join with first carry_up = words_in_length @buffer, space_left #@buffer[0..space_left] # XXX if carry_up.nil? # carry down last word prev_wd = remove_last_word @prow-1 @buffer.insert 0, prev_wd @curpos = prev_wd.length $log.debug " carry up nil! prev_wd (#{prev_wd}) len:#{prev_wd.length}" fire_handler :CHANGE, InputDataEvent.new(0,prev_wd.length, self, :INSERT, oldprow, prev_wd) # 2008-12-26 23:07 else $log.debug " carrying up #{carry_up.length} #{carry_up}, space: #{space_left}" @list[@prow-1]=prev + carry_up space_left2 = @buffer[(carry_up.length+1)..-1] @list[@prow]=space_left2 #if !space_left2.nil? @list[@prow] ||= "" up addrowcol -1,0 @curpos = prevlen fire_handler :CHANGE, InputDataEvent.new(oldcurpos,carry_up.length, self, :DELETE, oldprow, carry_up) # 2008-12-24 18:34 fire_handler :CHANGE, InputDataEvent.new(prevlen,carry_up.length, self, :INSERT, oldprow-1, carry_up) # 2008-12-24 18:34 end @form.col = @orig_col + @col_offset + @curpos # $log.debug "carry up: nil" if carry_up.nil? # $log.debug "listrow nil " if @list[@prow].nil? # $log.debug "carry up: #{carry_up} prow:#{@list[@prow]}" end |
#move_char_up ⇒ Object
move up one char from next row to current, used when deleting in a line should not be called if line ends in “r”
572 573 574 575 |
# File 'lib/rbcurse/rform.rb', line 572 def move_char_up @list[@prow] << @list[@prow+1].slice!(0) delete_line(@prow+1) if next_line().length==0 end |
#move_chars_up ⇒ Object
tries to move up as many as possible should not be called if line ends in “r”
578 579 580 581 582 583 584 585 586 587 |
# File 'lib/rbcurse/rform.rb', line 578 def move_chars_up oldprow = @prow oldcurpos = @curpos space_left = @maxlen - @buffer.length can_move = [space_left, next_line.length].min carry_up = @list[@prow+1].slice!(0, can_move) @list[@prow] << carry_up delete_line(@prow+1) if next_line().length==0 fire_handler :CHANGE, InputDataEvent.new(oldcurpos,oldcurpos+can_move, self, :INSERT, oldprow, carry_up) # 2008-12-24 18:34 end |
#next_line ⇒ Object
returns next line, does not move to it,
589 590 591 |
# File 'lib/rbcurse/rform.rb', line 589 def next_line @list[@prow+1] end |
#Oinsert(off0, *data) ⇒ Object
this avoids wrapping. Better to use the <<.
82 83 84 85 |
# File 'lib/rbcurse/rform.rb', line 82 def Oinsert off0, *data @list.insert off0, *data # fire_handler :CHANGE, self # 2008-12-09 14:56 NOT SURE end |
#print_borders ⇒ Object
private
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/rbcurse/rform.rb', line 155 def print_borders window = @form.window color = $datacolor window.print_border @row, @col, @height, @width, color print_title =begin hline = "+%s+" % [ "-"*(width-((1)*2)) ] hline2 = "|%s|" % [ " "*(width-((1)*2)) ] window.printstring( row=startrow, col=startcol, hline, color) print_title (startrow+1).upto(startrow+height-1) do |row| window.printstring(row, col=startcol, hline2, color) end window.printstring(startrow+height, col=startcol, hline, color) =end end |
#print_foot ⇒ Object
text_area print footer
177 178 179 180 181 |
# File 'lib/rbcurse/rform.rb', line 177 def print_foot @footer_attrib ||= Ncurses::A_REVERSE = "R: #{@prow+1}, C: #{@curpos}, #{@list.length} lines " @form.window.printstring( @row + @height, @col+2, , $datacolor, @footer_attrib) end |
#print_title ⇒ Object
private
173 174 175 |
# File 'lib/rbcurse/rform.rb', line 173 def print_title @form.window.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil? end |
#push_last_word(lineno = @prow) ⇒ Object
push the last word from given line to next I have modified it to push all words that are exceeding maxlen. This was needed for if i push 10 chars to next line, and the last word is less then the line will exceed. So i must push as many words as exceed length.
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/rbcurse/rform.rb', line 447 def push_last_word lineno=@prow #lastspace = @buffer.rindex(" ") #lastspace = @list[lineno].rindex(/ \w/) line = @list[lineno] line = @list[lineno][0..@maxlen+1] if line.length > @maxlen lastspace = line.rindex(/ \w/) $log.debug " PUSH:2 #{lastspace},#{line}," if !lastspace.nil? lastchars = @list[lineno][lastspace+1..-1] @list[lineno] = @list[lineno][0..lastspace] $log.debug "PUSH_LAST:ls:#{lastspace},lw:#{lastchars},lc:#{lastchars[-1]},:#{@list[lineno]}$" if lastchars[-1,1] == "\r" or @list[lineno+1].nil? # open a new line and keep the 10 at the end. append_row lineno, lastchars else # check for soft tab \n - NO EVEN THIS LOGIC IS WRONG. #if lastchars[-1,1] == "\n" if lastchars[-1,1] != ' ' and @list[lineno+1][0,1] !=' ' #@list[lineno+1].insert 0, lastchars + ' ' insert_wrap lineno+1, 0, lastchars + ' ' else #@list[lineno+1].insert 0, lastchars insert_wrap lineno+1, 0, lastchars end end return lastchars, lastspace end return nil end |
#putc(c) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/rbcurse/rform.rb', line 539 def putc c if c >= 32 and c <= 126 ret = putch c.chr if ret == 0 # addcol 1 set_modified return 0 end end return :UNHANDLED end |
#putch(char) ⇒ Object
add one char. careful, i shoved a string in yesterday.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/rbcurse/rform.rb', line 488 def putch char @buffer ||= @list[@prow] return -1 if !@editable #or @buffer.length >= @maxlen if @chars_allowed != nil return if char.match(@chars_allowed).nil? end raise "putch expects only one char" if char.length != 1 oldcurpos = @curpos $log.debug "putch : pr:#{@prow}, cp:#{@curpos}, char:#{char}, lc:#{@buffer[-1]}, buf:(#{@buffer})" @buffer.insert(@curpos, char) @curpos += 1 $log.debug "putch INS: cp:#{@curpos}, max:#{@maxlen}, buf:(#{@buffer.length})" if @curpos-1 > @maxlen or @buffer.length()-1 > @maxlen lastchars, lastspace = push_last_word @prow #$log.debug "last sapce #{lastspace}, lastchars:#{lastchars},lc:#{lastchars[-1]}, #{@list[@prow]} " ## wrap on word XX If last char is 10 then insert line @buffer = @list[@prow] if @curpos-1 > @maxlen or @curpos-1 > @buffer.length()-1 ret = down # keep the cursor in the same position in the string that was pushed down. @curpos = oldcurpos - lastspace #lastchars.length # 0 end end set_form_row @buffer = @list[@prow] set_form_col @modified = true #fire_handler :CHANGE, self # 2008-12-09 14:56 fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :INSERT, @prow, char) # 2008-12-24 18:34 0 end |
#remove_all ⇒ Object
92 93 94 |
# File 'lib/rbcurse/rform.rb', line 92 def remove_all @list = [] end |
#remove_last_word(lineno) ⇒ Object
removes and returns last word in given line number, or nil if no whitespace
525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/rbcurse/rform.rb', line 525 def remove_last_word lineno @list[lineno].chomp! line=@list[lineno] lastspace = line.rindex(" ") if !lastspace.nil? lastchars = line[lastspace+1..-1] @list[lineno].slice!(lastspace..-1) $log.debug " remove_last: lastspace #{lastspace},#{lastchars},#{@list[lineno]}" fire_handler :CHANGE, InputDataEvent.new(lastspace,lastchars.length, self, :DELETE, lineno, lastchars) # 2008-12-26 23:06 return lastchars end return nil end |
#repaint ⇒ Object
FOR scrollable ###
190 191 192 193 |
# File 'lib/rbcurse/rform.rb', line 190 def repaint # textarea paint print_foot if @print_footer end |
#rowcol ⇒ Object
76 77 78 79 |
# File 'lib/rbcurse/rform.rb', line 76 def rowcol # $log.debug "textarea rowcol : #{@row+@row_offset+@winrow}, #{@col+@col_offset}" return @row+@row_offset+@winrow, @col+@col_offset end |
#set_form_col(col1 = @curpos) ⇒ Object
set cursor on correct column
297 298 299 300 301 302 |
# File 'lib/rbcurse/rform.rb', line 297 def set_form_col col1=@curpos @curpos = col1 cursor_bounds_check @form.col = @orig_col + @col_offset + @curpos $log.debug "sfc: #{@orig_col}, #{@col_offset}. #{@curpos}. " end |
#set_form_row ⇒ Object
puts cursor on correct row.
293 294 295 |
# File 'lib/rbcurse/rform.rb', line 293 def set_form_row @form.row = @row + 1 + @winrow end |
#set_modified(tf = true) ⇒ Object
598 599 600 601 |
# File 'lib/rbcurse/rform.rb', line 598 def set_modified tf=true @modified = tf @form.modified = true if tf end |
#to_s ⇒ Object
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/rbcurse/rform.rb', line 609 def to_s l = getvalue str = "" old = " " l.each_with_index do |line, i| tmp = line.gsub("\n","") tmp.gsub!("\r", "\n") if old[-1,1] !~ /\s/ and tmp[0,1] !~ /\s/ str << " " end str << tmp old = tmp end str end |
#undo_delete ⇒ Object
271 272 273 274 275 |
# File 'lib/rbcurse/rform.rb', line 271 def undo_delete # added 2008-11-27 12:43 paste delete buffer into insertion point @buffer.insert @curpos, @delete_buffer unless @delete_buffer.nil? fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, @prow, @delete_buffer) # 2008-12-24 18:34 end |
#words_in_length(buff, len) ⇒ Object
return as many words as fit into len for carrying up.. actually there is a case of when the next char (len+1) is a white space or word boundary. XXX
433 434 435 436 437 438 439 440 441 442 |
# File 'lib/rbcurse/rform.rb', line 433 def words_in_length buff, len return nil if len == 0 str = buff[0..len] ix = str.rindex(/\s/) $log.debug " str #{str} len #{len} ix #{ix} , buff #{buff}~" return nil if ix.nil? ix = ix > 0 ? ix - 1 : ix $log.debug " str[]:#{str[0..ix]}~ len #{len} ix #{ix} , buff #{buff}~" return str[0..ix] end |
#wrap_para(line = @prow) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rbcurse/rform.rb', line 135 def wrap_para line=@prow line ||= 0 l=[] while true if @list[line].nil? or @list[line]=="" or @list[line]==13 #"\r" break end $log.debug "lastchar #{@list[line][-1]}, appending: #{@list[line]}]" t = @list[line] l << t.strip @list.delete_at line break if t[-1]==13 # "\r" # line += 1 end str=l.join(" ") $log.debug " sending insert : #{str}." insert line, str end |
#wrap_text(txt, col = @maxlen) ⇒ Object
private
87 88 89 90 91 |
# File 'lib/rbcurse/rform.rb', line 87 def wrap_text(txt, col = @maxlen) $log.debug "inside wrap text for :#{txt}" txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3\n") end |