1
2
3
4
5 package tabwriter_test
6
7 import (
8 "fmt"
9 "os"
10 "text/tabwriter"
11 )
12
13 func ExampleWriter_Init() {
14 w := new(tabwriter.Writer)
15
16
17 w.Init(os.Stdout, 0, 8, 0, '\t', 0)
18 fmt.Fprintln(w, "a\tb\tc\td\t.")
19 fmt.Fprintln(w, "123\t12345\t1234567\t123456789\t.")
20 fmt.Fprintln(w)
21 w.Flush()
22
23
24
25
26 w.Init(os.Stdout, 5, 0, 1, ' ', tabwriter.AlignRight)
27 fmt.Fprintln(w, "a\tb\tc\td\t.")
28 fmt.Fprintln(w, "123\t12345\t1234567\t123456789\t.")
29 fmt.Fprintln(w)
30 w.Flush()
31
32
33
34
35
36
37
38 }
39
40 func Example_elastic() {
41
42
43 w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, '.', tabwriter.AlignRight|tabwriter.Debug)
44 fmt.Fprintln(w, "a\tb\tc")
45 fmt.Fprintln(w, "aa\tbb\tcc")
46 fmt.Fprintln(w, "aaa\t")
47 fmt.Fprintln(w, "aaaa\tdddd\teeee")
48 w.Flush()
49
50
51
52
53
54
55 }
56
57 func Example_trailingTab() {
58
59
60 const padding = 3
61 w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, '-', tabwriter.AlignRight|tabwriter.Debug)
62 fmt.Fprintln(w, "a\tb\taligned\t")
63 fmt.Fprintln(w, "aa\tbb\taligned\t")
64 fmt.Fprintln(w, "aaa\tbbb\tunaligned")
65 fmt.Fprintln(w, "aaaa\tbbbb\taligned\t")
66 w.Flush()
67
68
69
70
71
72
73 }
74
View as plain text