console-applicationrebolred-lang

Colored text console output in Rebol


In some languages I can put Esc codes around text to make them colored on Linux console/terminal. However, this does not seem to work in Rebol:

NORMAL: "\e[0m"
RED: "\e[0;31m"

print rejoin["\e[0;31m" "red text" "\e[0m"]

Above code only produces black (usual colored) text output:

\e[0;31mred text\e[0m

Can colored text output be printed with Rebol on Linux terminal?


Solution

  • You can similarly use colour codes in Rebol/Red.

    print "This text is ^[[0;31mred^[[0m text."
    

    #"^[" is the Escape character in Rebol/Red.

    You can, for example, change the prompts in Red with the following codes:

    system/console/prompt: "^[[31m^[[5D>>^[(B^[[m "
    system/console/result: "^[[32m^[[5D==^[(B^[[m"
    

    In the Ren-C branch of Rebol 3 you can change the prompts with the following (similar) codes:

    system/console/prompt: "^[[31m^[[5D>>^[(B^[[m "
    system/console/result: "^[[32m^[[5D==^[(B^[[m "