GithubHelp home page GithubHelp logo

Comments (23)

dialex avatar dialex commented on May 27, 2024 1

No need to be sorry, it's easy to forget, especially when I don't provide a template for bug reports (but now I improved it, thanks to you 😉)

Regarding your issue, I'm having trouble understanding what your problem is. Here's my current understanding:

You expected ColoredPrinter.print(msg) to use System.out, because that's what the Javadoc says. But it didn't. You're right, the implementation doesn't match the doc.

  • The UnixColoredPrinter uses System.out to print (code).
  • The WindowsColoredPrinter, your case, uses AnsiConsole from Jansi to print (code).

From Jansi's official doc:

If the standard out natively supports ANSI escape codes, then this just returns System.out, otherwise it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences or which implement the escape sequences.

Is that a problem to you? PrintStream should work just like System.out -- check this SO question.

I can update the Javadoc, besides that I'm not sure what I can do to help you.

from jcolor.

IncPlusPlus avatar IncPlusPlus commented on May 27, 2024 1

Hi @dialex, I'm having the same issue as @DesertCookie with a little twist (you'll see why soon). I'm on Windows 10 and using version 2.0.3.1 of your library. This is awesome, by the way. I appreciate how much effort was put into this library and am grateful for its existence.

Right now, I have a method info(String message) that is defined below. Don't worry about the if(enabled) checks. It's for the very simple logger that I made.

public static void info(String message) {
		if (enabled) {
			cp.clear();
			cp.println(message, Ansi.Attribute.NONE, Ansi.FColor.CYAN, Ansi.BColor.BLACK);
			cp.clear();
		}
	}

This function works perfectly fine. However, if I want to print using this formatter but not have a newline at the end of the message, I have a method infoNoLine(String message) defined as follows:

public static void infoNoLine(String message) {
		if (enabled) {
			cp.clear();
			cp.print("message", Ansi.Attribute.NONE, Ansi.FColor.CYAN, Ansi.BColor.BLACK);
			cp.clear();
		}
	}

Here's where things get interesting. This works perfectly fine for me in Windows' cmd.exe. However, it does not work for me inside of IntelliJ's console window. Instead, nothing is printed at all. I currently have a temporary fix that seems to be doing the job. It works the same as infoNoLine(String message) but it works both in IntelliJ and in cmd.exe.

public static void infoNoLineTempFix(String message) {
		if (enabled) {
			cp.clear();
			//set formatter but don't print anything
			cp.print("", Ansi.Attribute.NONE, Ansi.FColor.CYAN, Ansi.BColor.BLACK);
			//use System.out.print to print the actual message
			System.out.print(message);
			//clear the formatting for whatever might use System.out next
			cp.clear();
		}
	}

Let me know if I can provide any other details that might be helpful for fleshing out this issue.

from jcolor.

IncPlusPlus avatar IncPlusPlus commented on May 27, 2024 1

I'll try that when I get the chance. It likely won't be for a day or two. Your assumption is correct. IntelliJ outputs its default white text and is not affected by the ANSI codes that should be included.

from jcolor.

dialex avatar dialex commented on May 27, 2024

What version are you using of this lib?
What is your operating system?

from jcolor.

DesertCookie avatar DesertCookie commented on May 27, 2024

I am using JCDP version 2.0.3.1 and Windows 10.
Sorry, forgot about the OS in the og post *facepalm

from jcolor.

DesertCookie avatar DesertCookie commented on May 27, 2024

Glad I was the cause of improvement.
I will investiage and mess around myself to find out why the two calls behave so differently on Windows.

from jcolor.

dialex avatar dialex commented on May 27, 2024

find out why the two calls behave so differently on Windows

Can you give an example? What do you see that is different? I'm curious.

from jcolor.

DesertCookie avatar DesertCookie commented on May 27, 2024

As I stated, visually there is no difference, but there is one in behavior, which makes the call to ColoredPrinter.print useless (in my usage scenario): it does not print to console immediately after being called, but rather later, when the next print call to (in my case) System.out takes place.

from jcolor.

dialex avatar dialex commented on May 27, 2024

Ah, like it stores the message to print in a buffer and only actually prints it when you call it twice? I checked my unit tests, and it should cover that case (printing a single message).

However I only run unit tests for the NIX printer, I should duplicate them for the WIN printer as well. I'll do that this Friday.

from jcolor.

dialex avatar dialex commented on May 27, 2024

Thank for your kind words @IncPlusPlus 🙇

I think I was able to reproduce your issue unit tests on #24. I missed it because I only had for NIX printers, ups! The same unit test is passing on Travis (Ubuntu) and failing on IntelliJ (Mac).

I used the unit from the NIX and it failed when targeting a WIN printer:

Screenshot 2019-11-17 at 19 38 33

Even though the message output is colored, the test was not able to find the ANSI code. I assumed this was because Jansi had detected that IntelliJ's terminal could not handle ansi codes, so it automatically converted the code to color. That behaviour matches their doc: "it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences".

So I changed the test to assert that the ANSI code is not in the message. That worked on IntelliJ. When the same test executed on Travis (Ubuntu) it failed:

Screenshot 2019-11-17 at 19 37 08

