Class: RubyCurses::OldTextView
- Includes:
- Scrollable
- Defined in:
- lib/rbcurse/rform.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 -
- searching, goto line - DONE
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
-
#prow ⇒ Object
readonly
the row on which cursor/focus is.
-
#toprow ⇒ Object
readonly
the toprow in the view (offsets are 0).
-
#winrow ⇒ Object
readonly
the row in the viewport/window.
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
- #addcol(num) ⇒ Object
- #addrowcol(row, col) ⇒ Object
- #cursor_backward ⇒ Object
- #cursor_forward ⇒ Object
- #do_relative_row(num) {|| ... } ⇒ Object
-
#find_first_match(regex) ⇒ Object
returns row of first match of given regex (or nil if not found).
-
#get_content ⇒ Object
FOR scrollable ###.
- #get_window ⇒ Object
- #getvalue ⇒ Object
-
#handle_key(ch) ⇒ Object
textview [ ] scroll left right DONE.
-
#initialize(form, config = {}, &block) ⇒ OldTextView
constructor
A new instance of OldTextView.
- #next_line ⇒ Object
- #print_borders ⇒ Object
- #print_foot ⇒ Object
- #print_title ⇒ Object
-
#repaint ⇒ Object
FOR scrollable ###.
- #row_count ⇒ Object
- #rowcol ⇒ Object
-
#scrollatrow ⇒ Object
—- for listscrollable —- ##.
-
#set_content(list) ⇒ Object
send in a list e.g.
-
#set_form_col(col = @curpos) ⇒ Object
set cursor on correct column tview.
-
#set_form_row ⇒ Object
puts cursor on correct row.
-
#top_row(*val) ⇒ Object
display this row on top.
- #wrap_text(txt, col = @maxlen) ⇒ Object
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, #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
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) ⇒ OldTextView
Returns a new instance of OldTextView.
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/rbcurse/rform.rb', line 644 def initialize form, config={}, &block @focusable = true @editable = false @left_margin = 1 @row = 0 @col = 0 @show_focus = false # don't highlight row under focus @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 @scrollatrow = @height-2 @content_rows = @list.length @win = @form.window init_scrollable print_borders @maxlen ||= @width-2 end |
Instance Attribute Details
#prow ⇒ Object (readonly)
the row on which cursor/focus is
640 641 642 |
# File 'lib/rbcurse/rform.rb', line 640 def prow @prow end |
#toprow ⇒ Object (readonly)
the toprow in the view (offsets are 0)
639 640 641 |
# File 'lib/rbcurse/rform.rb', line 639 def toprow @toprow end |
#winrow ⇒ Object (readonly)
the row in the viewport/window
641 642 643 |
# File 'lib/rbcurse/rform.rb', line 641 def winrow @winrow end |
Instance Method Details
#addcol(num) ⇒ Object
824 825 826 |
# File 'lib/rbcurse/rform.rb', line 824 def addcol num @form.addcol num end |
#addrowcol(row, col) ⇒ Object
827 828 829 |
# File 'lib/rbcurse/rform.rb', line 827 def addrowcol row,col @form.addrowcol row, col end |
#cursor_backward ⇒ Object
830 831 832 833 834 835 836 837 |
# File 'lib/rbcurse/rform.rb', line 830 def cursor_backward if @curpos > 0 @curpos -= 1 addcol -1 elsif @pcol > 0 # XXX added 2008-11-26 23:05 @pcol -= 1 end end |
#cursor_forward ⇒ Object
815 816 817 818 819 820 821 822 823 |
# File 'lib/rbcurse/rform.rb', line 815 def cursor_forward if @curpos < @width and @curpos < @maxlen-1 # else it will do out of box @curpos += 1 addcol 1 else # XXX 2008-11-26 23:03 trying out @pcol += 1 if @pcol <= @buffer.length end end |
#do_relative_row(num) {|| ... } ⇒ Object
841 842 843 |
# File 'lib/rbcurse/rform.rb', line 841 def do_relative_row num yield @list[@prow+num] end |
#find_first_match(regex) ⇒ Object
returns row of first match of given regex (or nil if not found)
689 690 691 692 693 694 |
# File 'lib/rbcurse/rform.rb', line 689 def find_first_match regex @list.each_with_index do |row, ix| return ix if !row.match(regex).nil? end return nil end |
#get_content ⇒ Object
FOR scrollable ###
730 731 732 |
# File 'lib/rbcurse/rform.rb', line 730 def get_content @list end |
#get_window ⇒ Object
733 734 735 |
# File 'lib/rbcurse/rform.rb', line 733 def get_window @form.window end |
#getvalue ⇒ Object
741 742 743 |
# File 'lib/rbcurse/rform.rb', line 741 def getvalue @list end |
#handle_key(ch) ⇒ Object
textview
-
scroll left right DONE
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/rbcurse/rform.rb', line 746 def handle_key ch @buffer = @list[@prow] if @buffer.nil? and @list.length == 0 @list << "\r" @buffer = @list[@prow] 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 end $log.debug "TV after loop : curpos #{@curpos} blen: #{@buffer.length}" pre_key case ch when ?\C-n.getbyte(0) scroll_forward when ?\C-p.getbyte(0) scroll_backward when ?0.getbyte(0), ?\C-[.getbyte(0) goto_start #start of buffer # cursor_start when ?\C-].getbyte(0) goto_end # end / bottom cursor_end when KEY_UP #select_prev_row ret = up #addrowcol -1,0 if ret != -1 or @winrow != @oldwinrow # positions the cursor up @form.row = @row + 1 + @winrow when KEY_DOWN ret = down @form.row = @row + 1 + @winrow when KEY_LEFT cursor_backward when KEY_RIGHT cursor_forward when KEY_BACKSPACE, 127 cursor_backward when 330 cursor_backward when ?\C-a.getbyte(0) # take care of data that exceeds maxlen by scrolling and placing cursor at start set_form_col 0 @pcol = 0 when ?\C-e.getbyte(0) # take care of data that exceeds maxlen by scrolling and placing cursor at end blen = @buffer.rstrip.length if blen < @maxlen set_form_col blen else @pcol = blen-@maxlen set_form_col @maxlen-1 end else $log.debug("TEXTVIEW XXX ch #{ch}") return :UNHANDLED end post_key # XXX 2008-11-27 13:57 trying out set_form_row end |
#next_line ⇒ Object
838 839 840 |
# File 'lib/rbcurse/rform.rb', line 838 def next_line @list[@prow+1] end |
#print_borders ⇒ Object
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/rbcurse/rform.rb', line 704 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
724 725 726 727 728 |
# File 'lib/rbcurse/rform.rb', line 724 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
721 722 723 |
# File 'lib/rbcurse/rform.rb', line 721 def print_title @form.window.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil? end |
#repaint ⇒ Object
FOR scrollable ###
737 738 739 740 |
# File 'lib/rbcurse/rform.rb', line 737 def repaint # textview paint print_foot if @print_footer end |
#row_count ⇒ Object
684 685 686 |
# File 'lib/rbcurse/rform.rb', line 684 def row_count @list.length end |
#rowcol ⇒ Object
695 696 697 698 |
# File 'lib/rbcurse/rform.rb', line 695 def rowcol #$log.debug "textarea rowcol : #{@row+@row_offset+@winrow}, #{@col+@col_offset}" return @row+@row_offset+@winrow, @col+@col_offset end |
#scrollatrow ⇒ Object
—- for listscrollable —- ##
681 682 683 |
# File 'lib/rbcurse/rform.rb', line 681 def scrollatrow @height - 2 end |
#set_content(list) ⇒ Object
send in a list e.g. set_content File.open(“README.txt”,“r”).readlines
668 669 670 |
# File 'lib/rbcurse/rform.rb', line 668 def set_content list @list = list end |
#set_form_col(col = @curpos) ⇒ Object
set cursor on correct column tview
811 812 813 814 |
# File 'lib/rbcurse/rform.rb', line 811 def set_form_col col=@curpos @curpos = col @form.col = @orig_col + @col_offset + @curpos end |
#set_form_row ⇒ Object
puts cursor on correct row.
807 808 809 |
# File 'lib/rbcurse/rform.rb', line 807 def set_form_row @form.row = @row + 1 + @winrow end |
#top_row(*val) ⇒ Object
display this row on top
672 673 674 675 676 677 678 679 |
# File 'lib/rbcurse/rform.rb', line 672 def top_row(*val) if val.empty? @toprow else @toprow = val[0] || 0 @prow = val[0] || 0 end end |
#wrap_text(txt, col = @maxlen) ⇒ Object
699 700 701 702 703 |
# File 'lib/rbcurse/rform.rb', line 699 def wrap_text(txt, col = @maxlen) $log.debug "inside wrap text for :#{txt}" txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3\n") end |