From 874c492e5c471d4ee9bde1638dc675999b8b1f51 Mon Sep 17 00:00:00 2001 From: citrons Date: Sat, 1 Feb 2025 14:19:23 -0600 Subject: renaming/refactoring --- tui/draw.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'tui/draw.go') diff --git a/tui/draw.go b/tui/draw.go index 01dfc83..2005f1a 100644 --- a/tui/draw.go +++ b/tui/draw.go @@ -26,30 +26,32 @@ type surface map[pos]char type screen struct { front surface back surface - prevSize Dims + prevSize ScreenSize writer *bufio.Writer cursor pos } -var terminfo *termfo.Terminfo +var ( + terminfo *termfo.Terminfo + scr screen +) -var scr screen func init() { scr.writer = bufio.NewWriterSize(os.Stdout, 50000) Clear() } -type Dims struct { +type ScreenSize struct { Width int Height int } -func Size() Dims { +func Size() ScreenSize { w, h, _ := term.GetSize(0) - return Dims {w, h} + return ScreenSize {w, h} } -func Write(x int, y int, text string, style Style) int { +func WriteAt(x int, y int, text string, style Style) int { width := 0 g := uniseg.NewGraphemes(text) for g.Next() { @@ -107,15 +109,15 @@ func End() { if saved == nil { return } - if term.Restore(0, saved) != nil { - return - } - saved = nil os.Stdout.WriteString( terminfo.Get(caps.ClearScreen) + terminfo.Get(caps.XM, 0) + terminfo.Get(caps.ExitCaMode), ) + if term.Restore(0, saved) != nil { + return + } + saved = nil } func writeCursor(x int, y int) error { -- cgit v1.2.3