about summary refs log tree commit diff stats
path: root/mandelbrot-fixed.mu
Commit message (Expand)AuthorAgeFilesLines
* mandelbrot: add some garish colorKartik K. Agaram2021-05-091-8/+6
* similarly zoom into fixed and fp mandelbrotKartik K. Agaram2021-05-091-3/+12
* mandelbrot-fixed: introduce some viewport parametersKartik K. Agaram2021-05-091-17/+42
* bugfix in mandelbrot-fixedKartik K. Agaram2021-05-091-13/+19
* .Kartik Agaram2021-05-091-3/+3
* .Kartik Agaram2021-05-091-1/+1
* .Kartik Agaram2021-05-091-1/+6
* mandelbrot: streamline expositionKartik Agaram2021-05-091-32/+26
* .Kartik Agaram2021-05-091-0/+1
* mandelbrot set in fixed-pointKartik K. Agaram2021-05-081-0/+224
eBodies to FetchFullMessages' href='/akspecs/aerc/commit/commands/account/pipe.go?h=0.1.1&id=95875b13f829919b3453763628d1dda97371fab0'>95875b1 ^
700dea2 ^



2958579 ^
700dea2 ^




2958579 ^
700dea2 ^

1a4cc31 ^

700dea2 ^


2958579 ^
700dea2 ^
700dea2 ^

71c13c9 ^



700dea2 ^



700dea2 ^


2958579 ^
700dea2 ^






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


               




                 
                                          

                                  
                                       










                                                                 

                                         
                                                                   



                                                                         
                                                                         




                                                                         
                                                                         

                              

                                                                      


                                                                                 
                                                                                 
                                

                                                                                            



                                                                             



                                       


                                                                                         
                                                                                         






                                            
package account

import (
	"errors"
	"io"
	"os/exec"
	"time"

	"git.sr.ht/~sircmpwn/aerc/widgets"

	"github.com/gdamore/tcell"
	"github.com/mattn/go-runewidth"
)

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()
	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)
		if err != nil {
			aerc.PushStatus(" "+err.Error(), 10*time.Second).
				Color(tcell.ColorDefault, tcell.ColorRed)
			return
		}
		name := args[1] + " <" + msg.Envelope.Subject
		aerc.NewTab(term, runewidth.Truncate(name, 32, "…"))
		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
}