Fix cursor handling in embedded terminal
This commit is contained in:
parent
28f393bdbd
commit
55ad16bb70
2
go.mod
2
go.mod
|
@ -1,7 +1,7 @@
|
||||||
module git.sr.ht/~sircmpwn/aerc2
|
module git.sr.ht/~sircmpwn/aerc2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231430-3db654768b06
|
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321235500-26a1fd7312be
|
||||||
github.com/emersion/go-imap v1.0.0-beta.1
|
github.com/emersion/go-imap v1.0.0-beta.1
|
||||||
github.com/emersion/go-imap-idle v0.0.0-20180114101550-2af93776db6b
|
github.com/emersion/go-imap-idle v0.0.0-20180114101550-2af93776db6b
|
||||||
github.com/emersion/go-sasl v0.0.0-20161116183048-7e096a0a6197 // indirect
|
github.com/emersion/go-sasl v0.0.0-20161116183048-7e096a0a6197 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -12,6 +12,8 @@ git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231235-12f4bd976b20 h1:5oQDpkPYOn
|
||||||
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231235-12f4bd976b20/go.mod h1:hT88+cTemwwESbMptwC7O33qrJfQX0SgRWbXlndUS2c=
|
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231235-12f4bd976b20/go.mod h1:hT88+cTemwwESbMptwC7O33qrJfQX0SgRWbXlndUS2c=
|
||||||
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231430-3db654768b06 h1:x9azyMxWqgTq4ARhNbYKHejt0PMhLi8J2XnuEsih9Qc=
|
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231430-3db654768b06 h1:x9azyMxWqgTq4ARhNbYKHejt0PMhLi8J2XnuEsih9Qc=
|
||||||
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231430-3db654768b06/go.mod h1:hT88+cTemwwESbMptwC7O33qrJfQX0SgRWbXlndUS2c=
|
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321231430-3db654768b06/go.mod h1:hT88+cTemwwESbMptwC7O33qrJfQX0SgRWbXlndUS2c=
|
||||||
|
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321235500-26a1fd7312be h1:2c/wWvhAzx530xu6pU8oEjtBAnHDyqQQIFmzIdko/48=
|
||||||
|
git.sr.ht/~sircmpwn/go-libvterm v0.0.0-20190321235500-26a1fd7312be/go.mod h1:hT88+cTemwwESbMptwC7O33qrJfQX0SgRWbXlndUS2c=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/emersion/go-imap v1.0.0-beta.1 h1:bTCaVlUnb5mKoW9lEukusxguSYYZPer+q0g5t+vw5X0=
|
github.com/emersion/go-imap v1.0.0-beta.1 h1:bTCaVlUnb5mKoW9lEukusxguSYYZPer+q0g5t+vw5X0=
|
||||||
|
|
|
@ -92,7 +92,6 @@ type Terminal struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
colors map[tcell.Color]tcell.Color
|
colors map[tcell.Color]tcell.Color
|
||||||
ctx *ui.Context
|
ctx *ui.Context
|
||||||
cursorPos vterm.Pos
|
|
||||||
cursorShown bool
|
cursorShown bool
|
||||||
damage []vterm.Rect
|
damage []vterm.Rect
|
||||||
err error
|
err error
|
||||||
|
@ -202,6 +201,7 @@ func (term *Terminal) Close(err error) {
|
||||||
term.OnClose(err)
|
term.OnClose(err)
|
||||||
}
|
}
|
||||||
term.closed = true
|
term.closed = true
|
||||||
|
term.ctx.HideCursor()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) OnInvalidate(cb func(d ui.Drawable)) {
|
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) {
|
func (term *Terminal) Focus(focus bool) {
|
||||||
term.focus = focus
|
term.focus = focus
|
||||||
term.resetCursor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertMods(mods tcell.ModMask) vterm.Modifier {
|
func convertMods(mods tcell.ModMask) vterm.Modifier {
|
||||||
|
@ -373,22 +379,10 @@ func (term *Terminal) onDamage(rect *vterm.Rect) int {
|
||||||
return 1
|
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,
|
func (term *Terminal) onMoveCursor(old *vterm.Pos,
|
||||||
pos *vterm.Pos, visible bool) int {
|
pos *vterm.Pos, visible bool) int {
|
||||||
|
|
||||||
term.cursorShown = visible
|
term.cursorShown = visible
|
||||||
term.cursorPos = *pos
|
|
||||||
term.resetCursor()
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue