diff --git a/component/sparkline/sparkline.go b/component/sparkline/sparkline.go index ed26966..b0451e1 100644 --- a/component/sparkline/sparkline.go +++ b/component/sparkline/sparkline.go @@ -121,4 +121,5 @@ func (s *SparkLine) Draw(buffer *ui.Buffer) { } s.Block.Draw(buffer) + component.RenderAlert(s.alert, s.Rectangle, buffer) } diff --git a/component/util/parse_test.go b/component/util/parse_test.go index b8b6028..c5f87da 100644 --- a/component/util/parse_test.go +++ b/component/util/parse_test.go @@ -13,7 +13,7 @@ func TestParseFloat(t *testing.T) { wantErr bool }{ {"should parse a regular number", args{"123"}, 123, false}, - {"should parse a regular number with spaces", args{" 123 "}, 123, false}, + {"should parse a regular number with spaces, tabs and line breaks", args{" \t 123 \t \n "}, 123, false}, {"should parse a last line in the given string", args{"123\n456"}, 456, false}, } for _, tt := range tests { diff --git a/data/item.go b/data/item.go index d588200..c2cd5ca 100644 --- a/data/item.go +++ b/data/item.go @@ -60,13 +60,13 @@ func (i *Item) nextValue(variables []string) (string, error) { if i.InitScript != nil { return i.executeInteractiveShellCmd(variables) } else { - return i.executeCmd(variables) + return i.executeCmd(variables, i.SampleScript) } } -func (i *Item) executeCmd(variables []string) (string, error) { +func (i *Item) executeCmd(variables []string, script string) (string, error) { - cmd := exec.Command("sh", "-c", i.SampleScript) + cmd := exec.Command("sh", "-c", script) enrichEnvVariables(cmd, variables) output, err := cmd.Output() @@ -75,7 +75,7 @@ func (i *Item) executeCmd(variables []string) (string, error) { return "", err } - return strings.TrimSpace(string(output)), nil + return string(output), nil } func (i *Item) initInteractiveShell(variables []string) error { @@ -167,13 +167,11 @@ func (i *Item) executeInteractiveShellCmd(variables []string) (string, error) { func (i *Item) transformInteractiveShellCmd(sample string) (string, error) { - result := sample - - if i.TransformScript != nil { - result = result // TODO + if i.TransformScript != nil && len(sample) > 0 { + return i.executeCmd([]string{"sample=" + sample}, *i.TransformScript) } - return result, nil + return sample, nil } func enrichEnvVariables(cmd *exec.Cmd, variables []string) {