diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2020-10-21 16:22:28 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2020-10-26 08:45:07 +0100 |
commit | 7fae7f74c5315877e0d341ec60ceef2e87c0c1cc (patch) | |
tree | afdea6e39840dfbd3db4e864bf914fe137009298 /ui/draw_utils.go | |
parent | Collapse bufferlist in one block (diff) |
Vertical channel list
Diffstat (limited to 'ui/draw_utils.go')
-rw-r--r-- | ui/draw_utils.go | 40 |
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) +} |