Class: RubyCurses::TextView
- Includes:
- ListScrollable
- Defined in:
- lib/rbcurse/rtextview.rb
Overview
A viewable read only box. Can scroll. Intention is to be able to change content dynamically - the entire list. Use set_content to set content, or just update the list attrib TODO -
- goto line - DONE
Direct Known Subclasses
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
-
#current_index ⇒ Object
readonly
Returns the value of attribute current_index.
-
#toprow ⇒ Object
readonly
the toprow in the view (offsets are 0).
-
#winrow ⇒ Object
readonly
attr_reader :prow # the row on which cursor/focus is.
Attributes included from ListScrollable
#find_offset, #find_offset1, #search_found_ix, #show_caret
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #parent_component, #row_offset, #rows_panned, #state
Instance Method Summary collapse
-
#addcol(num) ⇒ Object
2010-01-23 22:41.
-
#addrowcol(row, col) ⇒ Object
:nodoc:.
-
#check_curpos ⇒ Object
newly added to check curpos when moving up or down.
- #current_value ⇒ Object
-
#cursor_backward ⇒ Object
:nodoc:.
-
#cursor_forward ⇒ Object
:nodoc:.
-
#disp_menu ⇒ Object
this is just a test of the simple “most” menu How can application add to this, or override.
- #do_relative_row(num) {|| ... } ⇒ Object deprecated Deprecated.
-
#find_first_match(regex) ⇒ Object
returns row of first match of given regex (or nil if not found).
-
#fire_action_event ⇒ Object
on pressing ENTER we send user some info, the calling program would bind :PRESS – FIXME we can create this once and reuse ++.
-
#get_content ⇒ Object
FOR scrollable ###.
-
#get_window ⇒ Object
:nodoc:.
-
#getstr(prompt, maxlen = 10) ⇒ Object
this is just a test of prompting user for a string + as an alternative to the dialog.
- #getvalue ⇒ Object
-
#handle_key(ch) ⇒ Object
textview.
-
#init_vars ⇒ Object
:nodoc:.
-
#initialize(form = nil, config = {}, &block) ⇒ TextView
constructor
A new instance of TextView.
-
#load_module(requirename, includename) ⇒ Object
dynamically load a module and execute init method.
- #map_keys ⇒ Object
- #next_line ⇒ Object deprecated Deprecated.
-
#on_enter ⇒ Object
added 2010-09-30 18:48 so standard with other components, esp on enter.
-
#on_enter_row(arow) ⇒ Object
called by listscrollable, used by scrollbar ENTER_ROW.
-
#paint ⇒ Object
NOTE: earlier print_border was called only once in constructor, but when + a window is resized, and destroyed, then this was never called again, so the + border would not be seen in splitpane unless the width coincided exactly with + what is calculated in divider_location.
- #pipe_file ⇒ Object
-
#pipe_output(pipeto, str) ⇒ Object
returns array of lines after running command on string passed TODO: need to close pipe other’s we’ll have a process lying around forever.
-
#print_borders ⇒ Object
print a border Note that print_border clears the area too, so should be used sparingly.
-
#print_foot ⇒ Object
:nodoc:.
-
#print_title ⇒ Object
:nodoc:.
- #remove_all ⇒ Object
-
#repaint ⇒ Object
textview :nodoc:.
- #row_count ⇒ Object
-
#rowcol ⇒ Object
returns the position where cursor was to be positioned by default It may no longer work like that.
-
#sanitize(content) ⇒ Object
takes a block, this way anyone extending this class can just pass a block to do his job This modifies the string.
- #saveas(name = nil, config = {}) ⇒ Object
-
#scrollatrow ⇒ Object
—- for listscrollable —- ##.
-
#set_content(list, wrap = :WRAP_NONE) ⇒ Object
send in a list e.g.
-
#set_form_col(col1 = @curpos) ⇒ Object
set cursor on correct column tview.
-
#top_row(*val) ⇒ Object
display this row on top.
-
#truncate(content) ⇒ Object
returns only the visible portion of string taking into account display length and horizontal scrolling.
-
#wrap_text(txt, col = @maxlen) ⇒ Object
:nodoc:.
Methods included from ListScrollable
#_find_next, #_find_prev, #ask_search, #bounds_check, #find_more, #find_next, #find_prev, #focussed_index, #forward_char, #forward_word, #goto_bottom, #goto_last_position, #goto_top, #install_keys, #next_match, #next_row, #previous_row, #scroll_backward, #scroll_forward, #scroll_left, #scroll_right, #selected_item, #set_focus_on, #set_form_row, #set_selection_for_char, #show_caret_func
Methods inherited from Widget
#changed, #click, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #height, #height=, #hide, #leave, #modified?, #move, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #set_buffer_modified, #set_buffering, #set_form, #set_form_row, #set_modified, #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, #warn
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Constructor Details
#initialize(form = nil, config = {}, &block) ⇒ TextView
Returns a new instance of TextView.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rbcurse/rtextview.rb', line 53 def initialize form = nil, config={}, &block @focusable = true @editable = false @sanitization_required = true @suppress_borders = false @row_offset = @col_offset = 1 @row = 0 @col = 0 @show_focus = false # don't highlight row under focus @list = [] super # ideally this should have been 2 to take care of borders, but that would break # too much stuff ! @win = @graphic @_events.push :CHANGE # thru vieditable @_events << :PRESS # new, in case we want to use this for lists and allow ENTER @_events << :ENTER_ROW # new, should be there in listscrollable ?? install_keys # do something about this nonsense FIXME init_vars map_keys end |
Instance Attribute Details
#current_index ⇒ Object (readonly)
Returns the value of attribute current_index.
49 50 51 |
# File 'lib/rbcurse/rtextview.rb', line 49 def current_index @current_index end |
#toprow ⇒ Object (readonly)
the toprow in the view (offsets are 0)
43 44 45 |
# File 'lib/rbcurse/rtextview.rb', line 43 def toprow @toprow end |
#winrow ⇒ Object (readonly)
attr_reader :prow # the row on which cursor/focus is
45 46 47 |
# File 'lib/rbcurse/rtextview.rb', line 45 def winrow @winrow end |
Instance Method Details
#addcol(num) ⇒ Object
2010-01-23 22:41
389 390 391 392 393 394 395 396 397 |
# File 'lib/rbcurse/rtextview.rb', line 389 def addcol num #:nodoc: #@repaint_required = true @repaint_footer_required = true # 2010-01-23 22:41 if @form @form.addcol num else @parent_component.form && @parent_component.form.addcol(num) end end |
#addrowcol(row, col) ⇒ Object
:nodoc:
398 399 400 401 402 403 404 405 406 |
# File 'lib/rbcurse/rtextview.rb', line 398 def addrowcol row,col #:nodoc: #@repaint_required = true @repaint_footer_required = true # 2010-01-23 22:41 if @form @form.addrowcol row, col else @parent_component.form.addrowcol num end end |
#check_curpos ⇒ Object
newly added to check curpos when moving up or down
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/rbcurse/rtextview.rb', line 334 def check_curpos #:nodoc: @buffer = @list[@current_index] # if the cursor is ahead of data in this row then move it back if @pcol+@curpos > @buffer.length addcol((@pcol+@buffer.length-@curpos)+1) @curpos = @buffer.length maxlen = (@maxlen || @width-@internal_width) # even this row is gt maxlen, i.e., scrolled right if @curpos > maxlen @pcol = @curpos - maxlen @curpos = maxlen-1 else # this row is within maxlen, make scroll 0 @pcol=0 end set_form_col end end |
#current_value ⇒ Object
229 230 231 |
# File 'lib/rbcurse/rtextview.rb', line 229 def current_value @list[@current_index] end |
#cursor_backward ⇒ Object
:nodoc:
407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/rbcurse/rtextview.rb', line 407 def cursor_backward #:nodoc: repeatm { if @curpos > 0 @curpos -= 1 set_form_col #addcol -1 elsif @pcol > 0 @pcol -= 1 end } #@repaint_required = true @repaint_footer_required = true # 2010-01-23 22:41 end |
#cursor_forward ⇒ Object
:nodoc:
375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/rbcurse/rtextview.rb', line 375 def cursor_forward #:nodoc: maxlen = @maxlen || @width-@internal_width repeatm { if @curpos < @width and @curpos < maxlen-1 # else it will do out of box @curpos += 1 addcol 1 else @pcol += 1 if @pcol <= @buffer.length end } set_form_col #@repaint_required = true @repaint_footer_required = true # 2010-01-23 22:41 end |
#disp_menu ⇒ Object
this is just a test of the simple “most” menu How can application add to this, or override
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/rbcurse/rtextview.rb', line 537 def #:nodoc: require 'rbcurse/extras/menutree' # we need to put this into data-structure so that i can be manipulated by calling apps # This should not be at the widget level, too many types of menus. It should be at the app # level only if the user wants his app to use this kind of menu. @menu = RubyCurses::MenuTree.new "Main", { s: :goto_start, r: :scroll_right, l: :scroll_left, m: :submenu } @menu. :m, "submenu", {s: :noignorecase, t: :goto_last_position, f: :next3 } = PromptMenu.new self . @menu =begin menu = PromptMenu.new self menu.add( menu.create_mitem( 's', "Goto start ", "Going to start", Proc.new { goto_start} )) menu.add(menu.create_mitem( 'r', "scroll right", "I have scrolled ", :scroll_right )) menu.add(menu.create_mitem( 'l', "scroll left", "I have scrolled ", :scroll_left )) item = menu.create_mitem( 'm', "submenu", "submenu options" ) menu1 = PromptMenu.new( self, "Submenu Options") menu1.add(menu1.create_mitem( 's', "CASE sensitive", "Ignoring Case in search" )) menu1.add(menu1.create_mitem( 't', "goto last position", "moved to previous position", Proc.new { goto_last_position} )) item.action = menu1 menu.add(item) # how do i know what's available. the application or window should know where to place #menu.display @form.window, 23, 1, $datacolor #, menu =end .display @form.window, $error_message_row, $error_message_col, $datacolor #, menu end |
#do_relative_row(num) {|| ... } ⇒ Object
426 427 428 |
# File 'lib/rbcurse/rtextview.rb', line 426 def do_relative_row num #:nodoc: yield @list[@current_index+num] end |
#find_first_match(regex) ⇒ Object
returns row of first match of given regex (or nil if not found)
158 159 160 161 162 163 |
# File 'lib/rbcurse/rtextview.rb', line 158 def find_first_match regex #:nodoc: @list.each_with_index do |row, ix| return ix if !row.match(regex).nil? end return nil end |
#fire_action_event ⇒ Object
on pressing ENTER we send user some info, the calling program would bind :PRESS – FIXME we can create this once and reuse ++
577 578 579 580 581 |
# File 'lib/rbcurse/rtextview.rb', line 577 def fire_action_event require 'rbcurse/ractionevent' aev = TextActionEvent.new self, :PRESS, current_value(), @current_index, @curpos fire_handler :PRESS, aev end |
#get_content ⇒ Object
FOR scrollable ###
211 212 213 |
# File 'lib/rbcurse/rtextview.rb', line 211 def get_content @list end |
#get_window ⇒ Object
:nodoc:
214 215 216 |
# File 'lib/rbcurse/rtextview.rb', line 214 def get_window #:nodoc: @graphic end |
#getstr(prompt, maxlen = 10) ⇒ Object
this is just a test of prompting user for a string + as an alternative to the dialog.
525 526 527 528 529 530 531 532 533 534 |
# File 'lib/rbcurse/rtextview.rb', line 525 def getstr prompt, maxlen=10 #:nodoc: tabc = Proc.new {|str| Dir.glob(str +"*") } config={}; config[:tab_completion] = tabc config[:default] = "default" $log.debug " inside getstr before call " ret, str = rbgetstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config) $log.debug " rbgetstr returned #{ret} , #{str} " return "" if ret != 0 return str end |
#getvalue ⇒ Object
226 227 228 |
# File 'lib/rbcurse/rtextview.rb', line 226 def getvalue @list end |
#handle_key(ch) ⇒ Object
textview
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/rbcurse/rtextview.rb', line 233 def handle_key ch #:nodoc: $log.debug " textview got ch #{ch} " @buffer = @list[@current_index] if @buffer.nil? and row_count == 0 @list << "\r" @buffer = @list[@current_index] end return if @buffer.nil? #$log.debug " before: curpos #{@curpos} blen: #{@buffer.length}" if @curpos > @buffer.length addcol((@buffer.length-@curpos)+1) @curpos = @buffer.length set_form_col end # We can improve later case ch when ?\C-n.getbyte(0), 32 scroll_forward when ?\C-p.getbyte(0) scroll_backward when ?\C-[.getbyte(0), ?t.getbyte(0) goto_start #start of buffer # cursor_start when ?\C-].getbyte(0), ?G.getbyte(0) goto_end # end / bottom cursor_end when KEY_UP, ?k.getbyte(0) #select_prev_row ret = up get_window.ungetch(KEY_BTAB) if ret == :NO_PREVIOUS_ROW check_curpos when KEY_DOWN, ?j.getbyte(0) ret = down get_window.ungetch(KEY_TAB) if ret == :NO_NEXT_ROW check_curpos when KEY_LEFT, ?h.getbyte(0) cursor_backward when KEY_RIGHT, ?l.getbyte(0) cursor_forward when KEY_BACKSPACE, KEY_BSPACE, KEY_DELETE cursor_backward when ?\C-a.getbyte(0) #, ?0.getbyte(0) # take care of data that exceeds maxlen by scrolling and placing cursor at start @repaint_required = true if @pcol > 0 # tried other things but did not work set_form_col 0 @pcol = 0 when ?\C-e.getbyte(0), ?$.getbyte(0) # take care of data that exceeds maxlen by scrolling and placing cursor at end # This use to actually pan the screen to actual end of line, but now somewhere # it only goes to end of visible screen, set_form probably does a sanity check blen = @buffer.rstrip.length set_form_col blen # search related when @KEY_ASK_FIND ask_search when @KEY_FIND_MORE find_more when 10, 13, KEY_ENTER #fire_handler :PRESS, self fire_action_event when ?0.getbyte(0)..?9.getbyte(0) # FIXME the assumption here was that if numbers are being entered then a 0 is a number # not a beg-of-line command. # However, after introducing universal_argument, we can enters numbers using C-u and then press another # C-u to stop. In that case a 0 should act as a command, even though multiplier has been set if ch == ?0.getbyte(0) and $multiplier == 0 # copy of C-a - start of line @repaint_required = true if @pcol > 0 # tried other things but did not work set_form_col 0 @pcol = 0 return 0 end # storing digits entered so we can multiply motion actions $multiplier *= 10 ; $multiplier += (ch-48) return 0 #when ?\C-u.getbyte(0) ## multiplier. Series is 4 16 64 #@multiplier = (@multiplier == 0 ? 4 : @multiplier *= 4) #return 0 when ?\M-l.getbyte(0) # just added 2010-03-05 not perfect scroll_right # scroll data horizontally when ?\M-h.getbyte(0) scroll_left when ?\C-c.getbyte(0) $multiplier = 0 return 0 else # check for bindings, these cannot override above keys since placed at end begin ret = process_key ch, self rescue => err $log.error " TEXTVIEW ERROR #{err} " $log.debug(err.backtrace.join("\n")) alert err.to_s end return :UNHANDLED if ret == :UNHANDLED end $multiplier = 0 # you must reset if you've handled a key. if unhandled, don't reset since parent could use set_form_row return 0 # added 2010-01-12 22:17 else down arrow was going into next field end |
#init_vars ⇒ Object
:nodoc:
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rbcurse/rtextview.rb', line 75 def init_vars #:nodoc: @curpos = @pcol = @toprow = @current_index = 0 @repaint_all=true @repaint_required=true ## 2010-02-10 20:20 RFED16 taking care if no border requested @row_offset = @col_offset = 0 if @suppress_borders == true # added 2010-02-11 15:11 RFED16 so we don't need a form. @win_left = 0 @win_top = 0 $error_message_row ||= 23 $error_message_col ||= 1 # currently i scroll right only if current line is longer than display width, i should use # longest line on screen. @longest_line = 0 # the longest line printed on this page, used to determine if scrolling shd work @internal_width = 2 @internal_width = 0 if @suppress_borders end |
#load_module(requirename, includename) ⇒ Object
dynamically load a module and execute init method. Hopefully, we can get behavior like this such as vieditable or multibuffers
567 568 569 570 571 |
# File 'lib/rbcurse/rtextview.rb', line 567 def load_module requirename, includename require "rbcurse/#{requirename}" extend Object.const_get("#{includename}") send("#{requirename}_init") #if respond_to? "#{includename}_init" end |
#map_keys ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rbcurse/rtextview.rb', line 93 def map_keys bind_key([?g,?g]){ goto_start } # mapping double keys like vim bind_key([?',?']){ goto_last_position } # vim , goto last row position (not column) bind_key(?/, :ask_search) bind_key(?n, :find_more) bind_key([?\C-x, ?>], :scroll_right) bind_key([?\C-x, ?<], :scroll_left) bind_key([?\C-x, ?\C-s], :saveas) bind_key(?r) { getstr("Enter a word: ") } bind_key(?m, :disp_menu) end |
#next_line ⇒ Object
gives offset of next line, does not move
422 423 424 |
# File 'lib/rbcurse/rtextview.rb', line 422 def next_line #:nodoc: @list[@current_index+1] end |
#on_enter ⇒ Object
added 2010-09-30 18:48 so standard with other components, esp on enter
588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/rbcurse/rtextview.rb', line 588 def on_enter if @list.nil? || @list.size == 0 Ncurses.beep return :UNHANDLED end on_enter_row @current_index set_form_row @repaint_required = true super true end |
#on_enter_row(arow) ⇒ Object
called by listscrollable, used by scrollbar ENTER_ROW
583 584 585 586 |
# File 'lib/rbcurse/rtextview.rb', line 583 def on_enter_row arow fire_handler :ENTER_ROW, self @repaint_required = true end |
#paint ⇒ Object
NOTE: earlier print_border was called only once in constructor, but when + a window is resized, and destroyed, then this was never called again, so the + border would not be seen in splitpane unless the width coincided exactly with + what is calculated in divider_location.
434 435 436 437 438 439 440 441 442 443 444 445 446 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 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/rbcurse/rtextview.rb', line 434 def paint #:nodoc: my_win = nil if @form my_win = @form.window else my_win = @target_window end @graphic = my_win unless @graphic @win_left = my_win.left @win_top = my_win.top print_borders if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes rc = row_count maxlen = @maxlen || @width-@internal_width #$log.debug " #{@name} textview repaint width is #{@width}, height is #{@height} , maxlen #{maxlen}/ #{@maxlen}, #{@graphic.name} roff #{@row_offset} coff #{@col_offset}" tm = get_content tr = @toprow acolor = get_color $datacolor h = scrollatrow() r,c = rowcol @longest_line = @width-@internal_width #maxlen 0.upto(h) do |hh| crow = tr+hh if crow < rc #focussed = @current_index == crow ? true : false #selected = is_row_selected crow content = tm[crow] # next call modified string. you may wanna dup the string. # rlistbox does # scrolling fails if you do not dup, since content gets truncated content = content.dup sanitize content if @sanitization_required truncate content @graphic.printstring r+hh, c, "%-*s" % [@width-@internal_width,content], acolor, @attr # highlighting search results. if @search_found_ix == tr+hh if !@find_offset.nil? # handle exceed bounds, and if scrolling if @find_offset1 < maxlen+@pcol and @find_offset > @pcol @graphic.mvchgat(y=r+hh, x=c+@find_offset-@pcol, @find_offset1-@find_offset, Ncurses::A_NORMAL, $reversecolor, nil) end end end else # clear rows @graphic.printstring r+hh, c, " " * (@width-@internal_width), acolor,@attr end end #show_caret_func #@table_changed = false @repaint_required = false @repaint_footer_required = true @repaint_all = false end |
#pipe_file ⇒ Object
599 600 601 602 603 604 605 |
# File 'lib/rbcurse/rtextview.rb', line 599 def pipe_file # TODO ask process name from user output = pipe_output 'munpack', @list if output && !output.empty? set_content output end end |
#pipe_output(pipeto, str) ⇒ Object
returns array of lines after running command on string passed TODO: need to close pipe other’s we’ll have a process lying around forever.
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/rbcurse/rtextview.rb', line 609 def pipe_output (pipeto, str) case str when String #str = str.split "\n" # okay when Array str = str.join "\n" end #pipeto = '/usr/sbin/sendmail -t' #pipeto = %q{mail -s "my title" rahul} if pipeto != nil # i was taking pipeto from a hash, so checking proc = IO.popen(pipeto, "w+") proc.puts str proc.close_write proc.readlines end end |
#print_borders ⇒ Object
print a border Note that print_border clears the area too, so should be used sparingly.
177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rbcurse/rtextview.rb', line 177 def print_borders #:nodoc: raise "textview needs width" unless @width raise "textview needs height" unless @height $log.debug " #{@name} print_borders, #{@graphic.name} " @color_pair = get_color($datacolor) # added 2011-09-28 as in rlistbox # bordercolor = @border_color || $datacolor # changed 2011 dts bordercolor = @border_color || @color_pair # 2011-09-28 V1.3.1 borderatt = @border_attrib || Ncurses::A_NORMAL @graphic.print_border @row, @col, @height-1, @width, bordercolor, borderatt print_title end |
#print_foot ⇒ Object
:nodoc:
203 204 205 206 207 208 209 |
# File 'lib/rbcurse/rtextview.rb', line 203 def print_foot #:nodoc: @footer_attrib ||= Ncurses::A_REVERSE = "R: #{@current_index+1}, C: #{@curpos+@pcol}, #{@list.length} lines " #$log.debug " print_foot calling printstring with #{@row} + #{@height} -1, #{@col}+2" @graphic.printstring( @row + @height -1 , @col+2, , @color_pair || $datacolor, @footer_attrib) @repaint_footer_required = false # 2010-01-23 22:55 end |
#print_title ⇒ Object
:nodoc:
190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/rbcurse/rtextview.rb', line 190 def print_title #:nodoc: return unless @title raise "textview needs width" unless @width @color_pair ||= get_color($datacolor) # should we not use this ??? XXX #$log.debug " print_title #{@row}, #{@col}, #{@width} " # check title.length and truncate if exceeds width _title = @title if @title.length > @width - 2 _title = @title[0..@width-2] end # @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless @title.nil? # changed 2011 dts @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil? end |
#remove_all ⇒ Object
131 132 133 134 135 |
# File 'lib/rbcurse/rtextview.rb', line 131 def remove_all @list = [] init_vars @repaint_required = true end |
#repaint ⇒ Object
textview :nodoc:
218 219 220 221 222 223 224 225 |
# File 'lib/rbcurse/rtextview.rb', line 218 def repaint # textview :nodoc: $log.debug "TEXTVIEW repaint r c #{@row}, #{@col} " #return unless @repaint_required # 2010-02-12 19:08 TRYING - won't let footer print for col move paint if @repaint_required # raise "TV 175 graphic nil " unless @graphic print_foot if @print_footer && !@suppress_borders && @repaint_footer_required end |
#row_count ⇒ Object
153 154 155 |
# File 'lib/rbcurse/rtextview.rb', line 153 def row_count @list.length end |
#rowcol ⇒ Object
returns the position where cursor was to be positioned by default It may no longer work like that.
166 167 168 |
# File 'lib/rbcurse/rtextview.rb', line 166 def rowcol #:nodoc: return @row+@row_offset, @col+@col_offset end |
#sanitize(content) ⇒ Object
takes a block, this way anyone extending this class can just pass a block to do his job This modifies the string
494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/rbcurse/rtextview.rb', line 494 def sanitize content #:nodoc: if content.is_a? String content.chomp! # trying out since gsub giving #<ArgumentError: invalid byte sequence in UTF-8> 2011-09-11 content = content.encode("ASCII-8BIT", :invalid => :replace, :undef => :replace, :replace => "?") content.gsub!(/[\t\n\r]/, ' ') # don't display tab content.gsub!(/[^[:print:]]/, '') # don't display non print characters else content end end |
#saveas(name = nil, config = {}) ⇒ Object
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/rbcurse/rtextview.rb', line 626 def saveas name=nil, config={} unless name name = @graphic.ask "File to save as: " return if name.nil? || name == "" end exists = File.exists? name if exists # need to prompt return unless @graphic.agree("Overwrite existing file? ", true) end l = getvalue File.open(name, "w"){ |f| l.each { |line| f.puts line } #l.each { |line| f.write line.gsub(/\r/,"\n") } } @graphic.say "#{name} written." end |
#scrollatrow ⇒ Object
—- for listscrollable —- ##
146 147 148 149 150 151 152 |
# File 'lib/rbcurse/rtextview.rb', line 146 def scrollatrow #:nodoc: if @suppress_borders @height - 1 # should be 2 FIXME but erasing lower line. see appemail else @height - 3 end end |
#set_content(list, wrap = :WRAP_NONE) ⇒ Object
send in a list e.g. set_content File.open(“README.txt”,“r”).readlines set wrap at time of passing :WRAP_NONE :WRAP_WORD XXX if we widen the textview later, as in a vimsplit that data will still be wrapped at this width !!
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rbcurse/rtextview.rb', line 110 def set_content list, wrap = :WRAP_NONE @wrap_policy = wrap if list.is_a? String if @wrap_policy == :WRAP_WORD data = wrap_text list @list = data.split("\n") else @list = list.split("\n") end elsif list.is_a? Array if @wrap_policy == :WRAP_WORD data = wrap_text list.join(" ") @list = data.split("\n") else @list = list end else raise "set_content expects Array not #{list.class}" end init_vars end |
#set_form_col(col1 = @curpos) ⇒ Object
set cursor on correct column tview
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/rbcurse/rtextview.rb', line 354 def set_form_col col1=@curpos #:nodoc: @cols_panned ||= 0 @pad_offset ||= 0 # added 2010-02-11 21:54 since padded widgets get an offset. @curpos = col1 maxlen = @maxlen || @width-@internal_width #@curpos = maxlen if @curpos > maxlen if @curpos > maxlen @pcol = @curpos - maxlen @curpos = maxlen - 1 @repaint_required = true # this is required so C-e can pan screen else @pcol = 0 end # the rest only determines cursor placement win_col = 0 # 2010-02-07 23:19 new cursor stuff col2 = win_col + @col + @col_offset + @curpos + @cols_panned + @pad_offset $log.debug "TV SFC #{@name} setting c to #{col2} #{win_col} #{@col} #{@col_offset} #{@curpos} " #@form.setrowcol @form.row, col setrowcol nil, col2 @repaint_footer_required = true end |
#top_row(*val) ⇒ Object
display this row on top
137 138 139 140 141 142 143 144 |
# File 'lib/rbcurse/rtextview.rb', line 137 def top_row(*val) #:nodoc: if val.empty? @toprow else @toprow = val[0] || 0 end @repaint_required = true end |
#truncate(content) ⇒ Object
returns only the visible portion of string taking into account display length and horizontal scrolling. MODIFIES STRING
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/rbcurse/rtextview.rb', line 507 def truncate content #:nodoc: _maxlen = @maxlen || @width-@internal_width _maxlen = @width-@internal_width if _maxlen > @width-@internal_width # take care of decrease in width if !content.nil? if content.length > _maxlen # only show maxlen @longest_line = content.length if content.length > @longest_line #content = content[@pcol..@pcol+maxlen-1] content.replace(content[@pcol..@pcol+_maxlen-1] || "") else if @pcol > 0 content.replace(content[@pcol..-1] || "") end end end content end |