Re: Displaying colored text on console
- Posted by Senator May 28, 2020
- 1340 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