Skip to content

Commit 4850e30

Browse files
committed
feat: Update tablewriter to v1.1.2
Table formatting change: The only regression is that columns are now separated by 3 spaces instead of tabs. This is actually an improvement as it makes output more portable across different terminals.
1 parent a2265d8 commit 4850e30

File tree

32 files changed

+261
-179
lines changed

32 files changed

+261
-179
lines changed

cmd/addressbook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
Run: func(_ *cobra.Command, _ []string) {
2626
cfg := config.Global()
2727
table := table.New()
28-
table.SetHeader([]string{"Name", "Address"})
28+
table.Header("Name", "Address")
2929

3030
var output [][]string
3131
for name, acc := range cfg.AddressBook.All {
@@ -44,8 +44,8 @@ var (
4444
return output[i][0] < output[j][0]
4545
})
4646

47-
table.AppendBulk(output)
48-
table.Render()
47+
cobra.CheckErr(table.Bulk(output))
48+
cobra.CheckErr(table.Render())
4949
},
5050
}
5151

cmd/network/governance/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var govListCmd = &cobra.Command{
2828
cobra.CheckErr(err)
2929

3030
table := table.New()
31-
table.SetHeader([]string{"ID", "Kind", "Submitter", "Created At", "Closes At", "State"})
31+
table.Header("ID", "Kind", "Submitter", "Created At", "Closes At", "State")
3232

3333
proposals, err := conn.Consensus().Governance().Proposals(ctx, common.GetHeight())
3434
if err != nil {
@@ -59,8 +59,8 @@ var govListCmd = &cobra.Command{
5959
})
6060
}
6161

62-
table.AppendBulk(output)
63-
table.Render()
62+
cobra.CheckErr(table.Bulk(output))
63+
cobra.CheckErr(table.Render())
6464
},
6565
}
6666

cmd/network/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var listCmd = &cobra.Command{
1818
Run: func(_ *cobra.Command, _ []string) {
1919
cfg := cliConfig.Global()
2020
table := table.New()
21-
table.SetHeader([]string{"Name", "Chain Context", "RPC"})
21+
table.Header("Name", "Chain Context", "RPC")
2222

2323
var output [][]string
2424
for name, net := range cfg.Networks.All {
@@ -39,7 +39,7 @@ var listCmd = &cobra.Command{
3939
return output[i][0] < output[j][0]
4040
})
4141

42-
table.AppendBulk(output)
43-
table.Render()
42+
cobra.CheckErr(table.Bulk(output))
43+
cobra.CheckErr(table.Render())
4444
},
4545
}

cmd/network/show.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ var showCmd = &cobra.Command{
311311
continue
312312
}
313313
table := table.New()
314-
table.SetHeader([]string{"Entity ID", "Node ID", "Role"})
314+
table.Header("Entity ID", "Node ID", "Role")
315315

316316
runtimeID := runtime.ID
317317
paratimeName := getParatimeName(cfg, runtimeID.String())
@@ -344,8 +344,8 @@ var showCmd = &cobra.Command{
344344
})
345345
}
346346

347-
table.AppendBulk(output)
348-
table.Render()
347+
cobra.CheckErr(table.Bulk(output))
348+
cobra.CheckErr(table.Render())
349349
fmt.Println()
350350
}
351351
return

cmd/paratime/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var listCmd = &cobra.Command{
2323
Run: func(_ *cobra.Command, _ []string) {
2424
cfg := cliConfig.Global()
2525
table := table.New()
26-
table.SetHeader([]string{"Network", "Paratime", "ID", "Denomination(s)"})
26+
table.Header("Network", "Paratime", "ID", "Denominations")
2727

2828
var output [][]string
2929
for netName, net := range cfg.Networks.All {
@@ -50,8 +50,8 @@ var listCmd = &cobra.Command{
5050
return output[i][1] < output[j][1]
5151
})
5252

53-
table.AppendBulk(output)
54-
table.Render()
53+
cobra.CheckErr(table.Bulk(output))
54+
cobra.CheckErr(table.Render())
5555
},
5656
}
5757

cmd/paratime/statistics.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strconv"
1111

1212
"github.com/olekukonko/tablewriter"
13+
"github.com/olekukonko/tablewriter/renderer"
14+
"github.com/olekukonko/tablewriter/tw"
1315
"github.com/spf13/cobra"
1416

