summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-30 11:58:24 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-30 11:58:24 -0400
commit700dea23fa75f213af2f99449db994008eab9d21 (patch)
treefa142784bf4ccb6aba1cd2b8513228dd4b968b28 /commands
parent4465646fedc5dd3efa680a7cc8d06671350b75b9 (diff)
downloadaerc-700dea23fa75f213af2f99449db994008eab9d21.tar.gz
Implement :pipe
Diffstat (limited to 'commands')
-rw-r--r--commands/account/pipe.go73
-rw-r--r--commands/terminal/close.go1
2 files changed, 74 insertions, 0 deletions
diff --git a/commands/account/pipe.go b/commands/account/pipe.go
new file mode 100644
index 0000000..5693d4a
--- /dev/null
+++ b/commands/account/pipe.go
@@ -0,0 +1,73 @@
+package account
+
+import (
+	"bytes"
+	"errors"
+	"io"
+	"os/exec"
+	"time"
+
+	"git.sr.ht/~sircmpwn/aerc2/widgets"
+
+	"github.com/gdamore/tcell"
+	"github.com/mohamedattahri/mail"
+)
+
+func init() {
+	register("pipe", Pipe)
+}
+
+func Pipe(aerc *widgets.Aerc, args []string) error {
+	if len(args) < 2 {
+		return errors.New("Usage: :pipe <cmd> [args...]")
+	}
+	acct := aerc.SelectedAccount()
+	if acct == nil {
+		return errors.New("No account selected")
+	}
+	store := acct.Messages().Store()
+	msg := acct.Messages().Selected()
+	store.FetchBodies([]uint32{msg.Uid}, func(msg *mail.Message) {
+		cmd := exec.Command(args[1], args[2:]...)
+		pipe, err := cmd.StdinPipe()
+		if err != nil {
+			aerc.PushStatus(" "+err.Error(), 10*time.Second).
+				Color(tcell.ColorRed, tcell.ColorWhite)
+			return
+		}
+		term, err := widgets.NewTerminal(cmd)
+		if err != nil {
+			aerc.PushStatus(" "+err.Error(), 10*time.Second).
+				Color(tcell.ColorRed, tcell.ColorWhite)
+			return
+		}
+		host := widgets.NewTermHost(term, aerc.Config())
+		name := msg.Subject()
+		if len(name) > 12 {
+			name = name[:12]
+		}
+		aerc.NewTab(host, args[1] + " <" + name)
+		term.OnClose = func(err error) {
+			if err != nil {
+				aerc.PushStatus(" "+err.Error(), 10*time.Second).
+					Color(tcell.ColorRed, tcell.ColorWhite)
+			} else {
+				// TODO: Tab-specific status stacks
+				aerc.PushStatus("Process complete, press any key to close.",
+					10*time.Second)
+			}
+		}
+		term.OnStart = func() {
+			go func() {
+				reader := bytes.NewBuffer(msg.Bytes())
+				_, err := io.Copy(pipe, reader)
+				if err != nil {
+					aerc.PushStatus(" "+err.Error(), 10*time.Second).
+						Color(tcell.ColorRed, tcell.ColorWhite)
+				}
+				pipe.Close()
+			}()
+		}
+	})
+	return nil
+}
diff --git a/commands/terminal/close.go b/commands/terminal/close.go
index 68be6ac..cb5702e 100644
--- a/commands/terminal/close.go
+++ b/commands/terminal/close.go
@@ -19,5 +19,6 @@ func CommandClose(aerc *widgets.Aerc, args []string) error {
 		return errors.New("Error: not a terminal")
 	}
 	thost.Terminal().Close(nil)
+	aerc.RemoveTab(thost)
 	return nil
 }
'>cfb142b9 ^
5c7ed3d6 ^



13ba3def ^










08cf048f ^
13ba3def ^










795f5244 ^
166e3c0d ^
13ba3def ^
166e3c0d ^
9dcbec39 ^
e4630643 ^

166e3c0d ^






9dcbec39 ^
166e3c0d ^

5f98a10c ^
9dcbec39 ^
166e3c0d ^





aa088845 ^
48e40252 ^






614ea44b ^
de92036d ^
13ba3def ^

5aa38b52 ^
13ba3def ^
fc4a98dc ^

13ba3def ^
1b76245c ^
13ba3def ^

5aa38b52 ^





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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122