@@ -20,6 +20,8 @@ import (
2020 "io"
2121
2222 "github.com/olekukonko/tablewriter"
23+ "github.com/olekukonko/tablewriter/renderer"
24+ "github.com/olekukonko/tablewriter/tw"
2325)
2426
2527// NewTableWriter creates a new table writer with the given output and options.
@@ -31,3 +33,43 @@ func NewTableWriter(output io.Writer, options ...tablewriter.Option) *tablewrite
3133
3234 return table
3335}
36+
37+ // NewTableWriterWithDefaults creates a new table writer with default markdown configuration.
38+ // It includes left alignment, markdown renderer, and custom borders optimized for terminal output.
39+ func NewTableWriterWithDefaults (output io.Writer , options ... tablewriter.Option ) * tablewriter.Table {
40+ defaultOptions := []tablewriter.Option {
41+ tablewriter .WithConfig (tablewriter.Config {
42+ Header : tw.CellConfig {
43+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
44+ },
45+ }),
46+ tablewriter .WithRenderer (renderer .NewMarkdown ()),
47+ tablewriter .WithRendition (tw.Rendition {
48+ Symbols : tw .NewSymbols (tw .StyleMarkdown ),
49+ Borders : tw.Border {
50+ Left : tw .On ,
51+ Top : tw .Off ,
52+ Right : tw .On ,
53+ Bottom : tw .Off ,
54+ },
55+ Settings : tw.Settings {
56+ Separators : tw.Separators {
57+ BetweenRows : tw .On ,
58+ },
59+ },
60+ }),
61+ tablewriter .WithRowAutoWrap (tw .WrapNone ),
62+ }
63+
64+ defaultOptions = append (defaultOptions , options ... )
65+
66+ return NewTableWriter (output , defaultOptions ... )
67+ }
68+
69+ // NewTableWriterWithDefaultsAndHeader creates a new table writer with default configuration and header.
70+ func NewTableWriterWithDefaultsAndHeader (output io.Writer , header []string , options ... tablewriter.Option ) * tablewriter.Table {
71+ headerOption := tablewriter .WithHeader (header )
72+ allOptions := append ([]tablewriter.Option {headerOption }, options ... )
73+
74+ return NewTableWriterWithDefaults (output , allOptions ... )
75+ }
0 commit comments