terminal: properly handle cursor display

The terminal widget reports if the cursor should be displayed. Properly
handle this output to report cursor display back to aerc.

Reported-by: staceee
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-10-19 12:27:03 -05:00 committed by Robin Jarry
parent c3bb3aa2a8
commit 847c1cd3c3

View file

@ -13,14 +13,13 @@ import (
) )
type Terminal struct { type Terminal struct {
closed bool closed bool
cmd *exec.Cmd cmd *exec.Cmd
ctx *ui.Context ctx *ui.Context
cursorShown bool destroyed bool
destroyed bool focus bool
focus bool vterm *tcellterm.Terminal
vterm *tcellterm.Terminal running bool
running bool
OnClose func(err error) OnClose func(err error)
OnEvent func(event tcell.Event) bool OnEvent func(event tcell.Event) bool
@ -30,10 +29,9 @@ type Terminal struct {
func NewTerminal(cmd *exec.Cmd) (*Terminal, error) { func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
term := &Terminal{ term := &Terminal{
cursorShown: true, cmd: cmd,
vterm: tcellterm.New(),
} }
term.cmd = cmd
term.vterm = tcellterm.New()
return term, nil return term, nil
} }
@ -98,12 +96,12 @@ func (term *Terminal) Draw(ctx *ui.Context) {
func (term *Terminal) draw() { func (term *Terminal) draw() {
term.vterm.Draw() term.vterm.Draw()
if term.focus && !term.closed && term.ctx != nil { if term.focus && !term.closed && term.ctx != nil {
if !term.cursorShown { vis, x, y, style := term.vterm.GetCursor()
term.ctx.HideCursor() if vis {
} else {
_, x, y, style := term.vterm.GetCursor()
term.ctx.SetCursor(x, y) term.ctx.SetCursor(x, y)
term.ctx.SetCursorStyle(style) term.ctx.SetCursorStyle(style)
} else {
term.ctx.HideCursor()
} }
} }
} }