summaryrefslogtreecommitdiff
path: root/tui/draw.go
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-05-31 07:16:32 -0500
committercitrons <citrons@mondecitronne.com>2025-05-31 07:16:32 -0500
commit0a58e68ad438ff43fa5bbecdb8914aa00cab5099 (patch)
treecb53e132302297881d5be79813afc62a05320eda /tui/draw.go
parent22a50b723eb93c97d67eac362422d2424436b16b (diff)
support cursor in TUI layouts
Diffstat (limited to 'tui/draw.go')
-rw-r--r--tui/draw.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/tui/draw.go b/tui/draw.go
index 3772aa0..37a678e 100644
--- a/tui/draw.go
+++ b/tui/draw.go
@@ -29,6 +29,7 @@ type screen struct {
prevSize ScreenSize
writer *bufio.Writer
cursor pos
+ showCursor bool
}
var (
@@ -73,10 +74,16 @@ func WriteAt(x int, y int, text string, style Style) int {
func Clear() {
scr.front = make(surface)
+ ClearCursor()
}
-func MoveCursor(x int, y int) {
+func ShowCursor(x int, y int) {
scr.cursor = pos {x, y}
+ scr.showCursor = true
+}
+
+func ClearCursor() {
+ scr.showCursor = false
}
var saved *term.State
@@ -120,7 +127,12 @@ func End() {
saved = nil
}
+func writeClearCursor() {
+ scr.writer.WriteString(terminfo.Get(caps.CursorInvisible))
+}
+
func writeCursor(x int, y int) {
+ scr.writer.WriteString(terminfo.Get(caps.CursorNormal))
scr.writer.WriteString(terminfo.Get(caps.CursorAddress, y, x))
}
@@ -143,6 +155,8 @@ func writeStyle(style Style) {
}
func Present() error {
+ writeClearCursor()
+
s := Size()
reset := true
style := DefaultStyle
@@ -179,7 +193,9 @@ func Present() error {
p.x += cw
}
}
- writeCursor(scr.cursor.x, scr.cursor.y)
+ if scr.showCursor {
+ writeCursor(scr.cursor.x, scr.cursor.y)
+ }
scr.prevSize = s
f := scr.front