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
This commit is contained in:
parent
62cd0b08aa
commit
28fc9fa53d
8 changed files with 194 additions and 37 deletions
commands
56
commands/util.go
Normal file
56
commands/util.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc/widgets"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
// QuickTerm is an ephemeral terminal for running a single command and quiting.
|
||||
func QuickTerm(aerc *widgets.Aerc, args []string, stdin io.Reader) (*widgets.Terminal, error) {
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
pipe, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
term, err := widgets.NewTerminal(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
term.OnClose = func(err error) {
|
||||
if err != nil {
|
||||
aerc.PushError(" " + err.Error())
|
||||
// remove the tab on error, otherwise it gets stuck
|
||||
aerc.RemoveTab(term)
|
||||
} 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() {
|
||||
status := make(chan error, 1)
|
||||
|
||||
go func() {
|
||||
_, err := io.Copy(pipe, stdin)
|
||||
defer pipe.Close()
|
||||
status <- err
|
||||
}()
|
||||
|
||||
err := <-status
|
||||
if err != nil {
|
||||
aerc.PushError(" " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return term, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue