summary refs log tree commit diff stats
path: root/commands/account/pipe.go
diff options
context:
space:
mode:
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
 }