Code Monkey home page Code Monkey logo

Comments (6)

hartmut27 avatar hartmut27 commented on June 7, 2024

It has something to do with Jansi.
If I skip the Jansi Test, everything works fine!

package testprog;

public class AnsiKonsoleTestJansi {

    public static void main(String[] args) {
        // Direct Test
        System.out.println("Hello \u001b[1;31mred\u001b[0m world!");
    }
}

Produces:

Hello �red world!

where red is printed in red 👍

from ansi-econsole.

hartmut27 avatar hartmut27 commented on June 7, 2024

Now it is perfect.

package testprog;

import static org.fusesource.jansi.Ansi.ansi;
import static org.fusesource.jansi.Ansi.Color.GREEN;
import static org.fusesource.jansi.Ansi.Color.RED;

public class AnsiKonsoleTestJansi {

    public static void main(String[] args) {

        // Test with Jansi

        // In Eclipse: Remove:
        // AnsiConsole.systemInstall();

        // In Eclipse: Don't do eraseScreen().
        System.out.println(ansi().isEnabled());
        System.out.println(ansi().fg(RED).a("Hello").fg(GREEN).a(" World")
                .reset());
        System.out.println(ansi().render("@|red Hello|@ @|green World|@"));

        // Direct Test
        System.out.println("Hello \u001b[1;31mred\u001b[0m world!");

    }
}

from ansi-econsole.

paulvi avatar paulvi commented on June 7, 2024

Do you use http://mvnrepository.com/artifact/org.fusesource.jansi/jansi/1.11 ?

<dependency>
    <groupId>org.fusesource.jansi</groupId>
    <artifactId>jansi</artifactId>
    <version>1.11</version>
</dependency>

nice to know

from ansi-econsole.

mihnita avatar mihnita commented on June 7, 2024

@paulvi
Yes, I like jansi; (in fact, I have even contributed some improvements :-)

I usually download jansi directly from http://jansi.fusesource.org/
And when I need it in maven (for instance in https://github.com/mihnita/java-color-loggers), then I add the dependency, and "just works" (probably comes from mvnrepository, but I have never checked)

from ansi-econsole.

mihnita avatar mihnita commented on June 7, 2024

@hartmut27

One of my comments at http://mihai-nita.net/java has another solution, jansi.passthrough:

One cause possible: many libraries detect if the standard output is redirected, and if that is the case, they don’s output ANSI escapes anymore.

In most cases there are ways to force them to do that, but the solution is library specific. One example is jansi, and the way to force it is by setting jansi.passthrough

This means you can pass it as a parameter at execution and you don't need to touch the code at all.

from ansi-econsole.

hartmut27 avatar hartmut27 commented on June 7, 2024

@paulvi, mihnita
yes, I am using jansi Version 1.11.
I can confirm: doing before anything else:

System.setProperty("jansi.passthrough", "true");

works perfect.

from ansi-econsole.

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.