briandowns / spinner

Go (golang) package with 90 configurable terminal spinner/progress indicators.
Apache License 2.0
2.33k stars 129 forks source link

replace \033[K with \r in clear #117

Closed AskAlice closed 3 years ago

AskAlice commented 3 years ago

seems that in WSL it doesn't actually clear the line when just using \033[K, but it does with \r. In Powershell, however it does clear the line.

image

this fixes that

briandowns commented 3 years ago

LGTM

fatih commented 3 years ago

This change broke the clearing the lines for our CLI https://github.com/planetscale/cli.

I'm not sure what's going on with WSL, but to fix it, I had to print a new escape sequence:

fmt.Fprint(p.out(), "\033[2K")

The 2K, means to remove the entire line:

Erases part of the line. If n is 0 (or missing), clear from cursor to the end of the line. 
If n is 1, clear from cursor to beginning of the line. If n is 2, clear entire line. 
Cursor position does not change.

Esc[K   Clear line from cursor right   EL0
Esc[0K  Clear line from cursor right   EL0
Esc[1K  Clear line from cursor left    EL1
Esc[2K  Clear entire line              EL2 

https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences

I suggest to revert this change or guard it and only call \r if it detects WSL.

briandowns commented 3 years ago

Change reverted and cutting new release. We will need to address this fix again.

AskAlice commented 3 years ago

detecting the presence of /etc/wsl.conf is the most consistent way, but you can also grep Microsoft /proc/version

HarryMichal commented 2 years ago

Why is \r causing a line to be deleted? I only know it as Carriage Return and I wouldn't expect it to delete lines.