diff --git a/component/asciibox/asciibox.go b/component/asciibox/asciibox.go index a1d1f31..4549b3d 100644 --- a/component/asciibox/asciibox.go +++ b/component/asciibox/asciibox.go @@ -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())