aerc/ui/helpers.go

42 lines
745 B
Go
Raw Normal View History

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