summary refs log tree commit diff stats
path: root/commands/account/pipe.go
diff options
context:
space:
mode:
authorGalen Abell <galen@galenabell.com>2019-05-26 17:37:39 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-27 09:37:07 -0400
commit28fc9fa53da1449498392f83d63a8502a5a958a3 (patch)
tree5c940758d297ca88f47f24344da3e8ee08e998bc /commands/account/pipe.go
parent62cd0b08aa82fe19e6d5d96b0341f7cffbb4cb7b (diff)
downloadaerc-28fc9fa53da1449498392f83d63a8502a5a958a3.tar.gz
Add :save and :pipe commands to viewer
* :save takes a path and saves the current message part to that location
* :pipe is the same as pipe on the account page, but uses the current
  message part rather than the whole email (ie :pipe gzip -d)
* Refactored account:pipe and extracted common pipe code to
  commands.util.QuickTerm
* Added helper command aerc.PushError
Diffstat (limited to 'commands/account/pipe.go')
-rw-r--r--commands/account/pipe.go40
1 files changed, 3 insertions, 37 deletions
diff --git a/commands/account/pipe.go b/commands/account/pipe.go
index 9675fe4..d3cc80a 100644
--- a/commands/account/pipe.go
+++ b/commands/account/pipe.go
@@ -3,12 +3,9 @@ package account
 import (
 	"errors"
 	"io"
-	"os/exec"
-	"time"
 
+	"git.sr.ht/~sircmpwn/aerc/commands"
 	"git.sr.ht/~sircmpwn/aerc/widgets"
-
-	"github.com/gdamore/tcell"
 )
 
 func init() {
@@ -23,44 +20,13 @@ func Pipe(aerc *widgets.Aerc, args []string) error {
 	store := acct.Messages().Store()
 	msg := acct.Messages().Selected()
 	store.FetchFull([]uint32{msg.Uid}, func(reader io.Reader) {
-		cmd := exec.Command(args[1], args[2:]...)
-		pipe, err := cmd.StdinPipe()
-		if err != nil {
-			aerc.PushStatus(" "+err.Error(), 10*time.Second).
-				Color(tcell.ColorDefault, tcell.ColorRed)
-			return
-		}
-		term, err := widgets.NewTerminal(cmd)
+		term, err := commands.QuickTerm(aerc, args[1:], reader)
 		if err != nil {
-			aerc.PushStatus(" "+err.Error(), 10*time.Second).
-				Color(tcell.ColorDefault, tcell.ColorRed)
+			aerc.PushError(" " + err.Error())
 			return
 		}
 		name := args[1] + " <" + msg.Envelope.Subject
 		aerc.NewTab(term, name)
-		term.OnClose = func(err error) {
-			if err != nil {
-				aerc.PushStatus(" "+err.Error(), 10*time.Second).
-					Color(tcell.ColorDefault, tcell.ColorRed)
-			} else {
-				aerc.PushStatus("Process complete, press any key to close.",
-					10*time.Second)
-				term.OnEvent = func(event tcell.Event) bool {
-					aerc.RemoveTab(term)
-					return true
-				}
-			}
-		}
-		term.OnStart = func() {
-			go func() {
-				_, err := io.Copy(pipe, reader)
-				if err != nil {
-					aerc.PushStatus(" "+err.Error(), 10*time.Second).
-						Color(tcell.ColorDefault, tcell.ColorRed)
-				}
-				pipe.Close()
-			}()
-		}
 	})
 	return nil
 }