consolidate ESC sequences
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 May 2010 21:42:13 +0000 (23:42 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 May 2010 21:42:13 +0000 (23:42 +0200)
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 <vda.linux@googlemail.com>
console-tools/clear.c
console-tools/reset.c
editors/vi.c
libbb/lineedit.c
miscutils/fbsplash.c
miscutils/less.c
procps/top.c
procps/watch.c

index 8b727b39b681560cfc3302beb885744a70275bc0..b0c6d65d2a028153134d813bf2c4c1be50f39245 100644 (file)
@@ -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;
 }
index 6917eda426c4baac59d5adab8f4e3c5eb3336fe2..f0ea5cb20f2f4b362cbb6f31943e218718863ff6 100644 (file)
@@ -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:
index b8cacb43ff7fbe8db0b1611d0dbd70dbd7d710db..d9124fd7657abb019dee8945b7f027c5d398b56c 100644 (file)
@@ -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[]
index 72a1786ff20a0072a0f74e9f2a55ad900c2cfc81..bc089ab1cf5861da94123a2a304e6e87220839bf 100644 (file)
@@ -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)
index 5974006bb8fdf0b44690bcbba6002d9ffe25e429..e370d207bc13b61a8e9420b32eb0e2a696c6435b 100644 (file)
@@ -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;
 }
index e4f8ab979099ce83c15f1af693692c1c79926875..8482662120fc20ca504b9c88b8fa962758e58a18 100644 (file)
 #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 {
index f5c0a123ff074c38ec0623e53f9874d36a0e9505..e4afafc4cf639b25ed76dfdd4cc9a960e2ad5c61 100644 (file)
@@ -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",
index 126945c40b243cdee7db2238d71222c6407def67..a1cde9ea09efb90e85a6307aa96185406dcf7109 100644 (file)
@@ -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;