Comments (23)
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
usesSystem.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.
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.
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.
What version are you using of this lib?
What is your operating system?
from jcolor.
I am using JCDP version 2.0.3.1 and Windows 10.
Sorry, forgot about the OS in the og post *facepalm
from jcolor.
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.
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.
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.
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.
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:
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:
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.
@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.
@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.
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.
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):
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.
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.
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.
from jcolor.
Oops! 2019.2.4 🤣
from jcolor.
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.
⬆️ Run config ⬆️
⬇️ Launching the project through mvnw exec:java
⬇️
The project SDK version is 11.0.3 and the language level is 11.
from jcolor.
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.
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
IntelliJ (using Gradle) as Windows
iTerm (using Gradle) as Linux
from jcolor.
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:
from jcolor.
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.
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)
- 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
- bug report: CLEAR_SCREEN is not portable HOT 4
- 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.