ANSI character not working for eclipse console on Ubuntu Linux - java

I am fairly new to Java and need your help. I am trying to change the color of the text in Eclipse console on run-time. I referred to one of the posts and tried to follow that. But the output shows a box of unicode escape character and the color of the text remains unchanged.
public static void main(String[] args)
{
System.out.println((char)27 + "[31mTest red color");
}
OUTPUT:
|00|
|1B| [31mTest red color
Notes:
For output, I couldn't upload the image so i have typed [001B].
The console uses UTF-8 encoding.
UPDATE
Following the comment from Jarrod for possible duplication of the question, here is my update -
The question is mainly for ANSI character not working and not for text color, so i have updated the question.

Eclipse does not support ANSI escape characters out of the box.
You have to install a plugin for that: https://marketplace.eclipse.org/content/ansi-escape-console

Related

java processing replaces unicode char to square

I'm developing a java project with eclipse v2021-3, with the software processing v3.5.4, and I want to put unicode characters as a text on my screen.
I can do that and have positive results with no problem, just by doing this:
#Override
public void mousePressed(PApplet p) {
p.text("\u2196", 10, 10); // "\u2196" code for arrow top-left
}
But whenever I try to change the textSize:
p.textSize(10);
It turns all the unicode characters into squares, despite the size I choose.
https://prnt.sc/12pykgs -> this is a screenshot of before and after I scale the text.
In my work colleague is also working with eclipse and processing in her computer and she can do this without any problems, and I've looked for help on the forums and I haven't found anything.
Thank you in advance if you can help me with this problem! :)
Host OS configuration problem, not a programming problem
Likely not a Java programming problem, nor a problem with Eclipse. Likely a problem related to font problems on your particular computer.
See similar code run live on IdeOne.com.
String input = "\u2196" ;
System.out.println( input ) ;
โ†–
Code point U+2196 in hex (8,598 decimal) is NORTH WEST ARROW.
You should be seeing this character if your display app is running on a computer offering a font with a defined glyph. If none of the available fonts has such a glyph, you will get a fall-back glyph such as empty box.

How to print non-ascii character in java?

class P1
{
public static void main(String[] args)
{
System.out.println("ยข");
}
}
it comes as only one question mark in command prompt...if you know then please help me out.
Your terminal does not support UTF-8, you're most likely running Windows. Google to see how to change that.
The problem is almost certainly with the characters your default console/ide can display. Even when displayed on the screen, utf characters need a utf enabled font for them to render correctly.
There are probably Java UTF text editors on GitHub that you could use as a console replacement. Then what you need is an OutputStream that will append to the text editor panel (I created something of this ilk years ago: https://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/TextAreaOutputStream.java) and then you need to use
System.setOut
and
System.setErr
With your Stream

Unicode arrow character prints on Mac but not Windows

I have a Java program that is meant to print a Unicode LEFTWARDS ARROW character, โ†:
public class test {
public static void main(String[] args) {
System.out.print("\u2190");
}
}
When I run this program in Eclipse on a Mac computer, the console prints the proper arrow symbol, โ†. However, when I run the exact same code on a Windows 10 machine, the Unicode character prints as a question mark, ?.
I also tried printing an arrow character in a C++ program on my Windows computer, and got the same Unicode rendering problem.
I don't know when this stopped working and if it is a recent Windows update that is causing the character to not display properly, but I do know that this code used to work and doesn't anymore.
Any ideas as to why this code is not rendering the correct Unicode character on Windows?
Update
To address #ElliotFrisch's comment, I checked which font my Eclipse console is using, and it is using Consolas. I opened the font Character Map in Control Panel, and Consolas does seem to have a leftwards arrow, U+2190 character:
I also tried changing the font to different common fonts like Times New Roman, Calibri, Cambria and Arial, but none of those printed the correct arrow character.

How do you print out a black box char in Java?

I thought this would print out a black box: System.out.print('\u25A0');
But for some reason this only prints out question marks.
The console window has to use a TrueType font in order to display Unicode. Unix can show it but if you are using Windows console, this console doesn't use font substitution, there's little you can do to make them show up. If you're using IDE like IntellijIdea inside windows, it doesn't treat console output as a grid of character cells, but rather a text stream (as is usual in Unix, but not Windows) and displays it accordingly.

Print unique ascii characters in eclipse console

Kind of a strange question but... here it goes.
Recently my application threw an IOException that the text only had a clubs symbol in it (like the suit in cards) I know this is probably because there was a number in there that was cast to a char and printed to the screen, and I've found where that might have happened. The only problem is, I can't recreate it in eclipse because the eclipse console doesn't want to print those characters for me. All I get are boxes.
I figure this is an encoding issue or something but I need eclipse to print out those characters just like the windows console would. Is there a setting I can change to do this?
The respective Unicode character is U+2663. Just print "\u2663" and you should be fine. This has nothing to do with ASCII, though.
If you get boxes it may also be a font issue. If the font you selected for the console view in Eclipse does not have a glyph for that code point you'll get boxes, usually. The character might still correctly printed, though. Usually monospaced fonts have that character, though, since it was historically part of the glyphs for the control characters below character code 32 (not that control characters ever had the intention of a visual appearance, but well, they could be in the screen buffer, so someone thought it would be a good idea to display them as well).

Categories

Resources