aboutsummaryrefslogtreecommitdiffstats
path: root/ui/helpers.go
blob: f2b2adff65f06c100ff962990ae1ed946aae3847 (plain) (blame)
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
41
package ui

import (
	"fmt"

	tb "github.com/nsf/termbox-go"
)

func TPrintf(geo *Geometry, ref tb.Cell, format string, a ...interface{}) {
	str := fmt.Sprintf(format, a...)
	_geo := *geo
	newline := func() {
		// TODO: Abort when out of room?
		geo.Col = _geo.Col
		geo.Row++
	}
	for _, ch := range str {
		switch ch {
		case '\n':
			newline()
		case '\r':
			geo.Col = _geo.Col
		default:
			tb.SetCell(geo.Col, geo.Row, ch, ref.Fg, ref.Bg)
			geo.Col++
			if geo.Col == _geo.Col+geo.Width {
				newline()
			}
		}
	}
}

func TFill(geo Geometry, ref tb.Cell) {
	_geo := geo
	for ; geo.Row < geo.Height; geo.Row++ {
		for ; geo.Col < geo.Width; geo.Col++ {
			tb.SetCell(geo.Col, geo.Row, ref.Ch, ref.Fg, ref.Bg)
		}
		geo.Col = _geo.Col
	}
}