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=""
13 buffer.mark_dirty if buffer
18 fn = BufferManager.ask_for_filename :filename, "Save to file: "
19 save_to_file(fn) { |f| f.puts text } if fn
23 command = BufferManager.ask(:shell, "pipe command: ")
24 return if command.nil? || command.empty?
26 output = pipe_to_process(command) do |stream|
27 @text.each { |l| stream.puts l }
31 BufferManager.spawn "Output of '#{command}'", TextMode.new(output)
33 BufferManager.flash "'#{command}' done!"
47 @lines = [0] if @text.empty?
49 @lines << @text.length
61 return nil unless i < @lines.length
62 @text[@lines[i] ... (i + 1 < @lines.length ? @lines[i + 1] - 1 : @text.length)].normalize_whitespace
63 # (@lines[i] ... (i + 1 < @lines.length ? @lines[i + 1] - 1 : @text.length)).inspect
69 pos = @text.find_all_positions("\n")
70 pos.push @text.length unless pos.last == @text.length - 1
71 @lines = [0] + pos.map { |x| x + 1 }