summary refs log tree commit diff stats
path: root/widgets/terminal.go
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 /widgets/terminal.go
parent4465646fedc5dd3efa680a7cc8d06671350b75b9 (diff)
downloadaerc-700dea23fa75f213af2f99449db994008eab9d21.tar.gz
Implement :pipe
Diffstat (limited to 'widgets/terminal.go')
-rw-r--r--widgets/terminal.go20
1 files changed, 14 insertions, 6 deletions
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 {