class Redwood::TextMode

Attributes

text[R]

Public Class Methods

new(text="", filename=nil) click to toggle source
Calls superclass method Redwood::ScrollMode.new
# 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

Public Instance Methods

<<(line) click to toggle source
# File lib/sup/modes/text_mode.rb, line 52
def << line
  @lines = [0] if @text.empty?
  @text << line.fix_encoding!
  @lines << @text.length
  if buffer
    ensure_mode_validity
    buffer.mark_dirty
  end
end
[](i) click to toggle source
# File lib/sup/modes/text_mode.rb, line 66
  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() click to toggle source
# File lib/sup/modes/text_mode.rb, line 62
def lines
  @lines.length - 1
end
pipe() click to toggle source
# File lib/sup/modes/text_mode.rb, line 23
def pipe
  command = BufferManager.ask(:shell, "pipe command: ")
  return if command.nil? || command.empty?

  output, success = pipe_to_process(command) do |stream|
    @text.each { |l| stream.puts l }
  end

  unless success
    BufferManager.flash "Invalid command: '#{command}' is not an executable"
    return
  end

  if output
    BufferManager.spawn "Output of '#{command}'", TextMode.new(output.ascii)
  else
    BufferManager.flash "'#{command}' done!"
  end
end
save_to_disk() click to toggle source
# 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
text=(t) click to toggle source
# File lib/sup/modes/text_mode.rb, line 43
def text= t
  @text = t
  update_lines
  if buffer
    ensure_mode_validity
    buffer.mark_dirty
  end
end

Private Instance Methods

update_lines() click to toggle source
# File lib/sup/modes/text_mode.rb, line 74
def update_lines
  pos = @text.find_all_positions("\n")
  pos.push @text.length unless pos.last == @text.length - 1
  @lines = [0] + pos.map { |x| x + 1 }
end