JColor: ColoredPrinter.print does not behave like System.out.print
The Javadoc says ColoredPrinter.print is a
Usual System.out.print
This is not the case for me. Calling it does not immediately print my string; System.out.print correctly does in its place. Instead, my string appears with the next output made with ColoredPrinter.print or ColoredPrinter.println (or their equivalents from System.out).
For now I am using regular System.out in its place - I’d rather use ColoredPrinter as in the rest of my code though.
Is this a known and fixable error?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 23 (13 by maintainers)
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.
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 theif(enabled)checks. It’s for the very simple logger that I made.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: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 asinfoNoLine(String message)but it works both in IntelliJ and incmd.exe.Let me know if I can provide any other details that might be helpful for fleshing out this issue.
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 useSystem.out, because that’s what the Javadoc says. But it didn’t. You’re right, the implementation doesn’t match the doc.UnixColoredPrinterusesSystem.outto print (code).WindowsColoredPrinter, your case, uses AnsiConsole from Jansi to print (code).From Jansi’s official doc:
Is that a problem to you?
PrintStreamshould work just likeSystem.out– check this SO question.I can update the Javadoc, besides that I’m not sure what I can do to help you.