diff options
-rw-r--r-- | go.mod | 6 | ||||
-rw-r--r-- | go.sum | 10 | ||||
-rw-r--r-- | widgets/terminal.go | 35 |
3 files changed, 29 insertions, 22 deletions
@@ -3,7 +3,7 @@ module git.sr.ht/~rjarry/aerc go 1.17 require ( - git.sr.ht/~rockorager/tcell-term v0.6.0 + git.sr.ht/~rockorager/tcell-term v0.7.0 git.sr.ht/~sircmpwn/getopt v1.0.0 github.com/ProtonMail/go-crypto v0.0.0-20211221144345-a4f6767435ab github.com/arran4/golang-ical v0.0.0-20220517104411-fd89fefb0182 @@ -33,7 +33,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/rivo/uniseg v0.2.0 github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab - github.com/stretchr/testify v1.8.0 + github.com/stretchr/testify v1.8.2 github.com/syndtr/goleveldb v1.0.0 github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 github.com/zenhack/go.notmuch v0.0.0-20211022191430-4d57e8ad2a8b @@ -56,7 +56,7 @@ require ( github.com/rogpeppe/go-internal v1.8.1 // indirect golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect golang.org/x/net v0.6.0 // indirect - golang.org/x/sys v0.5.0 // indirect + golang.org/x/sys v0.6.0 // indirect golang.org/x/term v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect google.golang.org/appengine v1.6.7 // indirect @@ -31,8 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.sr.ht/~rockorager/tcell-term v0.6.0 h1:jSRvhfA4HXg1JtuWlv8eyA2zwCuGh+PkALf+nPUruP0= -git.sr.ht/~rockorager/tcell-term v0.6.0/go.mod h1:1I6RDEkdvPgg4p0znGy6qr4HriTlPFrrlfOo0H9/Too= +git.sr.ht/~rockorager/tcell-term v0.7.0 h1:XVbiLRIN9a3d6yzjh+Cl5yudwMiNkNDwCTRhlww8iWY= +git.sr.ht/~rockorager/tcell-term v0.7.0/go.mod h1:Snxh5CrziiA2CjyLOZ6tGAg5vMPlE+REMWT3rtKuyyQ= git.sr.ht/~sircmpwn/getopt v1.0.0 h1:/pRHjO6/OCbBF4puqD98n6xtPEgE//oq5U8NXjP7ROc= git.sr.ht/~sircmpwn/getopt v1.0.0/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -242,12 +242,14 @@ github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cma github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= @@ -378,6 +380,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/widgets/terminal.go b/widgets/terminal.go index c3c16db6..cbc943d7 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -2,14 +2,12 @@ package widgets import ( "os/exec" - "syscall" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/log" tcellterm "git.sr.ht/~rockorager/tcell-term" "github.com/gdamore/tcell/v2" - "github.com/gdamore/tcell/v2/views" ) type Terminal struct { @@ -19,7 +17,7 @@ type Terminal struct { destroyed bool focus bool visible bool - vterm *tcellterm.Terminal + vterm *tcellterm.VT running bool OnClose func(err error) @@ -47,7 +45,7 @@ func (term *Terminal) closeErr(err error) { } if term.vterm != nil { // Stop receiving events - term.vterm.Unwatch(term) + term.vterm.Detach() term.vterm.Close() } if !term.closed && term.OnClose != nil { @@ -81,12 +79,19 @@ func (term *Terminal) Draw(ctx *ui.Context) { if term.destroyed { return } - term.ctx = ctx // gross - term.vterm.SetView(ctx.View()) + term.vterm.SetSurface(ctx.View()) + + w, h := ctx.View().Size() + if term.ctx != nil { + ow, oh := term.ctx.View().Size() + if w != ow || h != oh { + term.vterm.Resize(w, h) + } + } + term.ctx = ctx if !term.running && !term.closed && term.cmd != nil { - term.vterm.Watch(term) - attr := &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1} - if err := term.vterm.StartWithAttrs(term.cmd, attr); err != nil { + term.vterm.Attach(term.HandleEvent) + if err := term.vterm.Start(term.cmd); err != nil { log.Errorf("error running terminal: %v", err) term.closeErr(err) return @@ -106,7 +111,7 @@ func (term *Terminal) Show(visible bool) { func (term *Terminal) draw() { term.vterm.Draw() if term.focus && !term.closed && term.ctx != nil { - vis, x, y, style := term.vterm.GetCursor() + y, x, style, vis := term.vterm.Cursor() if vis { term.ctx.SetCursor(x, y) term.ctx.SetCursorStyle(style) @@ -140,7 +145,7 @@ func (term *Terminal) Focus(focus bool) { if !term.focus { term.ctx.HideCursor() } else { - _, x, y, style := term.vterm.GetCursor() + y, x, style, _ := term.vterm.Cursor() term.ctx.SetCursor(x, y) term.ctx.SetCursorStyle(style) term.Invalidate() @@ -149,16 +154,15 @@ func (term *Terminal) Focus(focus bool) { } // HandleEvent is used to watch the underlying terminal events -func (term *Terminal) HandleEvent(ev tcell.Event) bool { +func (term *Terminal) HandleEvent(ev tcell.Event) { if term.closed || term.destroyed { - return false + return } switch ev := ev.(type) { - case *views.EventWidgetContent: + case *tcellterm.EventRedraw: if term.visible { ui.QueueRedraw() } - return true case *tcellterm.EventTitle: if term.OnTitle != nil { term.OnTitle(ev.Title()) @@ -167,7 +171,6 @@ func (term *Terminal) HandleEvent(ev tcell.Event) bool { term.Close() ui.QueueRedraw() } - return false } func (term *Terminal) Event(event tcell.Event) bool { |