/
util.go
37 lines (32 loc) · 925 Bytes
/
util.go
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
package ui
import (
termbox "github.com/nsf/termbox-go"
)
// DrawText prints a string at a paricular position
func DrawText(x, y int, text string, fg, bg termbox.Attribute) {
for i, char := range text {
termbox.SetCell(x+i, y, char, fg, bg)
}
}
func DrawTextPad(x, y int, text string, pad int, fg, bg termbox.Attribute) {
for i, char := range text {
termbox.SetCell(x+i, y, char, fg, bg)
}
for i := len(text); i < pad; i++ {
termbox.SetCell(x+i, y, ' ', fg, bg)
}
}
func DrawRunes(x, y int, text []rune, fg, bg termbox.Attribute) {
for i, char := range text {
termbox.SetCell(x+i, y, char, fg, bg)
}
}
// Clear clears the cells in the range [minX, minY], [maxX, maxY] to the
// specified foreground and background colors.
func Clear(minX, minY, maxX, maxY int, fg, bg termbox.Attribute) {
for y := minY; y <= maxY; y++ {
for x := minX; x <= maxX; x++ {
termbox.SetCell(x, y, ' ', fg, bg)
}
}
}