2015-02-04 03:13:51 +08:00
|
|
|
package termui
|
|
|
|
|
|
|
|
type P struct {
|
2015-02-04 09:56:49 +08:00
|
|
|
Block
|
2015-02-04 03:13:51 +08:00
|
|
|
Text string
|
2015-02-04 09:56:49 +08:00
|
|
|
TextFgColor Attribute
|
|
|
|
TextBgColor Attribute
|
2015-02-04 03:13:51 +08:00
|
|
|
}
|
|
|
|
|
2015-02-04 09:56:49 +08:00
|
|
|
func NewP(s string) *P {
|
|
|
|
return &P{Block: *NewBlock(), Text: s}
|
2015-02-04 03:13:51 +08:00
|
|
|
}
|
|
|
|
|
2015-02-04 09:56:49 +08:00
|
|
|
func (p *P) Buffer() []Point {
|
|
|
|
ps := p.Block.Buffer()
|
2015-02-04 03:13:51 +08: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
|
|
|
|
|
|
|
|
pi.Code.Ch = rs[k]
|
2015-02-04 09:56:49 +08:00
|
|
|
pi.Code.Bg = toTmAttr(p.TextBgColor)
|
|
|
|
pi.Code.Fg = toTmAttr(p.TextFgColor)
|
2015-02-04 03:13:51 +08:00
|
|
|
|
|
|
|
ps = append(ps, pi)
|
|
|
|
k++
|
|
|
|
j++
|
|
|
|
}
|
|
|
|
return ps
|
|
|
|
}
|