1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
}
|