Class: Redwood::TextMode

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

Direct Known Subclasses

HelpMode, LogMode

Constant Summary

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, #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?, #killable?, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file, #status

Constructor Details

- (TextMode) initialize(text = "",, filename = nil)

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

- (Object) text

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

- (Object) <<(line)



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

- (Object) [](i)



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

- (Object) lines



57
58
59
# File 'lib/sup/modes/text-mode.rb', line 57

def lines
  @lines.length - 1
end

- (Object) pipe



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)
  else
    BufferManager.flash "'#{command}' done!"
  end
end

- (Object) save_to_disk



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