-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony Worm
committed
May 18, 2024
1 parent
0b6a23a
commit a485910
Showing
4 changed files
with
113 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package yagu | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
) | ||
|
||
func DefaultTableFormat(table *tablewriter.Table) { | ||
table.SetAutoWrapText(false) | ||
table.SetAutoFormatHeaders(true) | ||
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetCenterSeparator("") | ||
table.SetColumnSeparator("") | ||
table.SetRowSeparator("") | ||
table.SetHeaderLine(false) | ||
table.SetBorder(false) | ||
table.SetTablePadding(" ") | ||
table.SetNoWhiteSpace(true) | ||
} | ||
|
||
type DataPrinter func(table *tablewriter.Table) ([][]string, error) | ||
|
||
func PrintAsTable(headers []string, printer DataPrinter) error { | ||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetHeader(headers) | ||
|
||
DefaultTableFormat(table) | ||
|
||
rows, err := printer(table) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
table.AppendBulk(rows) | ||
|
||
// render | ||
table.Render() | ||
|
||
return nil | ||
} |