Skip to content

Commit 5e6037d

Browse files
ekoopspoiana
authored andcommitted
chore(build/readme): adapt code to new tablewriter 1.1.2 API
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
1 parent dd557e8 commit 5e6037d

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

build/readme/fields.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ package main
1919

2020
import (
2121
"bytes"
22+
"fmt"
2223
"strings"
2324

2425
"github.com/falcosecurity/plugin-sdk-go/pkg/loader"
2526
"github.com/falcosecurity/plugin-sdk-go/pkg/sdk"
2627
"github.com/olekukonko/tablewriter"
28+
"github.com/olekukonko/tablewriter/renderer"
29+
"github.com/olekukonko/tablewriter/tw"
2730
)
2831

2932
const (
@@ -50,7 +53,7 @@ func fieldsRenderArgRow(a *sdk.FieldEntryArg) string {
5053

5154
// renderNewLines replaces '\n' character with "<br/>" for proper table formatting.
5255
func renderNewLines(desc string) string {
53-
return strings.ReplaceAll(desc, "\n", "<br/>")
56+
return strings.ReplaceAll(desc, "\n", "<br/>")
5457
}
5558

5659
func fieldsEditor(p *loader.Plugin, s string) (string, error) {
@@ -64,14 +67,20 @@ func fieldsEditor(p *loader.Plugin, s string) (string, error) {
6467
}
6568

6669
var buf bytes.Buffer
67-
table := tablewriter.NewWriter(&buf)
68-
table.SetHeader([]string{"Name", "Type", "Arg", "Description"})
69-
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
70-
table.SetCenterSeparator("|")
71-
table.SetRowSeparator("-")
72-
table.SetAutoWrapText(false)
70+
table := tablewriter.NewTable(&buf,
71+
tablewriter.WithRenderer(renderer.NewBlueprint()), // Use Blueprint
72+
tablewriter.WithRendition(tw.Rendition{
73+
Symbols: tw.NewSymbols(tw.StyleMarkdown),
74+
Borders: tw.Border{Left: tw.On, Right: tw.On, Top: tw.Off, Bottom: tw.Off}, // Markdown needs left/right borders
75+
}),
76+
tablewriter.WithHeaderAlignment(tw.AlignCenter), // Center align headers
77+
tablewriter.WithRowAlignment(tw.AlignLeft), // Common for Markdown
78+
tablewriter.WithHeaderAutoWrap(tw.WrapNone),
79+
tablewriter.WithRowAutoWrap(tw.WrapNone),
80+
tablewriter.WithHeader([]string{"Name", "Type", "Arg", "Description"}),
81+
)
7382
for _, f := range fields {
74-
row := []string{}
83+
var row []string
7584
row = append(row, "`"+f.Name+"`")
7685
if f.IsList {
7786
row = append(row, "`"+f.Type+" (list)`")
@@ -80,8 +89,14 @@ func fieldsEditor(p *loader.Plugin, s string) (string, error) {
8089
}
8190
row = append(row, fieldsRenderArgRow(&f.Arg))
8291
row = append(row, renderNewLines(f.Desc))
83-
table.Append(row)
92+
if err := table.Append(row); err != nil {
93+
return "", fmt.Errorf("failed to append field %v to table: %w", f.Name, err)
94+
}
95+
}
96+
97+
if err := table.Render(); err != nil {
98+
return "", fmt.Errorf("failed to render table: %w", err)
8499
}
85-
table.Render()
100+
86101
return replateTag(s, fieldsTag, buf.String())
87102
}

0 commit comments

Comments
 (0)