[bug] color.Output has indent error when using tabwriter.Writer
Author: fanybookCreated Dec 26, 2022Updated Aug 3, 2024
Env: OS: windows 10 go: 1.17.2 bash: cmd powershell gitbash
package main
import (
"fmt"
"github.com/fatih/color"
"io"
"text/tabwriter"
)
func main() {
tabOut := getTabOutWithWriter(color.Output)
fmt.Fprint(tabOut, "\x1b[0;32m demo\t\tStart the server\n\x1b[0m")
fmt.Fprint(tabOut, "\x1b[0;32m help\t\tHelp about any command\n\x1b[0m")
fmt.Fprint(tabOut, "\x1b[0;32m server:start\t\tStart the server\n\x1b[0m")
tabOut.Flush()
}
func getTabOutWithWriter(writer io.Writer) *tabwriter.Writer {
aTabOut := new(tabwriter.Writer)
aTabOut.Init(writer, 0, 8, 1, '\t', 0)
return aTabOut
}Output:
demo Start the server
help Help about any command
server:start Start the serverSource: fatih/color