From 700dea23fa75f213af2f99449db994008eab9d21 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 30 Mar 2019 11:58:24 -0400 Subject: Implement :pipe --- widgets/terminal.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'widgets') diff --git a/widgets/terminal.go b/widgets/terminal.go index e7286f9..45e3591 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -9,8 +9,8 @@ import ( "git.sr.ht/~sircmpwn/aerc2/lib/ui" "git.sr.ht/~sircmpwn/go-libvterm" + "git.sr.ht/~sircmpwn/pty" "github.com/gdamore/tcell" - "github.com/kr/pty" ) type vtermKey struct { @@ -105,6 +105,7 @@ type Terminal struct { vterm *vterm.VTerm OnClose func(err error) + OnStart func() OnTitle func(title string) } @@ -192,6 +193,9 @@ func (term *Terminal) flushTerminal() { } func (term *Terminal) Close(err error) { + if term.closed { + return + } term.mutex.Lock() defer term.mutex.Unlock() term.err = err @@ -226,11 +230,6 @@ func (term *Terminal) Invalidate() { func (term *Terminal) Draw(ctx *ui.Context) { if term.closed { - if term.err != nil { - ui.NewText(term.err.Error()).Strategy(ui.TEXT_CENTER).Draw(ctx) - } else { - ui.NewText("Terminal closed").Strategy(ui.TEXT_CENTER).Draw(ctx) - } return } @@ -252,6 +251,9 @@ func (term *Terminal) Draw(ctx *ui.Context) { return } term.start <- nil + if term.OnStart != nil { + term.OnStart() + } } term.ctx = ctx // gross @@ -309,6 +311,9 @@ func (term *Terminal) Draw(ctx *ui.Context) { } func (term *Terminal) Focus(focus bool) { + if term.closed { + return + } term.focus = focus if term.ctx != nil { if !term.focus { @@ -339,6 +344,9 @@ func convertMods(mods tcell.ModMask) vterm.Modifier { } func (term *Terminal) Event(event tcell.Event) bool { + if term.closed { + return false + } switch event := event.(type) { case *tcell.EventKey: if event.Key() == tcell.KeyRune { -- cgit v1.2.3