Class: Redwood::TextMode

Inherits:
ScrollMode show all
Defined in:
lib/sup/modes/text-mode.rb

Direct Known Subclasses

HelpMode, LogMode

Constant Summary

Constants inherited from ScrollMode

ScrollMode::COL_JUMP

Instance Attribute Summary collapse

Attributes inherited from ScrollMode

#botline, #leftcol, #status, #topline

Attributes inherited from Mode

#buffer

Instance Method Summary collapse

Methods inherited from ScrollMode

#at_bottom?, #at_top?, #cancel_search!, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #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_in_buffer, #search_start_line

Methods inherited from Mode

#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, #killable?, load_all_modes, make_name, #name, register_keymap, #resize, #resolve_input, #save_to_file, #status

Constructor Details

#initialize(text = "") ⇒ TextMode

Returns a new instance of TextMode.



9
10
11
12
13
14
# File 'lib/sup/modes/text-mode.rb', line 9

def initialize text=""
  @text = text
  update_lines
  buffer.mark_dirty if buffer
  super()
end

Instance Attribute Details

#textObject

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



30
31
32
33
34
35
36
37
38
# File 'lib/sup/modes/text-mode.rb', line 30

def << line
  @lines = [0] if @text.empty?
  @text << line
  @lines << @text.length
  if buffer
    ensure_mode_validity
    buffer.mark_dirty 
  end
end

#[](i) ⇒ Object



44
45
46
47
48
# File 'lib/sup/modes/text-mode.rb', line 44

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

#linesObject



40
41
42
# File 'lib/sup/modes/text-mode.rb', line 40

def lines
  @lines.length - 1
end

#save_to_diskObject



16
17
18
19
# File 'lib/sup/modes/text-mode.rb', line 16

def save_to_disk
  fn = BufferManager.ask_for_filename :filename, "Save to file: "
  save_to_file(fn) { |f| f.puts text } if fn
end