support newlines in asciibox

This commit is contained in:
sqshq 2019-08-24 09:15:07 -04:00
parent 423e50e3f2
commit ec6694ad17
1 changed files with 11 additions and 3 deletions

View File

@ -17,7 +17,6 @@ type AsciiBox struct {
*ui.Block
*data.Consumer
alert *data.Alert
text string
ascii string
style ui.Style
render *fl.AsciiRender
@ -58,8 +57,7 @@ func NewAsciiBox(c config.AsciiBoxConfig, palette console.Palette) *AsciiBox {
for {
select {
case sample := <-box.SampleChannel:
box.text = strings.TrimSpace(sample.Value)
box.ascii, _ = box.render.RenderOpts(box.text, box.options)
box.renderText(sample)
case alert := <-box.AlertChannel:
box.alert = alert
}
@ -69,6 +67,16 @@ func NewAsciiBox(c config.AsciiBoxConfig, palette console.Palette) *AsciiBox {
return &box
}
func (a *AsciiBox) renderText(sample *data.Sample) {
text := strings.TrimSpace(sample.Value)
lines := strings.Split(text, "\n")
a.ascii = ""
for _, line := range lines {
ascii, _ := a.render.RenderOpts(line, a.options)
a.ascii += ascii + "\n"
}
}
func (a *AsciiBox) Draw(buffer *ui.Buffer) {
buffer.Fill(ui.NewCell(' ', ui.NewStyle(ui.ColorBlack)), a.GetRect())