1. Displaying colored text on console
- Posted by rneu Jun 26, 2017
- 2344 views
In a console application, I need to display following text:
display("This is important notice.")
The word 'important' needs to be in red color. How can I achieve this?
I tried to check in manual and it seems I can do this only using graphics screen and not on regular terminal. Thanks for your help.
2. Re: Displaying colored text on console
- Posted by petelomax Jun 26, 2017
- 2344 views
Try this:
include std/graphics.e puts(1,"This is an ") text_color(BRIGHT_RED) puts(1,"important") text_color(WHITE) puts(1," notice.")
Pete
3. Re: Displaying colored text on console
- Posted by rneu Jun 26, 2017
- 2329 views
Try this:
include std/graphics.e puts(1,"This is an ") text_color(BRIGHT_RED) puts(1,"important") text_color(WHITE) puts(1," notice.")
Pete
The word 'important' came out in red but then there was error:
/usr/share/euphoria/include/std/graphics.e:97 in procedure text_color() type_check failure, c is {27,91,48,59,51,55,109}
The terminal color has become red and is not becoming black even on trying:
text_color(BLACK)
4. Re: Displaying colored text on console
- Posted by petelomax Jun 27, 2017
- 2328 views
The word 'important' came out in red but then there was error:
/usr/share/euphoria/include/std/graphics.e:97 in procedure text_color() type_check failure, c is {27,91,48,59,51,55,109}
The terminal color has become red and is not becoming black even on trying:
text_color(BLACK)
Not sure I can help.
On my system, WHITE is defined as the constant 7 in std\graphcst.e, but that value of {27,91,48,59,51,55,109} is the ansi sequence for white, "\e[0;37m".
Perhaps you could try text_color(7), and maybe text_color(0) instead of text_color(WHITE) and text_color(BLACK), see what that does.
Also the output of ?{WHITE,BLACK} may help someone else figure out what is wrong, maybe text_color() is broken on linux.
Someone else will have to explain where that value for WHITE is coming from.
Pete
5. Re: Displaying colored text on console
- Posted by CraigWelch Apr 18, 2020
- 1706 views
I had a similar problem, could not reset background to white.
Fixed by specifying BRIGHT_WHITE.
6. Re: Displaying colored text on console
- Posted by Lnettnay Apr 18, 2020
- 1750 views
Hi Craig,
It's admirable that you're trying to help someone with a problem that they had but how did you come to reply to a message from almost 3 years ago?
Are you that bored?
BTW, it works now (at least on Windows 8.1)
Lonny
7. Re: Displaying colored text on console
- Posted by CraigWelch Apr 19, 2020
- 1698 views
Hi Lonny,
No, I don't do boredom.
I was searching the site to find out how to change the colour on terminal text. I found out, and in the process saw this thread. When I found a problem figured out a work-around, it seemed like the natural thing to do to comment in the thread.
BTW, my platform is Mac OS X.
8. Re: Displaying colored text on console
- Posted by Senator May 28, 2020
- 1585 views
include std/console.e include std/graphics.e public procedure high_light(sequence text, sequence word, color restore_color = WHITE, -- the current foreground text_color color hilite = RED) integer i sequence rc = get_position() -- pos = {r,c} -- row, column text_color(restore_color) display("[]", {text}) -- text displayed in i = match(word,text) -- obtain column index of "word" to highlight position(rc[1],i) -- position @ word text_color(hilite) -- change to hicolor display("[]",{word}) -- overwrite word in hicolor text_color(restore_color) -- set text_color to restore_color end procedure -- test sequence text = "This is a test of the highlight() procedure!" high_light(text, "test") -- "test" displayed in RED high_light(text, "highlight_word()",WHITE,YELLOW) -- "highlight_word" displayed in YELLOW display("\n[]",{text}) -- text displayed in WHITE any_key("\n")
Is there any command to capture the current text_color, so
I wouldn't have to explicitly pass a restore color to the procedure?
Regards,
Ken