termui/p.go

46 lines
694 B
Go
Raw Normal View History

2015-02-03 12:13:51 -07:00
package termui
type Par struct {
2015-02-03 18:56:49 -07:00
Block
2015-02-03 12:13:51 -07:00
Text string
2015-02-03 18:56:49 -07:00
TextFgColor Attribute
TextBgColor Attribute
2015-02-03 12:13:51 -07:00
}
func NewPar(s string) *Par {
return &Par{
Block: *NewBlock(),
Text: s,
TextFgColor: theme.ParTextFg,
TextBgColor: theme.ParTextBg}
2015-02-03 12:13:51 -07:00
}
func (p *Par) Buffer() []Point {
2015-02-03 18:56:49 -07:00
ps := p.Block.Buffer()
2015-02-03 12:13:51 -07:00
rs := str2runes(p.Text)
i, j, k := 0, 0, 0
for i < p.innerHeight && k < len(rs) {
if rs[k] == '\n' || j == p.innerWidth {
i++
j = 0
if rs[k] == '\n' {
k++
}
continue
}
pi := Point{}
pi.X = p.innerX + j
pi.Y = p.innerY + i
2015-03-03 11:28:09 -07:00
pi.Ch = rs[k]
pi.Bg = p.TextBgColor
pi.Fg = p.TextFgColor
2015-02-03 12:13:51 -07:00
ps = append(ps, pi)
k++
j++
}
return ps
}