我正在使用制表符,但无法使用颜色。我正在使用“github.com/fatih/color”包。
基本上问题是我需要调用 tabwriter'sw.Flush()以便让颜色呈现......如果我没有调用刷新,我就无法切换颜色。
依次调用 Flush 与 tabwriter 格式。
关于如何将两者结合的任何想法?
package main
import "fmt"
import "text/tabwriter"
import "os"
import "github.com/fatih/color"
func main() {
w := new(tabwriter.Writer)
w.Init(os.Stderr, 0, 8, 0, '\t', 0)
color.Set(color.FgGreen)
fmt.Fprintln(w, "ID\tNAME\tSIZE\tFIELD1\tSTATUS\tSTATE")
// ------> Calling w.Flush() here cases problems.
color.Set(color.FgYellow)
fmt.Fprintln(w, "8617833164795356724\tfoo1\t1.1 Gb\t3\tsome_status\tsome_state")
fmt.Fprintln(w)
w.Flush()
}
素胚勾勒不出你
莫回无
相关分类