Closed verkestk closed 7 years ago
Things get complicated here: https://github.com/fatih/color/blob/9131ab34cf20d2f6d83fdc67168a5430d1c7dc23/color.go#L441-L443
This part adds a newline escape sequence to every string str
you used with Cyan
function as an argument and since your string is now str\n
and the nondestructive backspace only works on the current line, you won't be able to have same results with fmt.Print
when you use \b
.
This can be hurdled by simply removing the mentioned lines.
Here's a workaround for you,
fmt.Print(CyanString("Hello..."))
fmt.Print(CyanString("\b\b\b, World!\n"))
P.S.: I'm not sure if this is an issue, rather, I guess, it's a design choice but I'm in the same side with you and I would prefer these lines to be removed.
Hi @verkestk
@malisit is right. It's a design decision for the custom function. However you can use the constructors which don't have the problem:
func main() {
fmt.Println("with fmt:")
fmt.Print("Hello...")
fmt.Println("\b\b\b, World!\n")
fmt.Println("with custom color:")
c := color.New(color.FgCyan)
c.Print("Hello...")
c.Println("\b\b\b, World!\n")
}
This works as indented:
Thanks for the feedback and thanks @malisit for the lookup. I'm closing as this is expected.
Backspace character is not clearing previously output characters.
See screenshot:
I'm running zsh on OSX.
Here's the program to repro: