Last active
June 17, 2020 00:42
-
-
Save RoryQ/2553f3e0803053a06543c38c0cc3527d to your computer and use it in GitHub Desktop.
Golang text/tabwriter
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "text/tabwriter" | |
| ) | |
| func main() { | |
| minwidth := 0 // minimal cell width including any padding | |
| tabwidth := 4 // width of tab characters (equivalent number of spaces) | |
| padding := 1 // padding added to a cell before computing its width | |
| padchar := byte('\t') // ASCII char used for padding | |
| w := tabwriter.NewWriter(os.Stdout, minwidth, tabwidth, padding, padchar, tabwriter.AlignRight) | |
| fmt.Fprintln(w, "|Column 1\tColumn 2\tColumn 3\tColumn 4\t|") | |
| fmt.Fprintln(w, "|123\t12345\t1234567\t123456789\t|") | |
| fmt.Fprintln(w) | |
| w.Flush() | |
| /* | |
| |Column 1 Column 2 Column 3 Column 4 | | |
| |123 12345 1234567 123456789 | | |
| */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment