diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-31 12:35:51 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-31 12:35:51 -0400 |
commit | 0abafa60e159f87595148c0d0fc4f5f46be2d400 (patch) | |
tree | 1f6cc2059c1d9d712dd60e00146b7a7caa9b1c59 /widgets/msgviewer.go | |
parent | 95875b13f829919b3453763628d1dda97371fab0 (diff) | |
download | aerc-0abafa60e159f87595148c0d0fc4f5f46be2d400.tar.gz |
Make message viewer real, part two
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r-- | widgets/msgviewer.go | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 2c77aeb..c7ac44c 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -16,10 +16,11 @@ import ( ) type MessageViewer struct { - mail io.Reader - pipe io.Writer - grid *ui.Grid - term *Terminal + cmd *exec.Cmd + source io.Reader + sink io.WriteCloser + grid *ui.Grid + term *Terminal } func formatAddresses(addrs []*imap.Address) string { @@ -92,22 +93,33 @@ func NewMessageViewer(store *lib.MessageStore, grid.AddChild(body).At(1, 0) viewer := &MessageViewer{ - pipe: pipe, + cmd: cmd, + sink: pipe, grid: grid, term: term, } store.FetchBodyPart(msg.Uid, 0, func(reader io.Reader) { - viewer.mail = reader - go func() { - io.Copy(pipe, reader) - pipe.Close() - }() + viewer.source = reader + viewer.attemptCopy() }) + term.OnStart = func() { + viewer.attemptCopy() + } + return viewer } +func (mv *MessageViewer) attemptCopy() { + if mv.source != nil && mv.cmd.Process != nil { + go func() { + io.Copy(mv.sink, mv.source) + mv.sink.Close() + }() + } +} + func (mv *MessageViewer) Draw(ctx *ui.Context) { mv.grid.Draw(ctx) } |