Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jun 3, 2021
Merged

Conversation

AskAlice
Copy link
Contributor

@AskAlice AskAlice commented Jun 3, 2021

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
Copy link
Owner

LGTM

@briandowns briandowns merged commit c83d88d into briandowns:master Jun 3, 2021
@fatih
Copy link

fatih commented Jun 21, 2021

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.

fatih added a commit to planetscale/cli that referenced this pull request Jun 21, 2021
@briandowns
Copy link
Owner

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

fatih added a commit to planetscale/cli that referenced this pull request Jun 21, 2021
@AskAlice
Copy link
Contributor Author

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

@HarryMichal
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants