aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-04-23 08:01:23 -0500
committerRobin Jarry <robin@jarry.cc>2023-04-23 17:23:25 +0200
commitc7b122f4c4a87cd54402c78465e1a5c882f37aeb (patch)
tree77c6d85badb388ff4f790bd9bc7774b00bca32e0 /widgets
parent44b6c52ac342b1bc75ca565c3787e0b963259476 (diff)
downloadaerc-c7b122f4c4a87cd54402c78465e1a5c882f37aeb.tar.gz
tcell-term: upgrade to latest release
Upgrade tcell-term to latest release. This is a complete rewrite of tcell-term, and includes many minor bug fixes and overall improvements. Notably: - Improved parsing - One fewer goroutine - Improved API - Improved redraw messaging - Improved key support - Improved mouse support Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/terminal.go35
1 files changed, 19 insertions, 16 deletions
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 {