]> git.cworth.org Git - sup/commitdiff
add #pipe-to-process to text-mode
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Sat, 22 Dec 2007 18:10:03 +0000 (10:10 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Sat, 22 Dec 2007 18:10:03 +0000 (10:10 -0800)
lib/sup/modes/text-mode.rb

index aa53a845e03b6dae6586107f87920a4e653a1b21..22214d9e8d7df4e933ebe89528490d22cfaeb8f9 100644 (file)
@@ -4,6 +4,7 @@ class TextMode < ScrollMode
   attr_reader :text
   register_keymap do |k|
     k.add :save_to_disk, "Save to disk", 's'
+    k.add :pipe, "Pipe to process", '|'
   end
 
   def initialize text=""
@@ -18,6 +19,21 @@ class TextMode < ScrollMode
     save_to_file(fn) { |f| f.puts text } if fn
   end
 
+  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
+
   def text= t
     @text = t
     update_lines