diff --git a/ABTaskFile b/ABTaskFile index 3a456338..92903f7e 100644 --- a/ABTaskFile +++ b/ABTaskFile @@ -17,7 +17,7 @@ commands: script: | set -e - go test ./... + go list ./... | grep -F -e asciigraph -v |xargs go test - name: lint type: exec diff --git a/cli/consumer_command.go b/cli/consumer_command.go index 49852a28..23db0307 100644 --- a/cli/consumer_command.go +++ b/cli/consumer_command.go @@ -491,6 +491,10 @@ func (c *consumerCmd) graphAction(_ *fisk.ParseContext) error { height -= 5 } + if width < 20 || height < 20 { + return fmt.Errorf("please increase terminal dimensions") + } + nfo, err := consumer.State() if err != nil { continue diff --git a/cli/server_graph_command.go b/cli/server_graph_command.go index 52981809..2276ae45 100644 --- a/cli/server_graph_command.go +++ b/cli/server_graph_command.go @@ -60,7 +60,9 @@ func (c *SrvGraphCmd) graphWrapper(graphs int, h func(width int, height int, vz return fmt.Errorf("failed to get terminal dimensions: %w", err) } - if width < 20 || height < graphs*5 { + minHeight := graphs*5 + 2 // 3 graph lines, the ruler, the heading and overall heading plus newline + + if width < 20 || height < minHeight { return fmt.Errorf("please increase terminal dimensions") } @@ -104,10 +106,14 @@ func (c *SrvGraphCmd) graphWrapper(graphs int, h func(width int, height int, vz width = 80 } if width > 15 { - width -= 10 + width -= 11 } if height > 10 { - height -= 6 + height -= graphs + 1 // make space for the main heading and gaps in the graphs etc + } + + if width < 20 || height < minHeight { + return fmt.Errorf("please increase terminal dimensions") } vz, err = c.getVz(nc, subj, body) @@ -222,7 +228,6 @@ func (c *SrvGraphCmd) graphJetStream() error { return []string{cpuPlot, assetsPlot, apiRatesPlot, pendingPlot, filePlot, memPlot}, nil }) - } func (c *SrvGraphCmd) graphServer() error { diff --git a/cli/stream_command.go b/cli/stream_command.go index de06aad8..1cb2fe60 100644 --- a/cli/stream_command.go +++ b/cli/stream_command.go @@ -474,12 +474,16 @@ func (c *streamCmd) graphAction(_ *fisk.ParseContext) error { width = 80 } if width > 15 { - width -= 10 + width -= 11 } if height > 10 { height -= 6 } + if width < 20 || height < 20 { + return fmt.Errorf("please increase terminal dimensions") + } + nfo, err := stream.State() if err != nil { continue diff --git a/internal/asciigraph/asciigraph.go b/internal/asciigraph/asciigraph.go index 59de800a..2bd58115 100644 --- a/internal/asciigraph/asciigraph.go +++ b/internal/asciigraph/asciigraph.go @@ -169,6 +169,7 @@ func PlotMany(data [][]float64, options ...Option) string { maxWidth = 0 } + maxLabelLength := 0 // axis and labels reusing the previously calculated magnitudes for w, magnitude := range magnitudes { var label string @@ -181,12 +182,19 @@ func PlotMany(data [][]float64, options ...Option) string { h := int(math.Max(float64(config.Offset)-float64(len(label)), 0)) + labelLength := len(label) + if labelLength > maxLabelLength { + maxLabelLength = labelLength + } + plot[w][h].Text = label plot[w][h].Color = config.LabelColor plot[w][config.Offset-1].Text = "┤" plot[w][config.Offset-1].Color = config.AxisColor } + width -= maxLabelLength + for i := range data { series := data[i] @@ -289,7 +297,7 @@ func PlotMany(data [][]float64, options ...Option) string { lines.WriteRune('\n') lines.WriteString(strings.Repeat(" ", config.Offset+maxWidth)) if len(config.Caption) < lenMax { - lines.WriteString(strings.Repeat(" ", (lenMax-len(config.Caption))/2)) + lines.WriteString(strings.Repeat(" ", (lenMax-len(config.Caption)-maxLabelLength)/2)) } if config.CaptionColor != Default { lines.WriteString(config.CaptionColor.String())