Because Travis knows how to handle ANSI codes, Jansi did not handle the code, therefore it was present in the message, thus failing the test. Cross-platform is a headache... 😵

from jcolor.

dialex avatar dialex commented on May 27, 2024

@IncPlusPlus Can you show the code that use to create and assign cp?
Can you try assigning a new WindowsColoredPrinter... instead of new ColoredPrinter...?

P.S: doing a cp.clear() before and after printing is a bit of an overkill, specially if you specify a format on your print message. That will override whatever the current format is.

from jcolor.

IncPlusPlus avatar IncPlusPlus commented on May 27, 2024

@dialex Good to know. I'll make some adjustments when I get the chance. Right now I'm using JDCP for debug/logging in a project of mine. Here is how it is being used. All my other classes call info() debug() and error(). The reason I have some synchronized methods is to prevent simultaneous calls from printing over each other.

from jcolor.

dialex avatar dialex commented on May 27, 2024

Nice, public code :)
So try replacing ColoredPrinter with WindowsColoredPrinter (line 11) and check if it fixes the IntelliJ issue (I'm assuming is text not colored).

from jcolor.

dialex avatar dialex commented on May 27, 2024

Take your time, I'm already grateful that a student has the patience to debug an open-source dependency of their project! 🙏

What is bugging me is that, using the same JCDP version you have, my IntelliJ prints colored output (using the example code provided in the Readme). Notice the code (ColoredPrinter instance), the java version (1.8.0.202), and terminal (with colored msgs):

Screenshot 2019-11-17 at 20 11 31

Maybe you're using an old version of IntelliJ that doesn't support colors?
I'm using 2019.2.4 (Community Edition) and you?

from jcolor.

IncPlusPlus avatar IncPlusPlus commented on May 27, 2024

2019.4 for both CE and Ultimate. I use Ultimate for personal and school projects and CE for work. I might be remembering the output incorrectly. I'll check.

from jcolor.

dialex avatar dialex commented on May 27, 2024

2019.4???? Are you from the future? 🤣 The latest is 2019.2.4 and they're announcing what's coming on 2019.3, I doubt there's a 2019.4. Check again please.
Screenshot 2019-11-17 at 20 23 00

from jcolor.

IncPlusPlus avatar IncPlusPlus commented on May 27, 2024

Oops! 2019.2.4 🤣

from jcolor.

IncPlusPlus avatar IncPlusPlus commented on May 27, 2024

When I launch my project through an IntelliJ run configuration, no colored text ends up in the console. However, if I launch my project using IntelliJ's terminal the colored text does appear.

image
⬆️ Run config ⬆️
⬇️ Launching the project through mvnw exec:java ⬇️
image

The project SDK version is 11.0.3 and the language level is 11.

from jcolor.

dialex avatar dialex commented on May 27, 2024

I just released a new version of JCDP (3.0.0) that upgrades Jansi (which I use to print color on Windows). Before I investigate any further, can you (@DesertCookie @IncPlusPlus) please use my new version and tell me if the issue persists?
P.S: Mind that it requires Java 8, hope it's not a problem 🤞

from jcolor.

dialex avatar dialex commented on May 27, 2024

My environment:

  • JCDP 3.0.0
  • IntelliJ CE 2019.3 (latest) -> behaves like Windows
  • iTerm 3.3.7 on macOS -> behaves like Linux

I tried running the demo code on IntelliJ (to simulate Windows) and iTerm (to simulate Linux) and both printed the expected colors. Can you upgrade JCDP and IntelliJ and confirm if that fixes the issue? Screenshots below.

IntelliJ (default) as Windows

Screenshot 2019-12-15 at 19 05 30

IntelliJ (using Gradle) as Windows

Screenshot 2019-12-15 at 19 05 37

iTerm (using Gradle) as Linux

Screenshot 2019-12-15 at 19 06 58

from jcolor.

dialex avatar dialex commented on May 27, 2024

I also tried exactly your 3 lines of code, on exactly the same way (inside IntelliJ's command line) and still the output was colored as expected:
Screenshot 2019-12-15 at 19 20 07

from jcolor.

DesertCookie avatar DesertCookie commented on May 27, 2024

Before I investigate any further, can you (@DesertCookie @IncPlusPlus) please use my new version and tell me if the issue persists?

My original problem of the printed message not appearing until the next print is called still persists. At this point I'm thinking it may be a Java problem, or a me problem.
I'm calling ColoredPrinter.print, then waiting for some input with Scanner.nextLine. The input is made, a debug message is printed using ColoredPrinter.println. The resulting output would look like this...

userinput
> [DEBUG] message

...instead of this...

> userinput
[DEBUG] message

. Instead of [print, ENTER, println], it appears [ENTER, print, println] is happening.

Am I just stupid, or is there some seriosly crazy stuff going on?


P.S: Mind that it requires Java 8, hope it's not a problem 🤞

I tried both Java 8.0.232 and Java 11.0.5; both worked and yielded the same output and general behavior.

from jcolor.

dialex avatar dialex commented on May 27, 2024

I'm sorry @DesertCookie, I'm not sure what is the issue and what causes it 🤷‍♂
I'll close this topic, if you don't mind.

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.