github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/formatter/formatter.go (about) 1 package formatter 2 3 import ( 4 "io" 5 "text/tabwriter" 6 ) 7 8 // Human tells if the default formatting strategy should be human or machine friendly 9 var Human = false 10 11 // TabWriter for formatting text 12 type TabWriter struct { 13 output io.Writer 14 tabwriter tabwriter.Writer 15 } 16 17 // NewTabWriter creates a TabWriter 18 func NewTabWriter(output io.Writer) *TabWriter { 19 var t = &TabWriter{} 20 t.Init(output) 21 return t 22 } 23 24 // Init TabWriter 25 func (t *TabWriter) Init(output io.Writer) { 26 t.output = output 27 t.tabwriter.Init(output, 4, 0, 4, ' ', 0) 28 } 29 30 // Flush the TabWriter 31 func (t *TabWriter) Flush() error { 32 return t.tabwriter.Flush() 33 } 34 35 // Write content 36 func (t *TabWriter) Write(buf []byte) (n int, err error) { 37 if Human { 38 return t.tabwriter.Write(buf) 39 } 40 41 return t.output.Write(buf) 42 }