Clean, elastic tabbed columns for terminal output.
tab takes a string of whitespace-separated text and formats it into aligned columns using Go's tabwriter.
go get github.com/grimdork/climate/tabEvery whitespace boundary becomes a column break:
input := "Name Role Status\nAlice Admin Active\nBob User Offline"
output, _ := tab.Tabulate(input, false)
fmt.Print(output)
// Name Role Status
// Alice Admin Active
// Bob User OfflineThe first word is column one, everything else is column two:
input := "serve Start the web server\nconfig Show current configuration\nhelp Display this message"
output, _ := tab.Tabulate(input, true)
fmt.Print(output)
// serve Start the web server
// config Show current configuration
// help Display this messageUseful for command lists, key-description pairs, or any label+text layout.
If you need the parsed rows without formatting:
rows, _ := tab.SplitColumns(input, false)
// rows is [][]stringParse CSV with proper quoting support. The first row becomes a header with a separator line:
csv := "Name,Role,Status\nAlice,Admin,Active\n\"Eve, Jr\",Guest,Pending"
output, _ := tab.TabulateCSV(csv)
fmt.Print(output)
// Name Role Status
// ------- ----- -------
// Alice Admin Active
// Eve, Jr Guest PendingHandles quoted fields, commas inside values, and all standard CSV rules via Go's encoding/csv.
TabulateTSV and SplitColumnsTSV parse tab-separated values and preserve empty cells. Use these when your data may contain empty fields between consecutive tabs.
tsv := "a\tb\tc\n1\t\t3\n4\t5\t\n"
output, _ := tab.TabulateTSV(tsv)
fmt.Print(output)
// a b c
// 1 3
// 4 5If you prefer the whitespace-driven behaviour (collapsing consecutive whitespace), keep using Tabulate(input, false).