Class: RubyCurses::TextPad
- Includes:
- BorderTitle
- Defined in:
- lib/rbcurse/core/widgets/textpad.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#current_index ⇒ Object
readonly
Returns the value of attribute current_index.
-
#lastcol ⇒ Object
readonly
adding these only for debugging table, to see where cursor is.
-
#lastrow ⇒ Object
readonly
adding these only for debugging table, to see where cursor is.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #parent_component, #row_offset, #rows_panned, #state
Instance Method Summary collapse
- #_convert_formatted ⇒ Object
- #_do_borders ⇒ Object
-
#ask_search(str = nil) ⇒ Object
Ask user for string to search for This uses the dialog, but what if user wants the old style.
- #backward_word ⇒ Object
- #bottom_of_window ⇒ Object
- #content ⇒ Object (also: #get_content)
-
#current_value ⇒ Object
returns current value (what cursor is on).
-
#cursor_backward ⇒ Object
move cursor backward by one char (currently will not pan).
-
#cursor_bol ⇒ Object
moves cursor to start of line, panning if required.
-
#cursor_eol ⇒ Object
moves cursor to end of line also panning window if necessary NOTE: if one line on another page (not displayed) is way longer than any displayed line, then this will pan way ahead, so may not be very intelligent in such situations.
-
#cursor_forward ⇒ Object
move cursor forward by one char (currently will not pan).
-
#destroy ⇒ Object
Now since we use get_pad from window, upon the window being destroyed, it will call this.
-
#down(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
move down a line mimicking vim’s j key.
-
#ensure_visible(row = @current_index) ⇒ Object
Ensure current row is visible, if not make it first row NOTE - need to check if its at end and then reduce scroll at rows, check_prow does that.
-
#filename(filename, reader = nil) ⇒ Object
supply a filename as source for textpad Reads up file into @content One can optionally send in a method which takes a filename and returns an array of data This is required if you are processing files which are binary such as zip/archives and wish to print the contents.
-
#find_more ⇒ Object
Find next matching row for string accepted in ask_search.
-
#fire_action_event ⇒ Object
event when user hits enter on a row, user would bind :PRESS.
-
#fire_dimension_changed ⇒ Object
to be called with program / user has added a row or changed column widths so that the pad needs to be recreated.
-
#fire_row_changed(ix) ⇒ Object
repaint only one row since content of that row has changed.
-
#formatted_text(text, fmt) ⇒ Object
pass in formatted text along with parser (:tmux or :ansi) NOTE this does not call init_vars, i think it should, text() does.
-
#forward_word ⇒ Object
jumps cursor to next work, like vim’s w key.
-
#goto_end ⇒ Object
goto last line of file.
- #goto_last_position ⇒ Object
- #goto_line(line) ⇒ Object
-
#goto_start ⇒ Object
goto first line of file.
- #handle_key(ch) ⇒ Object
- #init_vars ⇒ Object
-
#initialize(form = nil, config = {}, &block) ⇒ TextPad
constructor
for external methods or classes to advance cursor attr_accessor :curpos You may pass height, width, row and col for creating a window otherwise a fullscreen window will be created.
-
#is_visible?(index) ⇒ Boolean
return true if the given row is visible.
-
#map_keys ⇒ Object
key mappings.
- #middle_of_window ⇒ Object
-
#next_match(str) ⇒ Object
Find the next row that contains given string.
-
#on_enter ⇒ Object
called when this widget is entered, by form.
-
#on_enter_row(arow) ⇒ Object
execute binding when a row is entered, used more in lists to display some text in a header or footer as one traverses.
-
#padrefresh ⇒ Object
write pad onto window private.
-
#print(string, _width = @content_cols) ⇒ Object
2013-03-07 - 19:57 changed width to @content_cols since data not printing in some cases fully when ansi sequences were present int some line but not in others lines without ansi were printing less by a few chars.
-
#print_foot ⇒ Object
print footer containing line and position XXX UNTESTED TODO TESTING.
-
#render(pad, lineno, text) ⇒ Object
default method for rendering a line.
-
#renderer(r) ⇒ Object
supply a custom renderer that implements render().
-
#repaint ⇒ Object
may need to call padrefresh TODO TESTING.
-
#rowcol ⇒ Object
:nodoc:.
-
#scroll_backward ⇒ Object
scrolls lines backward a window full at a time, on pressing pageup C-u may not work since it is trapped by form earlier.
-
#scroll_forward ⇒ Object
scrolls lines a window full at a time, on pressing ENTER or C-d or pagedown.
-
#scroll_left ⇒ Object
to prevent right from retaining earlier painted values padreader does not do a clear, yet works fine.
- #scroll_right ⇒ Object
-
#scroll_window_down(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
scrolls window down mimicking vim C-e.
-
#scroll_window_up(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
scrolls window up mimicking vim C-y.
-
#set_form_col ⇒ Object
called by form.
-
#set_form_row ⇒ Object
called by form.
- #show_colored_chunks(chunks, defcolor = nil, defattr = nil) ⇒ Object
-
#text(lines, fmt = :none) ⇒ Object
(also: #list, #set_content)
display text given in an array format.
- #top_of_window ⇒ Object
-
#up(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
move up a line mimicking vim’s k key.
Methods included from BorderTitle
#bordertitle_init, #print_borders, #print_title
Methods inherited from Widget
#action_manager, #changed, #click, #color_pair, #command, #enter, #event_list, #focus, #get_preferred_size, #getvalue, #getvalue_for_paint, #height, #height=, #hide, #leave, #modified?, #move, #on_leave, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #set_buffer_modified, #set_buffering, #set_form, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn
Methods included from Utils
#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #wrap_text
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) ⇒ TextPad
for external methods or classes to advance cursor attr_accessor :curpos You may pass height, width, row and col for creating a window otherwise a fullscreen window will be created. If you pass a window from caller then that window will be used. Some keys are trapped, jkhl space, pgup, pgdown, end, home, t b This is currently very minimal and was created to get me started to integrating pads into other classes such as textview.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 48 def initialize form=nil, config={}, &block @editable = false @focusable = true @config = config @row = @col = 0 @prow = @pcol = 0 @startrow = 0 @startcol = 0 # @list is unused, think it can be removed #@list = [] super ## NOTE # --------------------------------------------------- # Since we are using pads, you need to get your height, width and rows correct # Make sure the height factors in the row, else nothing may show # --------------------------------------------------- #@height = @height.ifzero(FFI::NCurses.LINES) #@width = @width.ifzero(FFI::NCurses.COLS) @rows = @height @cols = @width # NOTE XXX if cols is > COLS then padrefresh can fail @startrow = @row @startcol = @col unless @suppress_borders @row_offset = @col_offset = 1 @startrow += 1 @startcol += 1 @rows -=3 # 3 is since print_border_only reduces one from width, to check whether this is correct @cols -=3 @scrollatrows = @height - 3 else # no borders printed @rows -= 1 # 3 is since print_border_only reduces one from width, to check whether this is correct ## if next is 0 then padrefresh doesn't print @cols -=1 @scrollatrows = @height - 1 # check this out 0 or 1 @row_offset = @col_offset = 0 end @top = @row @left = @col @lastrow = @row + @row_offset @lastcol = @col + @col_offset @_events << :PRESS @_events << :ENTER_ROW init_vars end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
38 39 40 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 38 def cols @cols end |
#current_index ⇒ Object (readonly)
Returns the value of attribute current_index.
37 38 39 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 37 def current_index @current_index end |
#lastcol ⇒ Object (readonly)
adding these only for debugging table, to see where cursor is.
40 41 42 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 40 def lastcol @lastcol end |
#lastrow ⇒ Object (readonly)
adding these only for debugging table, to see where cursor is.
40 41 42 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 40 def lastrow @lastrow end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
38 39 40 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 38 def rows @rows end |
Instance Method Details
#_convert_formatted ⇒ Object
398 399 400 401 402 403 404 405 406 407 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 398 def _convert_formatted if @formatted_text l = RubyCurses::Utils.parse_formatted_text(@color_parser, @formatted_text) text(l) @formatted_text = nil end end |
#_do_borders ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 381 def _do_borders unless @suppress_borders if @repaint_all ## XXX im not getting the background color. #@window.print_border_only @top, @left, @height-1, @width, $datacolor clr = get_color $datacolor, @color, @bgcolor #@window.print_border @top, @left, @height-1, @width, clr @window.print_border_only @top, @left, @height-1, @width, clr print_title @repaint_footer_required = true if @oldrow != @current_index print_foot if @print_footer && !@suppress_borders && @repaint_footer_required @window.wrefresh end end end |
#ask_search(str = nil) ⇒ Object
Ask user for string to search for This uses the dialog, but what if user wants the old style. Isn’t there a cleaner way to let user override style, or allow user to use own UI for getting pattern and then passing here.
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 776 def ask_search str=nil # the following is a change that enables callers to prompt for the string # using some other style, basically the classical style and send the string in str = get_string("Enter pattern: ") unless str return if str.nil? str = @last_regex if str == "" return if str == "" ix = next_match str return unless ix @last_regex = str #@oldindex = @current_index @current_index = ix[0] @curpos = ix[1] ensure_visible end |
#backward_word ⇒ Object
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 865 def backward_word $multiplier = 1 if !$multiplier || $multiplier == 0 line = @current_index buff = @content[line].to_s return unless buff pos = @curpos || 0 # list does not have curpos $multiplier.times { found = buff.rindex(/[[:punct:][:space:]]\w/, pos-2) if !found || found == 0 # if not found, we've lost a counter if pos > 0 pos = 0 elsif line > 0 line -= 1 pos = @content[line].to_s.size else return end else pos = found + 1 end $log.debug " backward_word: pos #{pos} line #{line} buff: #{buff}" } $multiplier = 0 @current_index = line @curpos = pos ensure_visible @repaint_required = true end |
#bottom_of_window ⇒ Object
484 485 486 487 488 489 490 491 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 484 def bottom_of_window @current_index = @prow + @scrollatrows $multiplier ||= 0 if $multiplier > 0 @current_index -= $multiplier $multiplier = 0 end end |
#content ⇒ Object Also known as: get_content
236 237 238 239 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 236 def content raise "content is nil " unless @content return @content end |
#current_value ⇒ Object
returns current value (what cursor is on)
661 662 663 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 661 def current_value @content[@current_index] end |
#cursor_backward ⇒ Object
move cursor backward by one char (currently will not pan)
909 910 911 912 913 914 915 916 917 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 909 def cursor_backward $multiplier = 1 if $multiplier == 0 if @curpos > 0 @curpos -= $multiplier @curpos = 0 if @curpos < 0 @repaint_required = true end $multiplier = 0 end |
#cursor_bol ⇒ Object
moves cursor to start of line, panning if required
930 931 932 933 934 935 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 930 def cursor_bol # copy of C-a - start of line @repaint_required = true if @pcol > 0 @pcol = 0 @curpos = 0 end |
#cursor_eol ⇒ Object
moves cursor to end of line also panning window if necessary NOTE: if one line on another page (not displayed) is way longer than any displayed line, then this will pan way ahead, so may not be very intelligent in such situations.
922 923 924 925 926 927 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 922 def cursor_eol # pcol is based on max length not current line's length @pcol = @content_cols - @cols - 1 @curpos = @content[@current_index].size @repaint_required = true end |
#cursor_forward ⇒ Object
move cursor forward by one char (currently will not pan)
896 897 898 899 900 901 902 903 904 905 906 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 896 def cursor_forward $multiplier = 1 if $multiplier == 0 if @curpos < @cols @curpos += $multiplier if @curpos > @cols @curpos = @cols end @repaint_required = true end $multiplier = 0 end |
#destroy ⇒ Object
Now since we use get_pad from window, upon the window being destroyed, it will call this. Else it will destroy pad
682 683 684 685 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 682 def destroy FFI::NCurses.delwin(@pad) if @pad # when do i do this ? FIXME @pad = nil end |
#down(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
move down a line mimicking vim’s j key
499 500 501 502 503 504 505 506 507 508 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 499 def down num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier) #@oldindex = @current_index if num > 10 @current_index += num # no , i don't like this here. it scrolls up too much making prow = current_index unless is_visible? @current_index @prow += num end #ensure_visible $multiplier = 0 end |
#ensure_visible(row = @current_index) ⇒ Object
Ensure current row is visible, if not make it first row NOTE - need to check if its at end and then reduce scroll at rows, check_prow does that
830 831 832 833 834 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 830 def ensure_visible row = @current_index unless is_visible? row @prow = @current_index end end |
#filename(filename, reader = nil) ⇒ Object
supply a filename as source for textpad Reads up file into @content One can optionally send in a method which takes a filename and returns an array of data This is required if you are processing files which are binary such as zip/archives and wish to print the contents. (e.g. cygnus gem sends in :get_file_contents).
filename("a.c", method(:get_file_contents))
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 192 def filename(filename, reader=nil) @file = filename unless File.exists? filename alert "#{filename} does not exist" return end @filetype = File.extname filename if reader @content = reader.call(filename) else @content = File.open(filename,"r").readlines end if @filetype == "" if @content.first.index("ruby") @filetype = ".rb" end end init_vars @repaint_all = true @_populate_needed = true end |
#find_more ⇒ Object
Find next matching row for string accepted in ask_search
795 796 797 798 799 800 801 802 803 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 795 def find_more return unless @last_regex ix = next_match @last_regex return unless ix #@oldindex = @current_index @current_index = ix[0] @curpos = ix[1] ensure_visible end |
#fire_action_event ⇒ Object
event when user hits enter on a row, user would bind :PRESS
653 654 655 656 657 658 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 653 def fire_action_event return if @content.nil? || @content.size == 0 require 'rbcurse/core/include/ractionevent' aev = TextActionEvent.new self, :PRESS, current_value().to_s, @current_index, @curpos fire_handler :PRESS, aev end |
#fire_dimension_changed ⇒ Object
to be called with program / user has added a row or changed column widths so that the pad needs to be recreated. However, cursor positioning is maintained since this is considered to be a minor change. We do not call init_vars since user is continuing to do some work on a row/col.
343 344 345 346 347 348 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 343 def fire_dimension_changed # recreate pad since width or ht has changed (row count or col width changed) @_populate_needed = true @repaint_required = true @repaint_all = true end |
#fire_row_changed(ix) ⇒ Object
repaint only one row since content of that row has changed. No recreate of pad is done.
351 352 353 354 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 351 def fire_row_changed ix render @pad, ix, @content[ix] # may need to call padrefresh TODO TESTING end |
#formatted_text(text, fmt) ⇒ Object
pass in formatted text along with parser (:tmux or :ansi) NOTE this does not call init_vars, i think it should, text() does
296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 296 def formatted_text text, fmt require 'rbcurse/core/include/chunk' @formatted_text = text @color_parser = fmt @repaint_required = true _convert_formatted # don't know if start is always required. so putting in caller #goto_start #remove_all end |
#forward_word ⇒ Object
jumps cursor to next work, like vim’s w key
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 838 def forward_word $multiplier = 1 if !$multiplier || $multiplier == 0 line = @current_index buff = @content[line].to_s return unless buff pos = @curpos || 0 # list does not have curpos $multiplier.times { found = buff.index(/[[:punct:][:space:]]\w/, pos) if !found # if not found, we've lost a counter if line+1 < @content.length line += 1 else return end pos = 0 else pos = found + 1 end $log.debug " forward_word: pos #{pos} line #{line} buff: #{buff}" } $multiplier = 0 @current_index = line @curpos = pos ensure_visible @repaint_required = true end |
#goto_end ⇒ Object
goto last line of file
457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 457 def goto_end #@oldindex = @current_index $multiplier ||= 0 if $multiplier > 0 goto_line $multiplier - 1 return end @current_index = @content.count() - 1 @prow = @current_index - @scrollatrows $multiplier = 0 end |
#goto_last_position ⇒ Object
561 562 563 564 565 566 567 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 561 def goto_last_position return unless @oldindex tmp = @current_index @current_index = @oldindex @oldindex = tmp bounds_check end |
#goto_line(line) ⇒ Object
468 469 470 471 472 473 474 475 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 468 def goto_line line ## we may need to calculate page, zfm style and place at right position for ensure visible #line -= 1 @current_index = line ensure_visible line bounds_check $multiplier = 0 end |
#goto_start ⇒ Object
goto first line of file
443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 443 def goto_start #@oldindex = @current_index $multiplier ||= 0 if $multiplier > 0 goto_line $multiplier - 1 return end @current_index = 0 @curpos = @pcol = @prow = 0 @prow = 0 $multiplier = 0 end |
#handle_key(ch) ⇒ Object
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 595 def handle_key ch return :UNHANDLED unless @content @oldrow = @prow @oldcol = @pcol $log.debug "XXX: PAD got #{ch} prow = #{@prow}" begin case ch when ?0.getbyte(0)..?9.getbyte(0) if ch == ?0.getbyte(0) && $multiplier == 0 cursor_bol return 0 end # storing digits entered so we can multiply motion actions $multiplier *= 10 ; $multiplier += (ch-48) return 0 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 $multiplier = 0 bounds_check ## If i press C-x > i get an alert from rwidgets which blacks the screen # if i put a padrefresh here it becomes okay but only for one pad, # i still need to do it for all pads. rescue => err $log.error " TEXTPAD ERROR INS #{err} " $log.debug(err.backtrace.join("\n")) textdialog ["Error in TextPad: #{err} ", *err.backtrace], :title => "Exception" end ## NOTE if textpad does not handle the event and it goes to form which pops # up a messagebox, then padrefresh does not happen, since control does not # come back here, so a black rect is left on screen # please note that a bounds check will not happen for stuff that # is triggered by form, so you'll have to to it yourself or # call setrowcol explicity if the cursor is not updated return :UNHANDLED if ret == :UNHANDLED end rescue => err $log.error " TEXTPAD ERROR 591 #{err} " $log.debug( err) if err $log.debug(err.backtrace.join("\n")) if err textdialog ["Error in TextPad: #{err} ", *err.backtrace], :title => "Exception" $error_message.value = "" ensure padrefresh Ncurses::Panel.update_panels end return 0 end |
#init_vars ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 96 def init_vars $multiplier = 0 @oldindex = @current_index = 0 # column cursor @prow = @pcol = @curpos = 0 if @row && @col @lastrow = @row + @row_offset @lastcol = @col + @col_offset end @repaint_required = true map_keys unless @mapped_keys end |
#is_visible?(index) ⇒ Boolean
return true if the given row is visible
688 689 690 691 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 688 def is_visible? index j = index - @prow #@toprow j >= 0 && j <= @scrollatrows end |
#map_keys ⇒ Object
key mappings
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 412 def map_keys @mapped_keys = true bind_key([?g,?g], 'goto_start'){ goto_start } # mapping double keys like vim bind_key(279, 'goto_start'){ goto_start } bind_keys([?G,277], 'goto end'){ goto_end } bind_keys([?k,KEY_UP], "Up"){ up } bind_keys([?j,KEY_DOWN], "Down"){ down } bind_key(?\C-e, "Scroll Window Down"){ scroll_window_down } bind_key(?\C-y, "Scroll Window Up"){ scroll_window_up } bind_keys([32,338, ?\C-d], "Scroll Forward"){ scroll_forward } bind_keys([?\C-b,339]){ scroll_backward } # the next one invalidates the single-quote binding for bookmarks #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(?\M-l, :scroll_right) bind_key(?\M-h, :scroll_left) bind_key(?L, :bottom_of_window) bind_key(?M, :middle_of_window) bind_key(?H, :top_of_window) bind_key(?w, :forward_word) bind_key(?b, :backward_word) bind_key(?l, :cursor_forward) bind_key(?h, :cursor_backward) bind_key(?$, :cursor_eol) bind_key(KEY_ENTER, :fire_action_event) end |
#middle_of_window ⇒ Object
492 493 494 495 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 492 def middle_of_window @current_index = @prow + (@scrollatrows/2) $multiplier = 0 end |
#next_match(str) ⇒ Object
Find the next row that contains given string
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 809 def next_match str first = nil ## content can be string or Chunkline, so we had to write <tt>index</tt> for this. ## =~ does not give an error, but it does not work. @content.each_with_index do |line, ix| col = line.index str if col first ||= [ ix, col ] if ix > @current_index return [ix, col] end end end return first end |
#on_enter ⇒ Object
called when this widget is entered, by form
694 695 696 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 694 def on_enter set_form_row end |
#on_enter_row(arow) ⇒ Object
execute binding when a row is entered, used more in lists to display some text in a header or footer as one traverses
668 669 670 671 672 673 674 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 668 def on_enter_row arow return if @content.nil? || @content.size == 0 require 'rbcurse/core/include/ractionevent' aev = TextActionEvent.new self, :ENTER_ROW, current_value().to_s, @current_index, @curpos fire_handler :ENTER_ROW, aev @repaint_required = true end |
#padrefresh ⇒ Object
write pad onto window private
310 311 312 313 314 315 316 317 318 319 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 310 def padrefresh top = @window.top left = @window.left sr = @startrow + top sc = @startcol + left retval = FFI::NCurses.prefresh(@pad,@prow,@pcol, sr , sc , @rows + sr , @cols+ sc ); $log.warn "XXX: PADREFRESH #{retval}, #{@prow}, #{@pcol}, #{sr}, #{sc}, #{@rows+sr}, #{@cols+sc}." if retval == -1 # padrefresh can fail if width is greater than NCurses.COLS #FFI::NCurses.prefresh(@pad,@prow,@pcol, @startrow + top, @startcol + left, @rows + @startrow + top, @cols+@startcol + left); end |
#print(string, _width = @content_cols) ⇒ Object
2013-03-07 - 19:57 changed width to @content_cols since data not printing in some cases fully when ansi sequences were present int some line but not in others lines without ansi were printing less by a few chars. This was prolly copied from rwindow, where it is okay since its for a specific width
260 261 262 263 264 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 260 def print(string, _width = @content_cols) #return unless visible? w = _width == 0? Ncurses.COLS : _width FFI::NCurses.waddnstr(@pad,string.to_s, w) # changed 2011 dts end |
#print_foot ⇒ Object
print footer containing line and position XXX UNTESTED TODO TESTING
244 245 246 247 248 249 250 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 244 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 |
#render(pad, lineno, text) ⇒ Object
default method for rendering a line
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 163 def render pad, lineno, text if text.is_a? Chunks::ChunkLine FFI::NCurses.wmove @pad, lineno, 0 a = get_attrib @attrib show_colored_chunks text, nil, a return end if @renderer @renderer.render @pad, lineno, text else ## messabox does have a method to paint the whole window in bg color its in rwidget.rb att = NORMAL FFI::NCurses.wattron(@pad, @cp | att) FFI::NCurses.mvwaddstr(@pad,lineno, 0, @clearstring) if @clearstring FFI::NCurses.mvwaddstr(@pad,lineno, 0, @content[lineno]) #FFI::NCurses.mvwaddstr(pad, lineno, 0, text) FFI::NCurses.wattroff(@pad, @cp | att) end end |
#renderer(r) ⇒ Object
supply a custom renderer that implements render()
157 158 159 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 157 def renderer r @renderer = r end |
#repaint ⇒ Object
may need to call padrefresh TODO TESTING
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 355 def repaint ## 2013-03-08 - 21:01 This is the fix to the issue of form callign an event like ? or F1 # which throws up a messagebox which leaves a black rect. We have no place to put a refresh # However, form does call repaint for all objects, so we can do a padref here. Otherwise, # it would get rejected. UNfortunately this may happen more often we want, but we never know # when something pops up on the screen. unless @repaint_required padrefresh return end # I can't recall why we are doing this late. Is the rreason relevant any longer # Some methods that expect data are crashing like tablewidgets model_row _convert_formatted @window ||= @graphic populate_pad if @_populate_needed #HERE we need to populate once so user can pass a renderer _do_borders padrefresh Ncurses::Panel.update_panels @repaint_required = false @repaint_all = false end |
#rowcol ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 108 def rowcol #:nodoc: return @row+@row_offset, @col+@col_offset end |
#scroll_backward ⇒ Object
scrolls lines backward a window full at a time, on pressing pageup C-u may not work since it is trapped by form earlier. Need to fix
556 557 558 559 560 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 556 def scroll_backward #@oldindex = @current_index @current_index -= @scrollatrows @prow = @current_index - @scrollatrows end |
#scroll_forward ⇒ Object
scrolls lines a window full at a time, on pressing ENTER or C-d or pagedown
548 549 550 551 552 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 548 def scroll_forward #@oldindex = @current_index @current_index += @scrollatrows @prow = @current_index - @scrollatrows end |
#scroll_left ⇒ Object
to prevent right from retaining earlier painted values padreader does not do a clear, yet works fine. OK it has an update_panel after padrefresh, that clears it seems. this clears entire window not just the pad FFI::NCurses.wclear(@window.get_window) so border and title is repainted after window clearing
Next line was causing all sorts of problems when scrolling with ansi formatted text
588 589 590 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 588 def scroll_left @pcol -= 1 end |
#scroll_right ⇒ Object
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 568 def scroll_right # I don't think it will ever be less since we've increased it to cols if @content_cols <= @cols maxpcol = 0 @pcol = 0 else maxpcol = @content_cols - @cols - 1 @pcol += 1 @pcol = maxpcol if @pcol > maxpcol end # to prevent right from retaining earlier painted values # padreader does not do a clear, yet works fine. # OK it has an update_panel after padrefresh, that clears it seems. #this clears entire window not just the pad #FFI::NCurses.wclear(@window.get_window) # so border and title is repainted after window clearing # # Next line was causing all sorts of problems when scrolling with ansi formatted text #@repaint_all = true end |
#scroll_window_down(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
scrolls window down mimicking vim C-e
527 528 529 530 531 532 533 534 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 527 def scroll_window_down num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier) @prow += num if @prow > @current_index @current_index += 1 end #check_prow $multiplier = 0 end |
#scroll_window_up(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
scrolls window up mimicking vim C-y
538 539 540 541 542 543 544 545 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 538 def scroll_window_up num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier) @prow -= num unless is_visible? @current_index # one more check may be needed here TODO @current_index -= num end $multiplier = 0 end |
#set_form_col ⇒ Object
called by form
702 703 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 702 def set_form_col end |
#set_form_row ⇒ Object
called by form
698 699 700 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 698 def set_form_row setrowcol @lastrow, @lastcol end |
#show_colored_chunks(chunks, defcolor = nil, defattr = nil) ⇒ Object
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 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 266 def show_colored_chunks(chunks, defcolor = nil, defattr = nil) #return unless visible? chunks.each do |chunk| #|color, chunk, attrib| case chunk when Chunks::Chunk color = chunk.color attrib = chunk.attrib text = chunk.text when Array # for earlier demos that used an array color = chunk[0] attrib = chunk[2] text = chunk[1] end color ||= defcolor attrib ||= defattr || NORMAL #cc, bg = ColorMap.get_colors_for_pair color #$log.debug "XXX: CHUNK textpad #{text}, cp #{color} , attrib #{attrib}. #{cc}, #{bg} " FFI::NCurses.wcolor_set(@pad, color,nil) if color FFI::NCurses.wattron(@pad, attrib) if attrib print(text) FFI::NCurses.wattroff(@pad, attrib) if attrib end end |
#text(lines, fmt = :none) ⇒ Object Also known as: list, set_content
display text given in an array format. This is the principal way of giving content to a textpad, other than filename(). If a format other than :none is given, then formatted_text is called.
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 222 def text(lines, fmt=:none) # added so callers can have one interface and avoid an if condition return formatted_text(lines, fmt) unless fmt == :none return @content if lines.empty? @content = lines @_populate_needed = true @repaint_all = true init_vars self end |
#top_of_window ⇒ Object
476 477 478 479 480 481 482 483 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 476 def top_of_window @current_index = @prow $multiplier ||= 0 if $multiplier > 0 @current_index += $multiplier $multiplier = 0 end end |
#up(num = (($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)) ⇒ Object
move up a line mimicking vim’s k key
512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/rbcurse/core/widgets/textpad.rb', line 512 def up num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier) #@oldindex = @current_index if num > 10 @current_index -= num #unless is_visible? @current_index #if @prow > @current_index ##$status_message.value = "1 #{@prow} > #{@current_index} " #@prow -= 1 #else #end #end $multiplier = 0 end |