From 55ad16bb706a013711c555259c37292d441894f2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 21 Mar 2019 19:56:47 -0400 Subject: Fix cursor handling in embedded terminal --- widgets/terminal.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'widgets') diff --git a/widgets/terminal.go b/widgets/terminal.go index 29a619c5..d9772e66 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -92,7 +92,6 @@ type Terminal struct { cmd *exec.Cmd colors map[tcell.Color]tcell.Color ctx *ui.Context - cursorPos vterm.Pos cursorShown bool damage []vterm.Rect err error @@ -202,6 +201,7 @@ func (term *Terminal) Close(err error) { term.OnClose(err) } term.closed = true + term.ctx.HideCursor() } func (term *Terminal) OnInvalidate(cb func(d ui.Drawable)) { @@ -283,11 +283,17 @@ func (term *Terminal) Draw(ctx *ui.Context) { } } } + + if !term.cursorShown { + ctx.HideCursor() + } else { + row, col := term.vterm.ObtainState().GetCursorPos() + ctx.SetCursor(col, row) + } } func (term *Terminal) Focus(focus bool) { term.focus = focus - term.resetCursor() } func convertMods(mods tcell.ModMask) vterm.Modifier { @@ -373,22 +379,10 @@ func (term *Terminal) onDamage(rect *vterm.Rect) int { return 1 } -func (term *Terminal) resetCursor() { - if term.ctx != nil && term.focus { - if !term.cursorShown { - term.ctx.HideCursor() - } else { - term.ctx.SetCursor(term.cursorPos.Col(), term.cursorPos.Row()) - } - } -} - func (term *Terminal) onMoveCursor(old *vterm.Pos, pos *vterm.Pos, visible bool) int { term.cursorShown = visible - term.cursorPos = *pos - term.resetCursor() return 1 } -- cgit