...
1
2
3
4
5 package tabwriter_test
6
7 import (
8 "fmt"
9 "os"
10
11 "github.com/liggitt/tabwriter"
12 )
13
14 func ExampleWriter_Init() {
15 w := new(tabwriter.Writer)
16
17
18 w.Init(os.Stdout, 0, 8, 0, '\t', 0)
19 fmt.Fprintln(w, "a\tb\tc\td\t.")
20 fmt.Fprintln(w, "123\t12345\t1234567\t123456789\t.")
21 fmt.Fprintln(w)
22 w.Flush()
23
24
25
26
27 w.Init(os.Stdout, 5, 0, 1, ' ', tabwriter.AlignRight)
28 fmt.Fprintln(w, "a\tb\tc\td\t.")
29 fmt.Fprintln(w, "123\t12345\t1234567\t123456789\t.")
30 fmt.Fprintln(w)
31 w.Flush()
32
33
34
35
36
37
38
39 }
40
41 func Example_elastic() {
42
43
44 w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, '.', tabwriter.AlignRight|tabwriter.Debug)
45 fmt.Fprintln(w, "a\tb\tc")
46 fmt.Fprintln(w, "aa\tbb\tcc")
47 fmt.Fprintln(w, "aaa\t")
48 fmt.Fprintln(w, "aaaa\tdddd\teeee")
49 w.Flush()
50
51
52
53
54
55
56 }
57
58 func Example_trailingTab() {
59
60
61 const padding = 3
62 w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, '-', tabwriter.AlignRight|tabwriter.Debug)
63 fmt.Fprintln(w, "a\tb\taligned\t")
64 fmt.Fprintln(w, "aa\tbb\taligned\t")
65 fmt.Fprintln(w, "aaa\tbbb\tunaligned")
66 fmt.Fprintln(w, "aaaa\tbbbb\taligned\t")
67 w.Flush()
68
69
70
71
72
73
74 }
75
76 func Example_rememberWidth() {
77
78
79 const padding = 3
80 w := tabwriter.NewWriter(os.Stdout, 4, 6, 3, ' ', tabwriter.RememberWidths|tabwriter.Debug)
81 fmt.Fprintln(w, "a\tb\tc")
82 fmt.Fprintln(w, "ddd\teeeee\tfff")
83 w.Flush()
84 fmt.Fprintln(w, "g\thh\tii")
85 fmt.Fprintln(w, "jjj\tk\tl")
86 w.Flush()
87 fmt.Fprintln(w, "mmmmm\tn\to")
88 fmt.Fprintln(w, "p\tqqq\trrr")
89 w.Flush()
90
91
92
93
94
95
96
97
98 }
99
View as plain text