Home | OS/2 Software | Rexx | Using ANSI escape sequences to control text colors (intermediate level)

Using ANSI escape sequences to control text colors (intermediate level)

Contributed by: Doug Rickman, Global Hydrology and Climate Center, MSFC, NASA

This is aimed at intermediate REXX users.


 


/* Screen control using ANSI escape sequences.                               */
rc=lineout(,'1b'x||'[31;1m'||'This writes a bright red text')
rc=lineout(,'1b'x||'[0m'||'and resets the text to default')

rc=charout(,'1b'x||'[31;1m')
say 'This writes just this line in bright red and then restores the default'
rc=charout(,'1b'x||'[0m')

/* This writes the word "usage:' in yellow and the text " Program name ...   */
/* in normal video, all on one line.                                         */
rc= charout(,'1b'x||'[33;1m'||'usage:'||'1b'x||'[0m')
say ' Program name, arg1 arg2 ....'


/* the '1b'x is "escape", "[" starts an sequence, "31" means red,  ";" means */
/* more sequences follow, "1" bold, "m" means this is all a color operation. */
/* 0 all off(B&W), 1 bold, 2 normal, 4 underline, 5 blink, 7 reverse video   */
/* foreground 30-black 31-red 32-green 33-yellow 34-blue 35-magenta 36-cyan  */
/*            37-white                                                       */
/* background 40-black 41-red 42-green 43-yellow 44-blue 45-magenta 46-cyan  */
/*            47-white