| Author |
printing in bold and colors
|
|
| Roy Gourgi 2007-06-21, 10:08 pm |
| Hi,
How would I print out the following in bold and in red.
System.out.printf("Sum of Parts " + "\n");
How would I do it.
TIA
Roy
| |
| Joshua Cranmer 2007-06-21, 10:08 pm |
| On Thu, 21 Jun 2007 11:44:52 -0400, Roy Gourgi wrote:
> Hi,
>
> How would I print out the following in bold and in red.
> System.out.printf("Sum of Parts " + "\n");
>
> How would I do it.
>
> TIA
>
> Roy
Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm,
etc.):
System.out.println("\x1B[1mBOLD\x1B[0m\t\x1B[31mRED\x1B[0m");
will print BOLD in bold and RED in red. For more information about
controlling terminal output, see http://en.wikipedia.org/wiki/
ANSI_escape_code.
| |
| Roy Gourgi 2007-06-21, 10:08 pm |
| Thanks Joshua,
There is no easier way than that?
It looks pretty cluttered. :)
I am using JBuilder
Roy
"Roy Gourgi" <royng@videotron.ca> wrote in message
news:02xei.88$we4.8410@wagner.videotron.net...
> Hi,
>
> How would I print out the following in bold and in red.
> System.out.printf("Sum of Parts " + "\n");
>
> How would I do it.
>
> TIA
>
> Roy
>
>
| |
|
|
|
| Roy Gourgi wrote:
> There is no easier way than that?
> It looks pretty cluttered.
Such is the nature of ANSI escape sequences. You think that's cluttered?
Take a look at printer control streams sometime.
Bear in mind that by hard-coding ANSI escape sequences you are limiting your
program to run on consoles that support those escape sewquences, which cuts
you down to what I would guess to be 90% or more of the consoles you'd
encounter. Regardless of the actual proportion it's less than 100%, so you'll
be sacrificing the "Write Once, Run Anywhere" philosophy of Java. That might
be acceptable if you know you can assure ANSI compatibility on all targeted
consoles.
If you can think up an easier way let us know. Just remember that these
escape sequences are defined externally to Java; they're data, not code.
--
Lew
| |
| Roy Gourgi 2007-06-21, 10:08 pm |
| Hi Joshua,
I get the error message that x1B is an illegal escape character?
How can I fix that?
Roy
"Joshua Cranmer" <Pidgeot18@verizon.net> wrote in message
news:ccxei.2959$AR5.330@trnddc06...
> On Thu, 21 Jun 2007 11:44:52 -0400, Roy Gourgi wrote:
>
>
> Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm,
> etc.):
>
> System.out.println("\x1B[1mBOLD\x1B[0m\t\x1B[31mRED\x1B[0m");
>
> will print BOLD in bold and RED in red. For more information about
> controlling terminal output, see http://en.wikipedia.org/wiki/
> ANSI_escape_code.
| |
| Thomas Fritsch 2007-06-21, 10:08 pm |
| Roy Gourgi wrote:
[reordered top-down]
> "Joshua Cranmer" <Pidgeot18@verizon.net> wrote in message
> news:ccxei.2959$AR5.330@trnddc06...
> Hi Joshua,
>
> I get the error message that x1B is an illegal escape character?
>
> How can I fix that?
>
> Roy
Write \u001B instead \x1B
--
Thomas
| |
| Roy Gourgi 2007-06-21, 10:08 pm |
| Hi Thomas,
That did not work either.
Here is what I entered:
System.out.println(" \u001B[1mBOLD\u001B[0m\t\u001B[31mRED\u0
01B[0m");
And here is the output that I got
[1mBOLD[0m [31mRED[0m
Roy
"Thomas Fritsch" <i.dont.like.spam@invalid.com> wrote in message
news:newscache$vnwzjj$8w6$1@news.ops.de...
> Roy Gourgi wrote:
> [reordered top-down]
> Write \u001B instead \x1B
>
> --
> Thomas
| |
|
| Roy Gourgi wrote:
> That did not work either.
>
> Here is what I entered:
>
> System.out.println(" \u001B[1mBOLD\u001B[0m\t\u001B[31mRED\u0
01B[0m");
>
> And here is the output that I got
> [1mBOLD[0m [31mRED[0m
Please do not top post.
Does your console use ANSI escape sequences?
--
Lew
| |
| Roy Gourgi 2007-06-21, 10:08 pm |
| I do not know, I am using JBuilder.
How can I find out?
Roy
"Roy Gourgi" <royng@videotron.ca> wrote in message
news:02xei.88$we4.8410@wagner.videotron.net...
> Hi,
>
> How would I print out the following in bold and in red.
> System.out.printf("Sum of Parts " + "\n");
>
> How would I do it.
>
> TIA
>
> Roy
>
>
| |
|
|
|
|
| Real Gagnon 2007-06-23, 4:19 am |
| Lew <lew@lewscanon.nospam> wrote in
news:__GdnaMWN9QvoubbnZ2dnUVZ_oLinZ2d@co
mcast.com:
> Real Gagnon wrote:
>
> Huh. Works fine on my Linux console. Works fine in my Cygwin console
> in Win XP also.
My comments were for regular CMD.EXE or COMMAND.COM DOS shell.
Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
| |
| Roedy Green 2007-06-23, 4:19 am |
| On Thu, 21 Jun 2007 11:44:52 -0400, "Roy Gourgi" <royng@videotron.ca>
wrote, quoted or indirectly quoted someone who said :
>How would I print out the following in bold and in red.
>System.out.printf("Sum of Parts " + "\n");
You can't do it with System.out. You write the code that would
display it on screen, then feed it to a printer rendering engine. See
http://mindprod.com/jgloss/printing.html
Another way is to generate HTML, then feed it too a browser to print.
another way is to generate some sort of metafile then feed it to a C++
utility to print.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
| |
|
| Real Gagnon wrote:
> Lew <lew@lewscanon.nospam> wrote in
> news:__GdnaMWN9QvoubbnZ2dnUVZ_oLinZ2d@co
mcast.com:
>
>
> My comments were for regular CMD.EXE or COMMAND.COM DOS shell.
The person who suggested ANSI control codes in the first place was careful to
exclude those.
Joshua Cranmer said:
> Assuming you are outputting to an ANSI-compliant terminal (e.g., xterm,
> etc.):
So that point was already covered. Plus, I asked,
> Does your console use ANSI escape sequences?
Interestingly there was no answer to that question. I also pointed out
> Bear in mind that by hard-coding ANSI escape sequences you are limiting your program to run on consoles that support those escape sewquences,
It is helpful to the OP to know that the command shells you mentioned do not
fit into the target space for the advice. The issue that the suggestion is
not portable was well covered, however.
--
Lew
| |
| Roedy Green 2007-06-23, 7:10 pm |
| On Fri, 22 Jun 2007 06:05:04 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :
>
>You can't do it with System.out. You write the code that would
>display it on screen, then feed it to a printer rendering engine. See
>http://mindprod.com/jgloss/printing.html
>
>Another way is to generate HTML, then feed it too a browser to print.
>
>another way is to generate some sort of metafile then feed it to a C++
>utility to print.
Another way is to generate PostScript and then feed that to a PS
printer or software PS rendering engine.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
|
|
|