From d9a3e89f501800c3e7c779b7e9545a5c80134593 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 16 May 2010 23:42:13 +0200 Subject: consolidate ESC sequences function old new delta bell 2 - -2 CMdown 2 - -2 Ceos 4 - -4 Ceol 4 - -4 CMup 4 - -4 SOs 5 - -5 SOn 5 - -5 CMrc 9 - -9 Signed-off-by: Denys Vlasenko --- console-tools/clear.c | 3 ++- console-tools/reset.c | 10 +++++----- editors/vi.c | 16 ++++++++-------- libbb/lineedit.c | 2 +- miscutils/fbsplash.c | 4 ++-- miscutils/less.c | 10 +++++----- procps/top.c | 8 ++++---- procps/watch.c | 3 ++- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/console-tools/clear.c b/console-tools/clear.c index 8b727b39b..b0c6d65d2 100644 --- a/console-tools/clear.c +++ b/console-tools/clear.c @@ -15,5 +15,6 @@ int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { - return printf("\033[H\033[J") != 6; + /* home; clear to the end of screen */ + return printf("\033[H""\033[J") != 6; } diff --git a/console-tools/reset.c b/console-tools/reset.c index 6917eda42..f0ea5cb20 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c @@ -28,11 +28,11 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) { /* See 'man 4 console_codes' for details: - * "ESC c" -- Reset - * "ESC ( K" -- Select user mapping - * "ESC [ J" -- Erase display - * "ESC [ 0 m" -- Reset all display attributes - * "ESC [ ? 25 h" -- Make cursor visible. + * "ESC c" -- Reset + * "ESC ( K" -- Select user mapping + * "ESC [ J" -- Erase to the end of screen + * "ESC [ 0 m" -- Reset all display attributes + * "ESC [ ? 25 h" -- Make cursor visible */ printf("\033c\033(K\033[J\033[0m\033[?25h"); /* http://bugs.busybox.net/view.php?id=1414: diff --git a/editors/vi.c b/editors/vi.c index b8cacb43f..d9124fd76 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -60,18 +60,18 @@ enum { /* vt102 typical ESC sequence */ /* terminal standout start/normal ESC sequence */ -static const char SOs[] ALIGN1 = "\033[7m"; -static const char SOn[] ALIGN1 = "\033[0m"; +#define SOs "\033[7m" +#define SOn "\033[0m" /* terminal bell sequence */ -static const char bell[] ALIGN1 = "\007"; +#define bell "\007" /* Clear-end-of-line and Clear-end-of-screen ESC sequence */ -static const char Ceol[] ALIGN1 = "\033[K"; -static const char Ceos[] ALIGN1 = "\033[J"; +#define Ceol "\033[K" +#define Ceos "\033[J" /* Cursor motion arbitrary destination ESC sequence */ -static const char CMrc[] ALIGN1 = "\033[%d;%dH"; +#define CMrc "\033[%u;%uH" /* Cursor motion up and down ESC sequence */ -static const char CMup[] ALIGN1 = "\033[A"; -static const char CMdown[] ALIGN1 = "\n"; +#define CMup "\033[A" +#define CMdown "\n" #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK // cmds modifying text[] diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 72a1786ff..bc089ab1c 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -466,7 +466,7 @@ static void input_backward(unsigned num) cmdedit_x = w * count_y - num; } /* go to 1st column; go up; go to correct column */ - printf("\r" "\033[%dA" "\033[%dC", count_y, cmdedit_x); + printf("\r" "\033[%uA" "\033[%uC", count_y, cmdedit_x); } static void put_prompt(void) diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 5974006bb..e370d207b 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -359,7 +359,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv) if (fifo_filename && bCursorOff) { // hide cursor (BEFORE any fb ops) - full_write(STDOUT_FILENO, "\x1b" "[?25l", 6); + full_write(STDOUT_FILENO, "\033[?25l", 6); } fb_drawimage(); @@ -404,7 +404,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv) } if (bCursorOff) // restore cursor - full_write(STDOUT_FILENO, "\x1b" "[?25h", 6); + full_write(STDOUT_FILENO, "\033[?25h", 6); return EXIT_SUCCESS; } diff --git a/miscutils/less.c b/miscutils/less.c index e4f8ab979..848266212 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -29,11 +29,11 @@ #endif /* The escape codes for highlighted and normal text */ -#define HIGHLIGHT "\033[7m" -#define NORMAL "\033[0m" -/* The escape code to clear the screen */ -#define CLEAR "\033[H\033[J" -/* The escape code to clear to end of line */ +#define HIGHLIGHT "\033[7m" +#define NORMAL "\033[0m" +/* The escape code to home and clear to the end of screen */ +#define CLEAR "\033[H\033[J" +/* The escape code to clear to the end of line */ #define CLEAR_2_EOL "\033[K" enum { diff --git a/procps/top.c b/procps/top.c index f5c0a123f..e4afafc4c 100644 --- a/procps/top.c +++ b/procps/top.c @@ -478,8 +478,8 @@ static unsigned long display_header(int scr_width, int *lines_rem_p) snprintf(scrbuf, scr_width, "Mem: %luK used, %luK free, %luK shrd, %luK buff, %luK cached", used, mfree, shared, buffers, cached); - /* clear screen & go to top */ - printf(OPT_BATCH_MODE ? "%s\n" : "\e[H\e[J%s\n", scrbuf); + /* go to top & clear to the end of screen */ + printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf); (*lines_rem_p)--; /* Display CPU time split as percentage of total time @@ -518,7 +518,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) #endif /* what info of the processes is shown */ - printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, + printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width, " PID PPID USER STAT VSZ %MEM" IF_FEATURE_TOP_SMP_PROCESS(" CPU") IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU") @@ -772,7 +772,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p) snprintf(linebuf, sizeof(linebuf), "Mem total:%s anon:%s map:%s free:%s", S(total), S(anon), S(map), S(mfree)); - printf(OPT_BATCH_MODE ? "%.*s\n" : "\e[H\e[J%.*s\n", scr_width, linebuf); + printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, linebuf); snprintf(linebuf, sizeof(linebuf), " slab:%s buf:%s cache:%s dirty:%s write:%s", diff --git a/procps/watch.c b/procps/watch.c index 126945c40..a1cde9ea0 100644 --- a/procps/watch.c +++ b/procps/watch.c @@ -52,7 +52,8 @@ int watch_main(int argc UNUSED_PARAM, char **argv) width = (unsigned)-1; // make sure first time new_width != width header = NULL; while (1) { - printf("\033[H\033[J"); + /* home; clear to the end of screen */ + printf("\033[H""\033[J"); if (!(opt & 0x2)) { // no -t const unsigned time_len = sizeof("1234-67-90 23:56:89"); time_t t; -- cgit v1.2.3