Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Text color in Windows console

Reply
Thread Tools

Text color in Windows console

 
 
Xavier
Guest
Posts: n/a
 
      06-03-2005
Hi,

Running java (1.4) under Windows (XP), how can I change the console text
color for a part of the output text, perhaps something like :

System.out.println("This is [?1] green [?2]");

Where [?1] and [?2] are some (ANSI ?) code to set and unset text color in
green.

Thanks

Xavier


 
Reply With Quote
 
 
 
 
Fred L. Kleinschmidt
Guest
Posts: n/a
 
      06-03-2005


Xavier wrote:
>
> Hi,
>
> Running java (1.4) under Windows (XP), how can I change the console text
> color for a part of the output text, perhaps something like :
>
> System.out.println("This is [?1] green [?2]");
>
> Where [?1] and [?2] are some (ANSI ?) code to set and unset text color in
> green.
>
> Thanks
>
> Xavier


There is no portable way to do that. How to do it will depend on the
type of screen being used, or the visual being used on that screen (it
might be running on a black-and-white screen). It will also depend on
what kind of 'terminal' is being used for stdout - Xterm, dtterm, qterm,
dos, etc.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
#! rnews 1721
Xref: xyzzy sci.energy:132022 sci.energy.hydrogen:80848 sci.environment:397270 sci.physics:890044
Newsgroups: sci.energy,sci.environment,sci.energy.hydrogen,sci .physics,alt.politics
Path: xyzzy!nntp
From: "Fred McGalliard" <>
Subject: Re: California Rolls out $54M Hydrogen Highway Plan - Boondoggle
X-Nntp-Posting-Host: e056750.nw.nos.boeing.com
Message-ID: <>
X-Mimeole: Produced By Microsoft MimeOLE V6.00.2800.1441
X-Priority: 3
X-Msmail-Priority: Normal
Lines: 14
Sender: (Boeing NNTP News Access)
Organization: The Boeing Company
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
References: <W%mme.1516$> <> <EWtme.6265$> <. com> <GZ2ne.2602$> < .com> <> < .com> <dTcne.2648$> <. com>
Date: Fri, 3 Jun 2005 14:29:51 GMT


"Tim Campbell" <> wrote in message
news: ups.com...
....
> Though superior in many ways, the "horseless carriage" and fuel was not
> cheaper than horse, wagon and fuel. Economies of choice are not always
> solely driven by price and access.


