From c3f3f842c55429353cf1ce490b8d635380ef9326 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 3 Jan 2022 22:21:30 -0600 Subject: [PATCH] Replace \033 with \e in strings. --- lib/lib.c | 4 ++-- lib/tty.c | 2 +- toys/example/demo_scankey.c | 2 +- toys/lsb/dmesg.c | 2 +- toys/other/clear.c | 2 +- toys/other/reset.c | 5 ++++- toys/pending/diff.c | 12 ++++++------ toys/pending/vi.c | 4 ++-- toys/posix/grep.c | 10 +++++----- toys/posix/ls.c | 10 +++++----- toys/posix/ps.c | 12 ++++++------ 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/lib/lib.c b/lib/lib.c index b219a5d5..84af3f48 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -457,7 +457,7 @@ char *chomp(char *s) int unescape(char c) { - char *from = "\\abefnrtv", *to = "\\\a\b\033\f\n\r\t\v"; + char *from = "\\abefnrtv", *to = "\\\a\b\e\f\n\r\t\v"; int idx = stridx(from, c); return (idx == -1) ? 0 : to[idx]; @@ -483,7 +483,7 @@ int unescape2(char **c, int echo) if (-1 == (idx = stridx("\\abeEfnrtv'\"?0", **c))) return '\\'; ++*c; - return "\\\a\b\033\033\f\n\r\t\v'\"?"[idx]; + return "\\\a\b\e\e\f\n\r\t\v'\"?"[idx]; } // If string ends with suffix return pointer to start of suffix in string, diff --git a/lib/tty.c b/lib/tty.c index 77ddf671..b4aee45e 100644 --- a/lib/tty.c +++ b/lib/tty.c @@ -279,5 +279,5 @@ void start_redraw(unsigned *width, unsigned *height) toys.signal = -1; terminal_probesize(width, height); } - xprintf("\033[H\033[J"); + xputsn("\e[H\e[J"); } diff --git a/toys/example/demo_scankey.c b/toys/example/demo_scankey.c index 1b6326d2..05ffc414 100644 --- a/toys/example/demo_scankey.c +++ b/toys/example/demo_scankey.c @@ -49,7 +49,7 @@ void demo_scankey_main(void) printf("%c", key); printf("] "); } else printf("key=%d ", key); - printf("x=%d y=%d width=%d height=%d\033[K", x, y, width, height); + printf("x=%d y=%d width=%d height=%d\e[K", x, y, width, height); fflush(0); if (key == -2) continue; diff --git a/toys/lsb/dmesg.c b/toys/lsb/dmesg.c index 8736a8e5..384d6fcd 100644 --- a/toys/lsb/dmesg.c +++ b/toys/lsb/dmesg.c @@ -42,7 +42,7 @@ GLOBALS( static void color(int c) { - if (TT.use_color) printf("\033[%dm", c); + if (TT.use_color) printf("\e[%dm", c); } static void format_message(char *msg, int new) diff --git a/toys/other/clear.c b/toys/other/clear.c index 842579f8..400fe7b3 100644 --- a/toys/other/clear.c +++ b/toys/other/clear.c @@ -15,5 +15,5 @@ config CLEAR void clear_main(void) { - printf("\033[2J\033[H"); + printf("\e[2J\e[H"); } diff --git a/toys/other/reset.c b/toys/other/reset.c index 4d16a4a3..8723760d 100644 --- a/toys/other/reset.c +++ b/toys/other/reset.c @@ -3,6 +3,9 @@ * Copyright 2015 Rob Landley * * No standard. + * + * In 1979 3BSD's tset had a sleep(1) to let mechanical printer-and-ink + * terminals "settle down". We're not doing that. USE_RESET(NEWTOY(reset, 0, TOYFLAG_USR|TOYFLAG_BIN)) @@ -22,5 +25,5 @@ void reset_main(void) // man 4 console_codes: reset terminal is ESC (no left bracket) c // DEC private mode set enable wraparound sequence. - xwrite(fd<0 ? 1 : fd, "\033c\033[?7h", 2); + xwrite(fd<0 ? 1 : fd, "\ec\e[?7h", 2); } diff --git a/toys/pending/diff.c b/toys/pending/diff.c index e93c622c..4dd01653 100644 --- a/toys/pending/diff.c +++ b/toys/pending/diff.c @@ -427,8 +427,8 @@ static void print_diff(int a, int b, char c, int *off_set, FILE *fp) char *reset = NULL; if (c != ' ' && (toys.optflags & FLAG_color)) { - printf("\033[%dm", c == '+' ? 32 : 31); - reset = "\033[0m"; + printf("\e[%dm", c == '+' ? 32 : 31); + reset = "\e[0m"; } for (i = a; i <= b; i++) { @@ -639,7 +639,7 @@ static void do_diff(char **files) TT.status = change; //update status, may change bcoz of -w etc. if (!(toys.optflags & FLAG_q) && change) { //start of !FLAG_q - if (toys.optflags & FLAG_color) printf("\033[1m"); + if (toys.optflags & FLAG_color) printf("\e[1m"); if (toys.optflags & FLAG_L) printf("--- %s\n", llist->arg); else show_label("---", files[0], &(TT).st[0]); if (((toys.optflags & FLAG_L) && !llist->next) || !(toys.optflags & FLAG_L)) @@ -648,7 +648,7 @@ static void do_diff(char **files) while (llist->next) llist = llist->next; printf("+++ %s\n", llist->arg); } - if (toys.optflags & FLAG_color) printf("\033[0m"); + if (toys.optflags & FLAG_color) printf("\e[0m"); struct diff *t, *ptr1 = d, *ptr2 = d; while (i) { @@ -683,7 +683,7 @@ calc_ct: start2 = MAX(1, ptr1->c - (ptr1->a - ptr1->suff)); end2 = ptr2->prev - ptr2->b + ptr2->d; - if (toys.optflags & FLAG_color) printf("\033[36m"); + if (toys.optflags & FLAG_color) printf("\e[36m"); printf("@@ -%ld", start1 ? ptr1->suff: (ptr1->suff -1)); if (end1 != -1) printf(",%ld ", ptr2->prev-ptr1->suff + 1); else putchar(' '); @@ -692,7 +692,7 @@ calc_ct: if ((end2 - start2 +1) != 1) printf(",%ld ", (end2 - start2 +1)); else putchar(' '); printf("@@"); - if (toys.optflags & FLAG_color) printf("\033[0m"); + if (toys.optflags & FLAG_color) printf("\e[0m"); putchar('\n'); for (t = ptr1; t <= ptr2; t++) { diff --git a/toys/pending/vi.c b/toys/pending/vi.c index b11dd642..44ade442 100644 --- a/toys/pending/vi.c +++ b/toys/pending/vi.c @@ -1460,7 +1460,7 @@ static void draw_page() aw = crunch_nstr(&line, clip, bytes, 0, "\t\n", vi_crunch); crunch_str(&line, TT.screen_width-1, stdout, "\t\n", vi_crunch); if ( *line ) printf("@"); - } else printf("\033[2m~\033[m"); + } else printf("\e[2m~\e[m"); } if (SSOL+bytes < TT.filesize) { line = toybuf; @@ -1473,7 +1473,7 @@ static void draw_page() // Finished updating visual area, show status line. printf("\e[%uH\e[2K", TT.screen_height+1); - if (TT.vi_mode == 2) printf("\033[1m-- INSERT --\033[m"); + if (TT.vi_mode == 2) printf("\e[1m-- INSERT --\e[m"); if (!TT.vi_mode) { cx_scr = printf("%s", TT.il->data); cy_scr = TT.screen_height; diff --git a/toys/posix/grep.c b/toys/posix/grep.c index 6d23543d..0474f7db 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -461,11 +461,11 @@ void grep_main(void) toys.optflags &= ~FLAG_color; if (FLAG(color)) { - TT.purple = "\033[35m"; - TT.cyan = "\033[36m"; - TT.red = "\033[1;31m"; - TT.green = "\033[32m"; - TT.grey = "\033[m"; + TT.purple = "\e[35m"; + TT.cyan = "\e[36m"; + TT.red = "\e[1;31m"; + TT.green = "\e[32m"; + TT.grey = "\e[m"; } else TT.purple = TT.cyan = TT.red = TT.green = TT.grey = ""; if (FLAG(R)) toys.optflags |= FLAG_r; diff --git a/toys/posix/ls.c b/toys/posix/ls.c index d9cd90bd..15511059 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -84,7 +84,7 @@ static int crunch_qb(FILE *out, int cols, int wc) for (i = 0; ist_mode); - if (color) printf("\033[%d;%dm", color>>8, color&255); + if (color) printf("\e[%d;%dm", color>>8, color&255); } ss = dt->name; crunch_str(&ss, INT_MAX, stdout, TT.escmore, crunch_qb); - if (color) printf("\033[0m"); + if (color) printf("\e[0m"); if ((FLAG(l)||FLAG(o)||FLAG(n)||FLAG(g)) && S_ISLNK(mode)) { printf(" -> "); @@ -472,11 +472,11 @@ static void listfiles(int dirfd, struct dirtree *indir) if (fstatat(dirfd, dt->symlink, &st2, 0)) color = 256+31; else color = color_from_mode(st2.st_mode); - if (color) printf("\033[%d;%dm", color>>8, color&255); + if (color) printf("\e[%d;%dm", color>>8, color&255); } zprint(zap, "s", 0, (unsigned long)dt->symlink); - if (!zap && color) printf("\033[0m"); + if (!zap && color) printf("\e[0m"); } if (et) xputc(et); diff --git a/toys/posix/ps.c b/toys/posix/ps.c index b8b2ef3c..35bfbf45 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1458,8 +1458,8 @@ static int header_line(int line, int rev) if (FLAG(b)) puts(toybuf); else { - printf("%s%-*.*s%s\r\n", rev?"\033[7m":"", rev?TT.width:0, TT.width, toybuf, - rev?"\033[0m":""); + printf("%s%-*.*s%s\r\n", rev?"\e[7m":"", rev?TT.width:0, TT.width, toybuf, + rev?"\e[0m":""); } return line-1; @@ -1566,7 +1566,7 @@ static void top_common( if (recalc) { qsort(mix.tb, mix.count, sizeof(struct procpid *), (void *)ksort); if (!FLAG(b)) { - printf("\033[H\033[J"); + printf("\e[H\e[J"); if (toys.signal) { toys.signal = 0; terminal_probesize(&TT.width, &TT.height); @@ -1673,7 +1673,7 @@ static void top_common( lines = header_line(lines, 1); } if (!recalc && !FLAG(b)) - printf("\033[%dH\033[J", 1+TT.height-lines); + printf("\e[%dH\e[J", 1+TT.height-lines); recalc = 1; for (i = 0; istate == 'R'; if (!FLAG(b) && i) putchar('\n'); - if (bold) printf("\033[1m"); + if (bold) printf("\e[1m"); show_ps(mix.tb[i+topoff]); - if (bold) printf("\033[m"); + if (bold) printf("\e[m"); } if (TT.top.n && !--TT.top.n) { -- 2.39.2