Go Package text/tabwriter
Jump to navigation
Jump to search
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