From 7fae7f74c5315877e0d341ec60ceef2e87c0c1cc Mon Sep 17 00:00:00 2001 From: Hubert Hirtz Date: Wed, 21 Oct 2020 16:22:28 +0200 Subject: Vertical channel list --- ui/draw_utils.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ui/draw_utils.go (limited to 'ui/draw_utils.go') 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) +} -- cgit v1.2.3