A major factor, as I recall reading (wasn't there myself), was pollution.
The thousands of folk employed cleaning up horse manure from every street
and alley, and the "smog" of dried horse dung, made the city both dirty and
unhealthy.


 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      06-03-2005
Xavier wrote:

> Hi,
>
> Running java (1.4) under Windows (XP), how can I change the console text
> color for a part of the output text, perhaps something like :
>
> System.out.println("This is [?1] green [?2]");
>
> Where [?1] and [?2] are some (ANSI ?) code to set and unset text color in
> green.
>
> Thanks
>
> Xavier
>
>


Xavier:

Unfortunately the console is stream i/o, black and white only.

If you need more functionality than that, try AWT or Swing.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
Real Gagnon
Guest
Posts: n/a
 
      06-04-2005
> Running java (1.4) under Windows (XP), how can I change the console text
> color for a part of the output text, perhaps something like :
>
> System.out.println("This is [?1] green [?2]");
>
> Where [?1] and [?2] are some (ANSI ?) code to set and unset text color in
> green.


You can use a JNI routine for that.

See http://www.rgagnon.com/javadetails/java-0469.html
for an example.

Bye.
--
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
 
Reply With Quote
 
Lucy
Guest
Posts: n/a
 
      06-04-2005

"Knute Johnson" <> wrote in message
news:1117810422.67a27adf455c87e7d36db3e548ff38cd@1 usenet...
> Xavier wrote:
>
> > Hi,
> >
> > Running java (1.4) under Windows (XP), how can I change the console text
> > color for a part of the output text, perhaps something like :
> >
> > System.out.println("This is [?1] green [?2]");
> >
> > Where [?1] and [?2] are some (ANSI ?) code to set and unset text color

in
> > green.
> >
> > Thanks
> >
> > Xavier
> >
> >

>
> Xavier:
>
> Unfortunately the console is stream i/o, black and white only.


Not true. I just tried running my program on win xt pro. Just prior to
the java command, I entered the following command

cmd /T:78

which set the dos window to gray on silver (or similar). Then the
java program output maintained this color scheme, it did not
switch to black and white.

look into "ansi.sys" it may have what you want

>
> If you need more functionality than that, try AWT or Swing.
>
> --
>
> Knute Johnson
> email s/nospam/knute/



 
Reply With Quote
 
Steve Horsley
Guest
Posts: n/a
 
      06-04-2005
Xavier wrote:
> Hi,
>
> Running java (1.4) under Windows (XP), how can I change the console text
> color for a part of the output text, perhaps something like :
>
> System.out.println("This is [?1] green [?2]");
>
> Where [?1] and [?2] are some (ANSI ?) code to set and unset text color in
> green.
>
> Thanks
>
> Xavier
>
>


The ansi sequences for changing attributes (not all hosts support
these so you are being platform specific) are Escape followed by
'[' followed by a number followed by 'm'. Escape is the character
value 27. This makes the following text come out red for example:
String red = (char) 27 + "[31m";

Attributes can be combined by separating their values with a ';'.
For example, this makes the following text appear in blinking
underlined green:
String bug = "\u0027[5;4;32m";

Attributes I know of are:
0 Normal (clear all)
1 bold
2 dim
4 underline
5 blink
7 reverse
8 blank
9 overstrike
22 normal intensity (cancel bold and blank)
24 underline off
25 blink off
27 reverse off
28 blank off
29 overstrike off
30 black
31 red
32 green
33 yellow
34 blue
35 magenta
36 cyan
37 white
40 black background
41 red background
42 green background
43 yellow background
44 blue background
45 magenta background
46 cyan background
47 white background

Steve

 
Reply With Quote
 
Xavier
Guest
Posts: n/a
 
      06-06-2005
> Unfortunately the console is stream i/o, black and white only.
> If you need more functionality than that, try AWT or Swing.


I don't want GUI, I have a "server" program producing some informations on
the console, and for example, I just want to output in red color when it is
an error.

Xavier


 
Reply With Quote
 
Xavier
Guest
Posts: n/a
 
      06-06-2005
> Not true. I just tried running my program on win xt pro. Just prior to
> the java command, I entered the following command
>
> cmd /T:78
>
> which set the dos window to gray on silver (or similar). Then the
> java program output maintained this color scheme, it did not
> switch to black and white.


Thank you, but I know this command which change all the console. I need to
change only on line, for example for an error information.

Xavier


 
Reply With Quote
 
Xavier
Guest
Posts: n/a
 
      06-06-2005
Hi Steve,

> The ansi sequences for changing attributes (not all hosts support
> these so you are being platform specific) are Escape followed by
> '[' followed by a number followed by 'm'. Escape is the character
> value 27. This makes the following text come out red for example:
> String red = (char) 27 + "[31m";
>
> Attributes can be combined by separating their values with a ';'.
> For example, this makes the following text appear in blinking
> underlined green:
> String bug = "\u0027[5;4;32m";


Thak you for your answer,

I need something like that, but when I try you example (Java 1.4, Windows
XP), the output is :

red : ?[31m
bug : '[5;4;32m

The colors are not changed.

Any idea ?

Xavier


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-06-2005
On Mon, 6 Jun 2005 09:14:24 +0200, Xavier wrote:

(Knute)
>> If you need more functionality than that, try AWT or Swing.

>
> I don't want GUI, I have a "server" program producing some informations on
> the console, ...


Something that has not been *specifically* mentioned yet(?) is that
Java is not a language well suited to interacting with the console.
I suggest you prefix the console errors with..

**** Error - The kablooi has ....

...and be done with it.

If the user is that interested, they can store the output and do a find
on '**** Error - '.

Just a thought.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
Changing console text color Steve M Python 2 10-11-2005 12:30 AM
Change text color for one document.write but not color of all text? kroger@princeton.edu Javascript 7 02-02-2005 01:23 PM
Change text color of "visited link" back to unvisited color ??? Matt Adams HTML 0 08-26-2003 10:27 AM
Re: console mp3->wav decoder for $indows or GUI one which supports console Ben Finney Python 2 06-30-2003 05:43 AM



Advertisments