Merge pull request #58 from sqshq/fix_segfalt_for_newlines_in_asciibox
Support newlines in asciibox
This commit is contained in:
commit
cec214dc0d
|
@ -17,7 +17,6 @@ type AsciiBox struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
alert *data.Alert
|
alert *data.Alert
|
||||||
text string
|
|
||||||
ascii string
|
ascii string
|
||||||
style ui.Style
|
style ui.Style
|
||||||
render *fl.AsciiRender
|
render *fl.AsciiRender
|
||||||
|
@ -58,8 +57,7 @@ func NewAsciiBox(c config.AsciiBoxConfig, palette console.Palette) *AsciiBox {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case sample := <-box.SampleChannel:
|
case sample := <-box.SampleChannel:
|
||||||
box.text = strings.TrimSpace(sample.Value)
|
box.renderText(sample)
|
||||||
box.ascii, _ = box.render.RenderOpts(box.text, box.options)
|
|
||||||
case alert := <-box.AlertChannel:
|
case alert := <-box.AlertChannel:
|
||||||
box.alert = alert
|
box.alert = alert
|
||||||
}
|
}
|
||||||
|
@ -69,6 +67,16 @@ func NewAsciiBox(c config.AsciiBoxConfig, palette console.Palette) *AsciiBox {
|
||||||
return &box
|
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) {
|
func (a *AsciiBox) Draw(buffer *ui.Buffer) {
|
||||||
|
|
||||||
buffer.Fill(ui.NewCell(' ', ui.NewStyle(ui.ColorBlack)), a.GetRect())
|
buffer.Fill(ui.NewCell(' ', ui.NewStyle(ui.ColorBlack)), a.GetRect())
|
||||||
|
|
Loading…
Reference in New Issue