Class: Redwood::TextMode
- Inherits:
-
ScrollMode
- Object
- Mode
- ScrollMode
- Redwood::TextMode
- Defined in:
- lib/sup/modes/text_mode.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Attributes inherited from ScrollMode
#botline, #leftcol, #status, #topline
Attributes inherited from Mode
Instance Method Summary collapse
- #<<(line) ⇒ Object
- #[](i) ⇒ Object
-
#initialize(text = "", filename = nil) ⇒ TextMode
constructor
A new instance of TextMode.
- #lines ⇒ Object
- #pipe ⇒ Object
- #save_to_disk ⇒ Object
Methods inherited from ScrollMode
#at_bottom?, #at_top?, #cancel_search!, #col_jump, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #half_page_down, #half_page_up, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_goto_pos, #search_in_buffer, #search_start_line
Methods inherited from Mode
#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, keymap, keymaps, #killable?, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file, #status, #unsaved?
Constructor Details
#initialize(text = "", filename = nil) ⇒ TextMode
Returns a new instance of TextMode.
10 11 12 13 14 15 16 |
# File 'lib/sup/modes/text_mode.rb', line 10 def initialize text="", filename=nil @text = text @filename = filename update_lines buffer.mark_dirty if buffer super() end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/sup/modes/text_mode.rb', line 4 def text @text end |
Instance Method Details
#<<(line) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/sup/modes/text_mode.rb', line 47 def << line @lines = [0] if @text.empty? @text << line @lines << @text.length if buffer ensure_mode_validity buffer.mark_dirty end end |
#[](i) ⇒ Object
61 62 63 64 65 |
# File 'lib/sup/modes/text_mode.rb', line 61 def [] i return nil unless i < @lines.length @text[@lines[i] ... (i + 1 < @lines.length ? @lines[i + 1] - 1 : @text.length)].normalize_whitespace # (@lines[i] ... (i + 1 < @lines.length ? @lines[i + 1] - 1 : @text.length)).inspect end |
#lines ⇒ Object
57 58 59 |
# File 'lib/sup/modes/text_mode.rb', line 57 def lines @lines.length - 1 end |
#pipe ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sup/modes/text_mode.rb', line 23 def pipe command = BufferManager.ask(:shell, "pipe command: ") return if command.nil? || command.empty? output = pipe_to_process(command) do |stream| @text.each { |l| stream.puts l } end if output BufferManager.spawn "Output of '#{command}'", TextMode.new(output.ascii) else BufferManager.flash "'#{command}' done!" end end |
#save_to_disk ⇒ Object
18 19 20 21 |
# File 'lib/sup/modes/text_mode.rb', line 18 def save_to_disk fn = BufferManager.ask_for_filename :filename, "Save to file: ", @filename save_to_file(fn) { |f| f.puts text } if fn end |