3 class TextMode < ScrollMode
6 k.add :save_to_disk, "Save to disk", 's'
7 k.add :pipe, "Pipe to process", '|'
10 def initialize text="", filename=nil
14 buffer.mark_dirty if buffer
19 fn = BufferManager.ask_for_filename :filename, "Save to file: ", @filename
20 save_to_file(fn) { |f| f.puts text } if fn
24 command = BufferManager.ask(:shell, "pipe command: ")
25 return if command.nil? || command.empty?
27 output = pipe_to_process(command) do |stream|
28 @text.each { |l| stream.puts l }
32 BufferManager.spawn "Output of '#{command}'", TextMode.new(output)
34 BufferManager.flash "'#{command}' done!"
48 @lines = [0] if @text.empty?
50 @lines << @text.length
62 return nil unless i < @lines.length
63 @text[@lines[i] ... (i + 1 < @lines.length ? @lines[i + 1] - 1 : @text.length)].normalize_whitespace
64 # (@lines[i] ... (i + 1 < @lines.length ? @lines[i + 1] - 1 : @text.length)).inspect
70 pos = @text.find_all_positions("\n")
71 pos.push @text.length unless pos.last == @text.length - 1
72 @lines = [0] + pos.map { |x| x + 1 }