diff options
Diffstat (limited to 'tui/draw.go')
| -rw-r--r-- | tui/draw.go | 20 |
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 |
