diff --git a/go.mod b/go.mod index 5a6d34c8..26b252e0 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/prometheus/common v0.44.0 github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f - github.com/xlab/tablewriter v0.0.0-20160610135559-80b567a11ad5 golang.org/x/crypto v0.13.0 golang.org/x/term v0.12.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index ed481879..61d4b896 100644 --- a/go.sum +++ b/go.sum @@ -119,8 +119,6 @@ github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f h1:SGznmvCovewbaSgBsHgdThtWsLj5aCLX/3ZXMLd1UD0= github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f/go.mod h1:IY84XkhrEJTdHYLNy/zObs8mXuUAp9I65VyarbPSCCY= -github.com/xlab/tablewriter v0.0.0-20160610135559-80b567a11ad5 h1:gmD7q6cCJfBbcuobWQe/KzLsd9Cd3amS1Mq5f3uU1qo= -github.com/xlab/tablewriter v0.0.0-20160610135559-80b567a11ad5/go.mod h1:fVwOndYN3s5IaGlMucfgxwMhqwcaJtlGejBU6zX6Yxw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/monitor/monitor.go b/monitor/monitor.go index 97a456db..9aeacbf0 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -14,7 +14,8 @@ package monitor import ( - "github.com/xlab/tablewriter" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/jedib0t/go-pretty/v6/text" ) type Status string @@ -26,12 +27,15 @@ var ( UnknownStatus Status = "UNKNOWN" ) -func newTableWriter(title string) *tablewriter.Table { - table := tablewriter.CreateTable() - table.UTF8Box() +func newTableWriter(title string) table.Writer { + tbl := table.NewWriter() + tbl.SetStyle(table.StyleRounded) + tbl.Style().Title.Align = text.AlignCenter + tbl.Style().Format.Header = text.FormatDefault + if title != "" { - table.AddTitle(title) + tbl.SetTitle(title) } - return table + return tbl } diff --git a/monitor/result.go b/monitor/result.go index 57f88258..14962a3b 100644 --- a/monitor/result.go +++ b/monitor/result.go @@ -21,6 +21,8 @@ import ( "path/filepath" "strings" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/nats-io/natscli/columns" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/expfmt" ) @@ -109,40 +111,40 @@ func (r *Result) renderHuman() string { fmt.Fprintf(buf, "%s: %s\n\n", r.Name, r.Status) - table := newTableWriter("") - table.AddHeaders("Status", "Message") + tblWriter := newTableWriter("") + tblWriter.AppendHeader(table.Row{"Status", "Message"}) lines := 0 for _, ok := range r.OKs { - table.AddRow("OK", ok) + tblWriter.AppendRow(table.Row{"OK", ok}) lines++ } for _, warn := range r.Warnings { - table.AddRow("Warning", warn) + tblWriter.AppendRow(table.Row{"Warning", warn}) lines++ } for _, crit := range r.Criticals { - table.AddRow("Critical", crit) + tblWriter.AppendRow(table.Row{"Critical", crit}) lines++ } if lines > 0 { fmt.Fprintln(buf, "Status Detail") fmt.Fprintln(buf) - fmt.Fprint(buf, table.Render()) + fmt.Fprint(buf, tblWriter.Render()) fmt.Fprintln(buf) } - table = newTableWriter("") - table.AddHeaders("Metric", "Value", "Unit", "Critical Threshold", "Warning Threshold", "Description") + tblWriter = newTableWriter("") + tblWriter.AppendHeader(table.Row{"Metric", "Value", "Unit", "Critical Threshold", "Warning Threshold", "Description"}) lines = 0 for _, pd := range r.PerfData { - table.AddRow(pd.Name, pd.Value, pd.Unit, pd.Crit, pd.Warn, pd.Help) + tblWriter.AppendRow(table.Row{pd.Name, f(pd.Value), pd.Unit, f(pd.Crit), f(pd.Warn), pd.Help}) lines++ } if lines > 0 { fmt.Fprintln(buf, "Check Metrics") fmt.Fprintln(buf) - fmt.Fprint(buf, table.Render()) + fmt.Fprint(buf, tblWriter.Render()) fmt.Fprintln(buf) } @@ -296,3 +298,7 @@ func (r *Result) GenericExit() { r.Exit() } + +func f(v any) string { + return columns.F(v) +}