Comments (4)
Released: https://github.com/dialex/JColor/releases/tag/v5.4.1
(hopefully it works, because I don't want to spend more of my Sunday fixing it 🤞😬)
from jcolor.
So you say that \033[2J
works on Windows, but not on modern terminals.
- I tried IntelliJ's terminal in MacOS and it works.
- I tried iTerm2 in MacOS and it works.
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 cmd.exe
. If they use Windows Terminal everything works out of the box.
I did notice something not quite right. That 2J
escape code is adding new lines to push the text up and therefore clear the screen. That's not the behaviour I expect. I would like the text to be pushed up without adding empty space. So that needs tweaking.
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
I've decided to fix my ANSI escape code from "\033[2J"
to "\033[H\033[2J"
as that is producing the result I'm looking for. This works on any terminal that supports ANSI escape codes. As mentioned, Windows users can either use a compatible terminal (Windows Terminal) or do the workaround.
from jcolor.
Notice that the first example is your suggestion. I can't use it as it deletes all text previous displayed.
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. 👍
from jcolor.
// 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);
That's what I also faced. That was not the expected behaviour. I expected that the CLEAR_SCREEN
command should do the same like clear
in Unix or cls
in Windows. That's why I thought that the escape sequence is not working for me, then I tried some other terminals, and the same happened.
from jcolor.
Related Issues (20)
- Refactor: foreground and background words
- Which escape code to use?
- Test: convert acceptance test to snapshot test HOT 2
- Feature: allow dev to display color without printers HOT 1
- Fix "ghost formatting" on background
- Address all warnings in the code HOT 1
- Debugging Output in Eclipse IDE Does not format the markup HOT 1
- Probably Trailing new lines not supported/Line Break Issue HOT 4
- BACK_COLOR for True colors doesn't seem to work when I try with 5.0.0 HOT 7
- Colors don't work in Windows 10 command prompt + powershell HOT 2
- First word not printed properly HOT 2
- Feature: Support of clear screen HOT 4
- Import in java program HOT 2
- Windows Command Line and Powershell display ANSI escape codes instead of expected formatting HOT 8
- README.md code samples are confusing HOT 1
- Simple formatter like Color.format("text") with BB Codes or Markdown Syntax? HOT 3
- feature request: remove the jna dependency HOT 1
- Doesn't work on command prompt HOT 3
- Since v5.3.1 compile time dependencies include all maven-bundle-plugin dependencies HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jcolor.