From 28fc9fa53da1449498392f83d63a8502a5a958a3 Mon Sep 17 00:00:00 2001 From: Galen Abell Date: Sun, 26 May 2019 17:37:39 -0400 Subject: 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 --- commands/account/pipe.go | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) (limited to 'commands/account') 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 } -- cgit v1.2.3