diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2024-04-27 07:38:55 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2024-04-27 07:38:55 +0000 |
| commit | a3debf7741d20826bdc6ab786f4ccf0ef7358619 (patch) | |
| tree | a138d1cb23448290ddd8a8110e54eb017bc63b1b /utils | |
| parent | dcs: XTGETTCAP: handle empty request (diff) | |
dcs: xtgettcap: always reply with tigetstr(3) formatted "strings"
That is, instead of sometimes replying with a "source" encoded
string (where e.g. '\E' are returned just like that, and not as an
actual ESC), always unescape all string values.
This also includes \n \r \t \b \f \s, \^ \\ \ \:, as well as ^x-styled
escapes.
Closes #1701
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/xtgettcap.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/utils/xtgettcap.c b/utils/xtgettcap.c index b3ab712a..069a9ecb 100644 --- a/utils/xtgettcap.c +++ b/utils/xtgettcap.c @@ -103,7 +103,7 @@ main(int argc, const char *const *argv) if (isprint(buf[i])) printf("%c", buf[i]); else if (buf[i] == '\033') - printf("\033[1;31m\\E\033[m"); + printf("\033[1;31m<ESC>\033[m"); else printf("%02x", (uint8_t)buf[i]); } @@ -158,12 +158,30 @@ main(int argc, const char *const *argv) printf(" \033[%dm", color); for (size_t i = 0 ; i < len; i++) { - if (isprint(decoded[i])) + if (isprint(decoded[i])) { + /* All printable characters */ printf("%c", decoded[i]); - else if (decoded[i] == '\033') - printf("\033[1;31m\\E\033[22;%dm", color); - else + } + + else if (decoded[i] == '\033') { + /* ESC */ + printf("\033[1;31m<ESC>\033[22;%dm", color); + } + + else if (decoded[i] >= '\x00' && decoded[i] <= '\x5f') { + /* Control characters, e.g. ^G etc */ + printf("\033[1m^%c\033[22m", decoded[i] + '@'); + } + + else if (decoded[i] == '\x7f') { + /* Control character ^? */ + printf("\033[1m^?\033[22m"); + } + + else { + /* Unknown: print hex representation */ printf("\033[1m%02x\033[22m", (uint8_t)decoded[i]); + } } printf("\033[m\r\n"); replies++; |
