*: use ESC define instead of "\033"; use ESC[m instead of ESC[0m
text data bss dec hex filename
922535 481 6832 929848 e3038 busybox_old
922534 481 6832 929847 e3037 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/console-tools/clear.c b/console-tools/clear.c
index 3cc1625..09ef1ea 100644
--- a/console-tools/clear.c
+++ b/console-tools/clear.c
@@ -23,9 +23,11 @@
#include "libbb.h"
+#define ESC "\033"
+
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
/* home; clear to the end of screen */
- return full_write1_str("\033[H""\033[J") != 6;
+ return full_write1_str(ESC"[H" ESC"[J") != 6;
}
diff --git a/console-tools/reset.c b/console-tools/reset.c
index f2b900d..471ef91 100644
--- a/console-tools/reset.c
+++ b/console-tools/reset.c
@@ -46,11 +46,11 @@
/* See 'man 4 console_codes' for details:
* "ESC c" -- Reset
* "ESC ( B" -- Select G0 Character Set (B = US)
- * "ESC [ 0 m" -- Reset all display attributes
+ * "ESC [ m" -- Reset all display attributes
* "ESC [ J" -- Erase to the end of screen
* "ESC [ ? 25 h" -- Make cursor visible
*/
- printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h");
+ printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h");
/* http://bugs.busybox.net/view.php?id=1414:
* people want it to reset echo etc: */
#if ENABLE_STTY
diff --git a/coreutils/ls.c b/coreutils/ls.c
index af5e6cb..a4e324b 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -347,6 +347,8 @@
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
} while (0)
+#define ESC "\033"
+
/*** Output code ***/
@@ -586,12 +588,12 @@
if (!mode)
if (lstat(dn->fullname, &statbuf) == 0)
mode = statbuf.st_mode;
- printf("\033[%u;%um", bold(mode), fgcolor(mode));
+ printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
}
#endif
column += print_name(dn->name);
if (G_show_color) {
- printf("\033[0m");
+ printf(ESC"[m");
}
if (lpath) {
@@ -609,7 +611,7 @@
# endif
# if ENABLE_FEATURE_LS_COLOR
if (G_show_color) {
- printf("\033[%u;%um", bold(mode), fgcolor(mode));
+ printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
}
# endif
}
@@ -617,7 +619,7 @@
column += print_name(lpath) + 4;
free(lpath);
if (G_show_color) {
- printf("\033[0m");
+ printf(ESC"[m");
}
}
#if ENABLE_FEATURE_LS_FILETYPES
diff --git a/editors/vi.c b/editors/vi.c
index 116022c..c010f79 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -224,24 +224,25 @@
* See "Xterm Control Sequences"
* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
*/
+#define ESC "\033"
/* Inverse/Normal text */
-#define ESC_BOLD_TEXT "\033[7m"
-#define ESC_NORM_TEXT "\033[0m"
+#define ESC_BOLD_TEXT ESC"[7m"
+#define ESC_NORM_TEXT ESC"[m"
/* Bell */
#define ESC_BELL "\007"
/* Clear-to-end-of-line */
-#define ESC_CLEAR2EOL "\033[K"
+#define ESC_CLEAR2EOL ESC"[K"
/* Clear-to-end-of-screen.
* (We use default param here.
* Full sequence is "ESC [ <num> J",
* <num> is 0/1/2 = "erase below/above/all".)
*/
-#define ESC_CLEAR2EOS "\033[J"
+#define ESC_CLEAR2EOS ESC"[J"
/* Cursor to given coordinate (1,1: top left) */
-#define ESC_SET_CURSOR_POS "\033[%u;%uH"
+#define ESC_SET_CURSOR_POS ESC"[%u;%uH"
//UNUSED
///* Cursor up and down */
-//#define ESC_CURSOR_UP "\033[A"
+//#define ESC_CURSOR_UP ESC"[A"
//#define ESC_CURSOR_DOWN "\n"
#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
@@ -696,14 +697,14 @@
save_argc = argc;
optind = 0;
// "Save cursor, use alternate screen buffer, clear screen"
- write1("\033[?1049h");
+ write1(ESC"[?1049h");
while (1) {
edit_file(argv[optind]); /* param might be NULL */
if (++optind >= argc)
break;
}
// "Use normal screen buffer, restore cursor"
- write1("\033[?1049l");
+ write1(ESC"[?1049l");
//-----------------------------------------------------------
return 0;
@@ -772,7 +773,7 @@
#if ENABLE_FEATURE_VI_ASK_TERMINAL
if (G.get_rowcol_error /* TODO? && no input on stdin */) {
uint64_t k;
- write1("\033[999;999H" "\033[6n");
+ write1(ESC"[999;999H" ESC"[6n");
fflush_all();
k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100);
if ((int32_t)k == KEYCODE_CURSOR_POS) {
@@ -4454,7 +4455,7 @@
sleeptime = 0; // how fast to type
}
}
- strcat(readbuffer, "\033");
+ strcat(readbuffer, ESC);
}
readbuffer[0] = strlen(readbuffer + 1);
cd1:
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 0106093..17766a1 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -2868,7 +2868,7 @@
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
"\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:"
"\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] "
- "\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]";
+ "\\!\\[\\e[36;1m\\]\\$ \\[\\E[m\\]";
#else
"% ";
#endif
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 9ac91e0..5b2e5ac 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -65,6 +65,8 @@
/* If you want logging messages on /tmp/fbsplash.log... */
#define DEBUG 0
+#define ESC "\033"
+
struct globals {
#if DEBUG
bool bdebug_messages; // enable/disable logging
@@ -514,7 +516,7 @@
if (fifo_filename && bCursorOff) {
// hide cursor (BEFORE any fb ops)
- full_write(STDOUT_FILENO, "\033[?25l", 6);
+ full_write(STDOUT_FILENO, ESC"[?25l", 6);
}
fb_drawimage();
@@ -559,7 +561,7 @@
}
if (bCursorOff) // restore cursor
- full_write(STDOUT_FILENO, "\033[?25h", 6);
+ full_write(STDOUT_FILENO, ESC"[?25h", 6);
return EXIT_SUCCESS;
}
diff --git a/miscutils/less.c b/miscutils/less.c
index f37c80a..241f7f8 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -137,7 +137,7 @@
#define ESC "\033"
/* The escape codes for highlighted and normal text */
#define HIGHLIGHT ESC"[7m"
-#define NORMAL ESC"[0m"
+#define NORMAL ESC"[m"
/* The escape code to home and clear to the end of screen */
#define CLEAR ESC"[H"ESC"[J"
/* The escape code to clear to the end of line */
@@ -1042,7 +1042,7 @@
open_file_and_read_lines();
#if ENABLE_FEATURE_LESS_ASK_TERMINAL
if (G.winsize_err)
- printf("\033[999;999H" "\033[6n");
+ printf(ESC"[999;999H" ESC"[6n");
#endif
buffer_fill_and_print();
}
diff --git a/procps/powertop.c b/procps/powertop.c
index 5d522bf..2872035 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -51,6 +51,8 @@
/* Max filename length of entry in /sys/devices subsystem */
#define BIG_SYSNAME_LEN 16
+#define ESC "\033"
+
typedef unsigned long long ullong;
struct line {
@@ -776,8 +778,8 @@
}
}
- /* Clear the screen */
- printf("\033[H\033[J");
+ /* Home; clear screen */
+ printf(ESC"[H" ESC"[J");
/* Clear C-state lines */
memset(&cstate_lines, 0, sizeof(cstate_lines));
diff --git a/procps/top.c b/procps/top.c
index f97ded5..b777c49 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -117,6 +117,7 @@
#include "libbb.h"
+#define ESC "\033"
typedef struct top_status_t {
unsigned long vsz;
@@ -580,7 +581,7 @@
meminfo[MI_BUFFERS],
meminfo[MI_CACHED]);
/* Go to top & clear to the end of screen */
- printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf);
+ printf(OPT_BATCH_MODE ? "%s\n" : ESC"[H" ESC"[J" "%s\n", scrbuf);
(*lines_rem_p)--;
/* Display CPU time split as percentage of total time.
@@ -618,7 +619,7 @@
#endif
/* what info of the processes is shown */
- printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width,
+ printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width,
" PID PPID USER STAT VSZ %VSZ"
IF_FEATURE_TOP_SMP_PROCESS(" CPU")
IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
@@ -802,7 +803,7 @@
meminfo[MI_ANONPAGES],
meminfo[MI_MAPPED],
meminfo[MI_MEMFREE]);
- printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf);
+ printf(OPT_BATCH_MODE ? "%.*s\n" : ESC"[H" ESC"[J" "%.*s\n", scr_width, line_buf);
snprintf(line_buf, LINE_BUF_SIZE,
" slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu",
@@ -844,7 +845,7 @@
cp[6] = ch;
do *cp++ = ch; while (*cp == ' ');
- printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf);
+ printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, line_buf);
lines_rem--;
if (lines_rem > ntop - G_scroll_ofs)
diff --git a/procps/watch.c b/procps/watch.c
index 6fc9f7d..e58fd1f 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -37,6 +37,8 @@
#include "libbb.h"
+#define ESC "\033"
+
// procps 2.0.18:
// watch [-d] [-n seconds]
// [--differences[=cumulative]] [--interval=seconds] command
@@ -77,7 +79,7 @@
header = NULL;
while (1) {
/* home; clear to the end of screen */
- printf("\033[H""\033[J");
+ printf(ESC"[H" ESC"[J");
if (!(opt & 0x2)) { // no -t
const unsigned time_len = sizeof("1234-67-90 23:56:89");