Go Package text/tabwriter: Difference between revisions
Jump to navigation
Jump to search
Line 16: | Line 16: | ||
fmt.Fprintf(tw, "aaaaaaaaaaaaa\tb\tcccc\n") | fmt.Fprintf(tw, "aaaaaaaaaaaaa\tb\tcccc\n") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
produces | |||
<font size=-2> | |||
Column A Column B Column C | |||
a bbbbbb ccc | |||
aaaa bb ccc | |||
aaaaaaaaaaaaa b cccc | |||
</font> |
Revision as of 04:04, 20 January 2024
External
Internal
Overview
The package implements a write filter that translates tabbed columns in input into properly aligned text. The package is using the Elastic Tabstops algorithm described at http://nickgravgaard.com/elastictabstops/index.html.
tw := tabwriter.NewWriter(os.Stdout, 0, 1, 2, ' ', 0)
defer tw.Flush()
fmt.Fprintf(tw, "Column A\tColumn B\tColumn C\n")
fmt.Fprintf(tw, "a\tbbbbbb\tccc\n")
fmt.Fprintf(tw, "aaaa\tbb\tccc\n")
fmt.Fprintf(tw, "aaaaaaaaaaaaa\tb\tcccc\n")
produces Column A Column B Column C a bbbbbb ccc aaaa bb ccc aaaaaaaaaaaaa b cccc