Not working on windows terminal
radbrawler opened this issue · 3 comments
I'm not able to make it work on windows terminal.
package main
import (
"time"
"sync"
tm "github.com/buger/goterm"
)
func main() {
defer tm.Println("\nAll is said and done.")
var wg sync.WaitGroup
ticker := time.Tick(time.Second)
for i := 1; i <= 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
<-ticker
tm.MoveCursor(1, 1)
// log.Printf("\CLS")
tm.Printf("On %d/10 ", i)
tm.Println(tm.Background(tm.Color(tm.Bold("Important header"), tm.RED), tm.WHITE))
tm.Flush()
}(i)
}
wg.Wait()
}
Desired Output:
On 10/10 Important header
Important Header in Red Bold with White Background.
Output:
�[1;1HOn 1/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 6/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 5/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 7/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 2/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 3/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 8/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 9/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 10/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
�[1;1HOn 4/10 �[47m�[31m�[1mImportant header�[0m�[0m�[0m
Is there a specific way to make it work or are windows terminals not compatible with the lib.
Well, looks like Windows do not support standard ANSI codes (except Windows 10), there is alternative ways. Here is the list of workarounds http://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line.
There are Go libraries that managed this difference, for example, https://github.com/fatih/color (which use https://github.com/mattn/go-colorable).
I found this as an alternative approach to make ANSI codes work.
tm.Output = bufio.NewWriter(color.Output)
fixed it for me in PowerShell. In command prompt it doesn't clean the screen, but moving the cursor works.
PowerShell has strange color choices though, magenta is just same as blue background. In prompt it's ok...