GithubHelp home page GithubHelp logo

Comments (4)

dialex avatar dialex commented on May 27, 2024 1

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.

dialex avatar dialex commented on May 27, 2024

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.

PiprTuff avatar PiprTuff commented on May 27, 2024

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.

PiprTuff avatar PiprTuff commented on May 27, 2024

// 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.