2018-01-11 03:41:15 +00:00
|
|
|
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
|
2018-01-11 14:04:18 +00:00
|
|
|
newline := func() {
|
|
|
|
// TODO: Abort when out of room?
|
|
|
|
geo.Col = _geo.Col
|
|
|
|
geo.Row++
|
|
|
|
}
|
2018-01-11 03:41:15 +00:00
|
|
|
for _, ch := range str {
|
2018-01-11 14:04:18 +00:00
|
|
|
switch ch {
|
|
|
|
case '\n':
|
|
|
|
newline()
|
|
|
|
case '\r':
|
2018-01-11 03:41:15 +00:00
|
|
|
geo.Col = _geo.Col
|
2018-01-11 14:04:18 +00:00
|
|
|
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)
|
2018-01-11 03:41:15 +00:00
|
|
|
}
|
2018-01-11 14:04:18 +00:00
|
|
|
geo.Col = _geo.Col
|
2018-01-11 03:41:15 +00:00
|
|
|
}
|
|
|
|
}
|