1517
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
@@ -489,12 +491,42 @@ func (s *runtimeStats) printStats() {
489491

490492
func (s *runtimeStats) printEntityStats() {
491493
fmt.Println("\n=== ENTITY STATISTICS ===")
492-
table := tablewriter.NewWriter(os.Stdout)
493-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
494-
table.SetCenterSeparator("|")
495-
table.SetHeader(s.entitiesHeader)
496-
table.AppendBulk(s.entitiesOutput)
497-
table.Render()
494+
495+
// Configure table with left/right borders, no top/bottom borders, and pipe separators.
496+
rendition := tw.Rendition{
497+
Borders: tw.Border{
498+
Left: tw.On,
499+
Right: tw.On,
500+
Top: tw.Off,
501+
Bottom: tw.Off,
502+
},
503+
Symbols: tw.NewSymbols(tw.StyleASCII),
504+
Settings: tw.Settings{
505+
Separators: tw.Separators{
506+
BetweenColumns: tw.On,
507+
},
508+
},
509+
}
510+
511+
table := tablewriter.NewTable(
512+
os.Stdout,
513+
tablewriter.WithRenderer(renderer.NewBlueprint(rendition)),
514+
tablewriter.WithConfig(tablewriter.Config{
515+
Row: tw.CellConfig{
516+
Formatting: tw.CellFormatting{
517+
AutoWrap: tw.WrapNormal,
518+
},
519+
},
520+
}),
521+
)
522+
// Convert []string to []any for Header.
523+
headerAny := make([]any, len(s.entitiesHeader))
524+
for i, v := range s.entitiesHeader {
525+
headerAny[i] = v
526+
}
527+
table.Header(headerAny...)
528+
cobra.CheckErr(table.Bulk(s.entitiesOutput))
529+
cobra.CheckErr(table.Render())
498530
}
499531

500532
func init() {

cmd/rofl/provider/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func outputJSON(ctx context.Context, npa *common.NPASelection, conn connection.C
9999
// outputText returns providers in human-readable table format.
100100
func outputText(ctx context.Context, npa *common.NPASelection, conn connection.Connection, providers []*roflmarket.Provider) {
101101
table := table.New()
102-
table.SetHeader([]string{"Provider Address", "Scheduler App", "Nodes", "Offers", "Instances"})
102+
table.Header("Provider Address", "Scheduler App", "Nodes", "Offers", "Instances")
103103

104104
rows := make([][]string, 0, len(providers))
105105
for _, provider := range providers {
@@ -120,8 +120,8 @@ func outputText(ctx context.Context, npa *common.NPASelection, conn connection.C
120120
})
121121
}
122122

123-
table.AppendBulk(rows)
124-
table.Render()
123+
cobra.CheckErr(table.Bulk(rows))
124+
cobra.CheckErr(table.Render())
125125

126126
// If --show-offers is enabled, display offers for each provider.
127127
if roflCommon.ShowOffers {

cmd/wallet/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var listCmd = &cobra.Command{
1818
Run: func(_ *cobra.Command, _ []string) {
1919
cfg := config.Global()
2020
table := table.New()
21-
table.SetHeader([]string{"Account", "Kind", "Address"})
21+
table.Header("Account", "Kind", "Address")
2222

2323
var output [][]string
2424
for name, acc := range cfg.Wallet.All {
@@ -37,7 +37,7 @@ var listCmd = &cobra.Command{
3737
return output[i][0] < output[j][0]
3838
})
3939

40-
table.AppendBulk(output)
41-
table.Render()
40+
cobra.CheckErr(table.Bulk(output))
41+
cobra.CheckErr(table.Render())
4242
},
4343
}

examples/addressbook/03-list.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
NAME ADDRESS
2-
meghan 0xBe8B38ED9b0794e7ab9EbEfC1e710b4F4EC6F6C1
3-
mike oasis1qrtrpg56l6y2cfudwtgfuxmq5e5cyhffcsfpdqvw
1+
NAME ADDRESS
2+
meghan 0xBe8B38ED9b0794e7ab9EbEfC1e710b4F4EC6F6C1
3+
mike oasis1qrtrpg56l6y2cfudwtgfuxmq5e5cyhffcsfpdqvw

examples/addressbook/07-list.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
NAME ADDRESS
2-
mark oasis1qrtrpg56l6y2cfudwtgfuxmq5e5cyhffcsfpdqvw
3-
meghan 0xBe8B38ED9b0794e7ab9EbEfC1e710b4F4EC6F6C1
1+
NAME ADDRESS
2+
mark oasis1qrtrpg56l6y2cfudwtgfuxmq5e5cyhffcsfpdqvw
3+
meghan 0xBe8B38ED9b0794e7ab9EbEfC1e710b4F4EC6F6C1

0 commit comments

Comments
 (0)