summaryrefslogtreecommitdiff
path: root/ui/draw_utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'ui/draw_utils.go')
-rw-r--r--ui/draw_utils.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/ui/draw_utils.go b/ui/draw_utils.go
new file mode 100644
index 0000000..893a77f
--- /dev/null
+++ b/ui/draw_utils.go
@@ -0,0 +1,40 @@
+package ui
+
+import (
+ "fmt"
+ "time"
+
+ "github.com/gdamore/tcell/v2"
+)
+
+func printIdent(screen tcell.Screen, x, y, width int, st tcell.Style, s string) {
+ s = truncate(s, width, "\u2026")
+ x += width - StringWidth(s)
+ screen.SetContent(x-1, y, ' ', nil, st)
+ printString(screen, &x, y, st, s)
+ screen.SetContent(x, y, ' ', nil, st)
+}
+
+func printString(screen tcell.Screen, x *int, y int, st tcell.Style, s string) {
+ for _, r := range s {
+ screen.SetContent(*x, y, r, nil, st)
+ *x += runeWidth(r)
+ }
+}
+
+func printNumber(screen tcell.Screen, x *int, y int, st tcell.Style, n int) {
+ s := fmt.Sprintf("%d", n)
+ printString(screen, x, y, st, s)
+}
+
+func printTime(screen tcell.Screen, x int, y int, st tcell.Style, t time.Time) {
+ hr0 := rune(t.Hour()/10) + '0'
+ hr1 := rune(t.Hour()%10) + '0'
+ mn0 := rune(t.Minute()/10) + '0'
+ mn1 := rune(t.Minute()%10) + '0'
+ screen.SetContent(x+0, y, hr0, nil, st)
+ screen.SetContent(x+1, y, hr1, nil, st)
+ screen.SetContent(x+2, y, ':', nil, st)
+ screen.SetContent(x+3, y, mn0, nil, st)
+ screen.SetContent(x+4, y, mn1, nil, st)
+}