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

Use more universal ANSI sequence for 'clear screen and clear buffer' #57701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

colinta
Copy link

@colinta colinta commented Mar 8, 2024

Fixes ##57700

Tiny tiny patch to bring just a little more terminal support to tsc --watch. In my case, iTerm2 needs this ESC [ 3J sequence in order to clear screen and remove scroll history.

If there's a setting in iTerm2 to change this, I would happily do that, but I didn't see anything.

  92049 passing (6m)

Finished do-runtests-parallel in 6m 22.9s
Completed runtests-parallel in 6m 57.3s
✨  Done in 417.81s.

@mrazauskas
Copy link

For what it’s worth, the ansi-escapes library has two similarly named methods: clearScreen() and clearTerminal().

clearScreen() is the same as current tsc --watch implementation.

clearTerminal() is more complex and it is based on Jest's implementation (see sindresorhus/ansi-escapes#6 and https://github.com/jestjs/jest/blob/6b120fbc5d1cadb3ef205bd1d48549155bed5dd1/packages/jest-util/src/specialChars.ts#L18-L20)

I am pointing to ansi-escapes, because it is rather widely used. Not sure if there are any standards in this field.

@sandersn sandersn added this to Not started in PR Backlog Mar 18, 2024
@sandersn sandersn moved this from Not started to Needs merge in PR Backlog Mar 20, 2024
@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Mar 20, 2024
@jakebailey
Copy link
Member

jakebailey commented Mar 20, 2024

If we're going to do this, I'm somewhat inclined to take the more popular approach of using the same sequence that ansi-escapes/jest take, though that appears to be platform specific which may make our tests unhappy.

I'll have to ask for feedback on this from the team.

@colinta
Copy link
Author

colinta commented Mar 22, 2024

I wonder if we even need to make a distinction between mac and windows

echo -n -e "\x1B[2J\x1B[3J\x1BH\x1B[0f"

Works on all my terminals (Terminal, iTerm, & VSCode). I don't have a Windows machine to test on, though. (I updated the PR to use this sequence)

@colinta colinta changed the title Use 'standard' ANSI sequence for 'clear screen and clear buffer' Use more universal ANSI sequence for 'clear screen and clear buffer' Apr 24, 2024
@colinta
Copy link
Author

colinta commented Apr 25, 2024

The passage of time made me forget the ANSI sequence I had settled on, but I remembered this morning and updated this PR one more time.

So, the sequence in there is based on the one from ansi-sequences. It's just a combination of the two, without the OS check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
PR Backlog
  
Needs merge
Development

Successfully merging this pull request may close these issues.

None yet

5 participants