Class: RubyCurses::MultiTextView
- Inherits:
-
TextView
- Object
- TextView
- RubyCurses::MultiTextView
- Includes:
- ListScrollable
- Defined in:
- lib/rbcurse/extras/widgets/rmultitextview.rb
Overview
A viewable read only box. Can scroll. Extends TextView with ability to load more than one file or content and switch between files (buffers). NOTE: ideally, i should be able to dynamically add this functionality to either Textview or TextArea or even ListBox or Table someday. Should then be a Module rather than a class.
Instance Method Summary collapse
-
#add(file, title) ⇒ Object
load a file into the textview.
- #buffer_at(index) ⇒ Object
- #buffer_delete ⇒ Object
- #buffer_first ⇒ Object
- #buffer_last ⇒ Object
-
#buffer_menu ⇒ Object
this is just a test of the simple “most” menu can use this for next, prev, first, last, new, delete, overwrite etc.
- #buffer_next ⇒ Object
- #buffer_previous ⇒ Object
- #buffers_list ⇒ Object
-
#current_buffer ⇒ RBuffer
returns current buffer.
-
#file_edit ⇒ Object
prompts user for filename and opens in buffer Like vim’s :e.
-
#getfilename(prompt = "Enter filename: ", maxlen = 90) ⇒ Object
prompt user for a filename to read in.
-
#handle_key(ch) ⇒ Object
multi-textview.
- #init_vars ⇒ Object
-
#initialize(form = nil, config = {}, &block) ⇒ MultiTextView
constructor
A new instance of MultiTextView.
- #perror(errmess) ⇒ Object
-
#set_content(list, wrap = :WRAP_NONE) ⇒ Object
send in a list e.g.
- #set_current_buffer ⇒ Object
Constructor Details
#initialize(form = nil, config = {}, &block) ⇒ MultiTextView
Returns a new instance of MultiTextView.
33 34 35 36 37 38 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 33 def initialize form = nil, config={}, &block super @bmanager = BufferManager.new self end |
Instance Method Details
#add(file, title) ⇒ Object
load a file into the textview. This is the preferred method since it lets us add a title too Shucks, this misses wrap_style which the other one has
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 170 def add file, title begin @current_buffer = @bmanager.add file, title $log.debug " file edit got cb : #{@current_buffer} " set_current_buffer rescue => err alert err.to_s Ncurses.beep return -1 end end |
#buffer_at(index) ⇒ Object
181 182 183 184 185 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 181 def buffer_at index @current_buffer = @bmanager.element_at index $log.debug " buffer_last got #{@current_buffer} " set_current_buffer end |
#buffer_delete ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 139 def buffer_delete if @bmanager.size > 1 @bmanager.delete_at @current_buffer = @bmanager.previous set_current_buffer else perror "Only one buffer. Cannot delete." end end |
#buffer_first ⇒ Object
129 130 131 132 133 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 129 def buffer_first @current_buffer = @bmanager.first $log.debug " buffer_first got #{@current_buffer} " set_current_buffer end |
#buffer_last ⇒ Object
134 135 136 137 138 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 134 def buffer_last @current_buffer = @bmanager.last $log.debug " buffer_last got #{@current_buffer} " set_current_buffer end |
#buffer_menu ⇒ Object
this is just a test of the simple “most” menu can use this for next, prev, first, last, new, delete, overwrite etc
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 89 def = PromptMenu.new self .add(.create_mitem( 'e', "edit a file", "opened file ", :file_edit )) .add(.create_mitem( 'o', "overwrite file", "opened a file ", :file_overwrite )) .add(.create_mitem( 'l', "list buffers", "list buffers ", :buffers_list )) item = .create_mitem( 'b', "Buffer Options", "Buffer Options" ) = PromptMenu.new( self, "Buffer Options") .add(.create_mitem( 'n', "Next", "Switched to next buffer", :buffer_next )) .add(.create_mitem( 'p', "Prev", "Switched to previous buffer", :buffer_previous )) .add(.create_mitem( 'f', "First", "Switched to first buffer", :buffer_first )) .add(.create_mitem( 'l', "Last", "Switched to last buffer", :buffer_last )) .add(.create_mitem( 'd', "Delete", "Deleted buffer", :buffer_delete )) item.action = .add(item) # how do i know what's available. the application or window should know where to place .display @form.window, $error_message_row, $error_message_col, $datacolor #, menu end |
#buffer_next ⇒ Object
116 117 118 119 120 121 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 116 def buffer_next perror "No other buffer" and return if @bmanager.size < 2 @current_buffer = @bmanager.next set_current_buffer end |
#buffer_previous ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 122 def buffer_previous perror "No other buffer" and return if @bmanager.size < 2 @current_buffer = @bmanager.previous $log.debug " buffer_prev got #{@current_buffer} " set_current_buffer end |
#buffers_list ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 148 def buffers_list = PromptMenu.new self @bmanager.each_with_index{ |b, ix| aproc = Proc.new { buffer_at(ix) } name = b.title num = ix + 1 .add(.create_mitem( num.to_s, name, "Switched to buffer #{ix}", aproc )) } .display @form.window, $error_message_row, $error_message_col, $datacolor end |
#current_buffer ⇒ RBuffer
returns current buffer
51 52 53 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 51 def current_buffer @bmanager.current end |
#file_edit ⇒ Object
prompts user for filename and opens in buffer Like vim’s :e
160 161 162 163 164 165 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 160 def file_edit file = getfilename() $log.debug " got file_edit: #{file} " return if file == "" add file, file end |
#getfilename(prompt = "Enter filename: ", maxlen = 90) ⇒ Object
prompt user for a filename to read in
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 76 def getfilename prompt="Enter filename: ", maxlen=90 tabc = Proc.new {|str| Dir.glob(str +"*") } config={}; config[:tab_completion] = tabc #config[:default] = "defaulT" $log.debug " inside getstr before call #{$error_message_row} + #{$error_message_col} " #ret, str = rbgetstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config) ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config) $log.debug " rbgetstr returned #{ret} , #{str} " return "" if ret != 0 return str end |
#handle_key(ch) ⇒ Object
multi-textview
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 65 def handle_key ch # put list as current list and buffer too then super #@current_buffer = @bmanager.current #@list = @current_buffer.list @buffer = @list[@current_index] #@buffer = @bmanager.current ret = super # check for any keys not handled and check our own ones return ret # end |
#init_vars ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 39 def init_vars super bind_key(?:, :buffer_menu) bind_key(?e, :file_edit) bind_key([?\C-x, ?f], :file_edit) bind_key([?\C-x, ?k], :buffer_delete) bind_key([?\C-x, ?\C-b], :buffers_list) # easily cycle using p. n is used for next search. bind_key(?p, :buffer_previous) end |
#perror(errmess) ⇒ Object
192 193 194 195 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 192 def perror errmess #@form.window.print_error_message errmess alert errmess 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
59 60 61 62 63 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 59 def set_content list, wrap = :WRAP_NONE ret = super # buff = @bmanager.add_content @list return ret end |
#set_current_buffer ⇒ Object
186 187 188 189 190 191 |
# File 'lib/rbcurse/extras/widgets/rmultitextview.rb', line 186 def set_current_buffer @current_index = @current_buffer.current_index @curpos = @current_buffer.curpos @title = @current_buffer.title @list = @current_buffer.list end |