-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
bug report: CLEAR_SCREEN is not portable #68
Comments
So you say that
I consider iTerm2 a modern terminal. Can you give an example of a terminal where this code doesn't work? This source confirms that the ANSI escape code I used is right. This other source contradicts what you said, that the code works on every OS except Windows (unless you enable VT). 🤔 Note that Windows 10 users already have to enable VT for ANSI escape codes to work on I did notice something not quite right. That So I tested lots of different flavours and these were the results // Actually deletes the previous text from the screen
// char escapeChar = 27;
// String cmd = Character.toString(escapeChar) + 'c';
// System.out.println(cmd);
// Actually deletes the previous text from the screen
// System.out.print("\033\143");
// Pushes the previous text up, by adding multiple new lines, and does not place new text at the top
// String cmd = Ansi.generateCode(CLEAR_SCREEN());
// System.out.println(cmd);
// Pushes the previous text up, no new lines, new text at the top. Perfection.
// System.out.print("\033[H\033[2J");
// System.out.flush();
// Pushes the previous text up, no new lines, new text at the top. Perfection.
// System.out.print("\033[H\033[2J");
// Does nothing
// Runtime.getRuntime().exec("clear"); Notice that the first example is your suggestion. I can't use it as it deletes all text previous displayed. tl;dr |
That's exactly the point! That's why I said that your escape sequence does not work on modern terminals, because I thought that by the command CLEAR_SCREEN, you meant to clear all previous texts, permanently. If you mean just pushing the previous texts up by the word 'CLEAR', then you are right from your perspective. Go ahead. Good luck. 👍 |
That's what I also faced. That was not the expected behaviour. I expected that the |
Released: https://github.com/dialex/JColor/releases/tag/v5.4.1 |
Current implementation of the CLEAR_SCREEN command returns only
\033[2J
which works on Windows but on not in many other modern terminals.Most of the terminals used today are VT terminals, which includes most of the modern Linux and Mac terminals and the Windows Terminal available since Windows 10+. The escape sequence for clearing the screen and the scroll-back in a VT terminal is
\033c
. This should also work in the Windows Command Prompt if VT (support for ANSI) is enabled. This works exactly like callingclear
in Linux orcls
in Windows.Some other Linux terminals, like the KDE Console (Konsole) and XTerm support
\033[3J
for clearing the screen and resetting the scroll-back.In my opinion,
\033c
will be the most platform-independent implementation. But users should be able to provide custom escape sequence implementation for the CLEAR_SCREEN command.Source: https://stackoverflow.com/a/5367075
The text was updated successfully, but these errors were encountered: