summary refs log tree commit diff stats
path: root/commands/util.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/util.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/util.go')
-rw-r--r--commands/util.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/commands/util.go b/commands/util.go
new file mode 100644
index 0000000..e9fd205
--- /dev/null
+++ b/commands/util.go
@@ -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
+}
py Fixed embedded shellscript (quotes for bash)' href='/akspecs/ranger/commit/ranger.py?h=v1.6.1&id=63a9639d62c208f78d9e5c8740f10cce74a4e967'>63a9639d ^
a2853ab6 ^
8fa87054 ^


a66c4a26 ^

f027adc0 ^
b289f679 ^

5c210a96 ^

3de15ddd ^

fb275079 ^

5c210a96 ^
3d566884 ^
e30d16cb ^
621a1a39 ^
c44b726e ^
465bff73 ^




f8e96a97 ^
b289f679 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56