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

Is there anyway to clear screen? #5

Open
zsh2401 opened this issue Aug 12, 2022 · 5 comments
Open

Is there anyway to clear screen? #5

zsh2401 opened this issue Aug 12, 2022 · 5 comments

Comments

@zsh2401
Copy link

zsh2401 commented Aug 12, 2022

Just like unix clear command.

@A-312
Copy link
Owner

A-312 commented Aug 12, 2022

@zsh2401
Copy link
Author

zsh2401 commented Aug 14, 2022

Try with ANSI escape code https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences

Thank you! Here's my code:

process.stdout.write("\r\x1b[1J", () => {
        process.stdout.write("\r\x1b[3J", () => {
            console.log("")
        })
})

As you can see, after using that to clear screen, I have to use console.log to make serverline's prompt works correctly. Is there any way more graceful to fix this issue?

@A-312
Copy link
Owner

A-312 commented Sep 12, 2022

Did you try : process.stdout.write("\x1Bc"); ?

@zsh2401
Copy link
Author

zsh2401 commented Sep 13, 2022

: process.stdout.write("\x1Bc")

This seems won't work, prompt will miss util I input an Enter

@pocketfood
Copy link

Your code is not working because its a ansi escape character. Its going back one character not clearing screen. I suggest putting the process.stdout.write("\x1Bc"); globally before the prompt. Also ctrl+L and console.clear(); works but that depends on what operating system you have and what kind of terminal you use.
Hope it helps.

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

No branches or pull requests

3 participants