From bfd50c7071d54a0d31a260807ee2c4e5ca339f1a Mon Sep 17 00:00:00 2001 From: Jon Foster Date: Wed, 29 Sep 2021 22:41:38 -0700 Subject: [PATCH] ANSI and TTY handling improvements This fixes an issue with colors in the COLOR command on ANSI terminals. The first 8 color codes are in one range of numbers and the second are in a second range. bwx_COLOR expected all 16 colors to be contiguous. Also the code was cleaned up to use escapes where appropriate and to use better primitive functions where available. --- bwx_tty.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bwx_tty.c b/bwx_tty.c index 08607ab..b550cda 100644 --- a/bwx_tty.c +++ b/bwx_tty.c @@ -64,10 +64,10 @@ bwx_LOCATE (int Row, int Col) case C_OPTION_TERMINAL_NONE: break; case C_OPTION_TERMINAL_ADM: - fprintf (My->SYSOUT->cfp, "%c=%c%c", 27, Row + 32, Col + 32); + fprintf (My->SYSOUT->cfp, "\e=%c%c", Row + 32, Col + 32); break; case C_OPTION_TERMINAL_ANSI: - fprintf (My->SYSOUT->cfp, "%c[%d;%dH", 27, Row, Col); + fprintf (My->SYSOUT->cfp, "\e[%d;%dH", Row, Col); break; default: WARN_ADVANCED_FEATURE; @@ -90,10 +90,10 @@ bwx_CLS (void) case C_OPTION_TERMINAL_NONE: break; case C_OPTION_TERMINAL_ADM: - fprintf (My->SYSOUT->cfp, "%c", 26); + fputc(26, My->SYSOUT->cfp); break; case C_OPTION_TERMINAL_ANSI: - fprintf (My->SYSOUT->cfp, "%c[2J", 27); + fputs("\e[2J", My->SYSOUT->cfp); break; default: WARN_ADVANCED_FEATURE; @@ -123,7 +123,10 @@ bwx_COLOR (int Fore, int Back) case C_OPTION_TERMINAL_ADM: break; case C_OPTION_TERMINAL_ANSI: - fprintf (My->SYSOUT->cfp, "%c[%d;%dm", 27, 30 + Fore, 40 + Back); + fprintf (My->SYSOUT->cfp, "\e[%d;%dm", + Fore+(Fore>7 ? 82 : 30), + Back+(Back>7 ? 92 : 40) + ); break; default: WARN_ADVANCED_FEATURE;