*: 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>
This commit is contained in:
parent
136946c3ea
commit
8187e01438
@ -23,9 +23,11 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
#define ESC "\033"
|
||||||
|
|
||||||
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||||
{
|
{
|
||||||
/* home; clear to the end of screen */
|
/* 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;
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,11 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
|||||||
/* See 'man 4 console_codes' for details:
|
/* See 'man 4 console_codes' for details:
|
||||||
* "ESC c" -- Reset
|
* "ESC c" -- Reset
|
||||||
* "ESC ( B" -- Select G0 Character Set (B = US)
|
* "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 [ J" -- Erase to the end of screen
|
||||||
* "ESC [ ? 25 h" -- Make cursor visible
|
* "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:
|
/* http://bugs.busybox.net/view.php?id=1414:
|
||||||
* people want it to reset echo etc: */
|
* people want it to reset echo etc: */
|
||||||
#if ENABLE_STTY
|
#if ENABLE_STTY
|
||||||
|
@ -347,6 +347,8 @@ struct globals {
|
|||||||
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
|
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define ESC "\033"
|
||||||
|
|
||||||
|
|
||||||
/*** Output code ***/
|
/*** Output code ***/
|
||||||
|
|
||||||
@ -586,12 +588,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
|||||||
if (!mode)
|
if (!mode)
|
||||||
if (lstat(dn->fullname, &statbuf) == 0)
|
if (lstat(dn->fullname, &statbuf) == 0)
|
||||||
mode = statbuf.st_mode;
|
mode = statbuf.st_mode;
|
||||||
printf("\033[%u;%um", bold(mode), fgcolor(mode));
|
printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
column += print_name(dn->name);
|
column += print_name(dn->name);
|
||||||
if (G_show_color) {
|
if (G_show_color) {
|
||||||
printf("\033[0m");
|
printf(ESC"[m");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpath) {
|
if (lpath) {
|
||||||
@ -609,7 +611,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
|||||||
# endif
|
# endif
|
||||||
# if ENABLE_FEATURE_LS_COLOR
|
# if ENABLE_FEATURE_LS_COLOR
|
||||||
if (G_show_color) {
|
if (G_show_color) {
|
||||||
printf("\033[%u;%um", bold(mode), fgcolor(mode));
|
printf(ESC"[%u;%um", bold(mode), fgcolor(mode));
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
@ -617,7 +619,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
|||||||
column += print_name(lpath) + 4;
|
column += print_name(lpath) + 4;
|
||||||
free(lpath);
|
free(lpath);
|
||||||
if (G_show_color) {
|
if (G_show_color) {
|
||||||
printf("\033[0m");
|
printf(ESC"[m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_LS_FILETYPES
|
#if ENABLE_FEATURE_LS_FILETYPES
|
||||||
|
21
editors/vi.c
21
editors/vi.c
@ -224,24 +224,25 @@ enum {
|
|||||||
* See "Xterm Control Sequences"
|
* See "Xterm Control Sequences"
|
||||||
* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
||||||
*/
|
*/
|
||||||
|
#define ESC "\033"
|
||||||
/* Inverse/Normal text */
|
/* Inverse/Normal text */
|
||||||
#define ESC_BOLD_TEXT "\033[7m"
|
#define ESC_BOLD_TEXT ESC"[7m"
|
||||||
#define ESC_NORM_TEXT "\033[0m"
|
#define ESC_NORM_TEXT ESC"[m"
|
||||||
/* Bell */
|
/* Bell */
|
||||||
#define ESC_BELL "\007"
|
#define ESC_BELL "\007"
|
||||||
/* Clear-to-end-of-line */
|
/* Clear-to-end-of-line */
|
||||||
#define ESC_CLEAR2EOL "\033[K"
|
#define ESC_CLEAR2EOL ESC"[K"
|
||||||
/* Clear-to-end-of-screen.
|
/* Clear-to-end-of-screen.
|
||||||
* (We use default param here.
|
* (We use default param here.
|
||||||
* Full sequence is "ESC [ <num> J",
|
* Full sequence is "ESC [ <num> J",
|
||||||
* <num> is 0/1/2 = "erase below/above/all".)
|
* <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) */
|
/* 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
|
//UNUSED
|
||||||
///* Cursor up and down */
|
///* Cursor up and down */
|
||||||
//#define ESC_CURSOR_UP "\033[A"
|
//#define ESC_CURSOR_UP ESC"[A"
|
||||||
//#define ESC_CURSOR_DOWN "\n"
|
//#define ESC_CURSOR_DOWN "\n"
|
||||||
|
|
||||||
#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
|
#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
|
||||||
@ -696,14 +697,14 @@ int vi_main(int argc, char **argv)
|
|||||||
save_argc = argc;
|
save_argc = argc;
|
||||||
optind = 0;
|
optind = 0;
|
||||||
// "Save cursor, use alternate screen buffer, clear screen"
|
// "Save cursor, use alternate screen buffer, clear screen"
|
||||||
write1("\033[?1049h");
|
write1(ESC"[?1049h");
|
||||||
while (1) {
|
while (1) {
|
||||||
edit_file(argv[optind]); /* param might be NULL */
|
edit_file(argv[optind]); /* param might be NULL */
|
||||||
if (++optind >= argc)
|
if (++optind >= argc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// "Use normal screen buffer, restore cursor"
|
// "Use normal screen buffer, restore cursor"
|
||||||
write1("\033[?1049l");
|
write1(ESC"[?1049l");
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -772,7 +773,7 @@ static void edit_file(char *fn)
|
|||||||
#if ENABLE_FEATURE_VI_ASK_TERMINAL
|
#if ENABLE_FEATURE_VI_ASK_TERMINAL
|
||||||
if (G.get_rowcol_error /* TODO? && no input on stdin */) {
|
if (G.get_rowcol_error /* TODO? && no input on stdin */) {
|
||||||
uint64_t k;
|
uint64_t k;
|
||||||
write1("\033[999;999H" "\033[6n");
|
write1(ESC"[999;999H" ESC"[6n");
|
||||||
fflush_all();
|
fflush_all();
|
||||||
k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100);
|
k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100);
|
||||||
if ((int32_t)k == KEYCODE_CURSOR_POS) {
|
if ((int32_t)k == KEYCODE_CURSOR_POS) {
|
||||||
@ -4454,7 +4455,7 @@ static void crash_dummy()
|
|||||||
sleeptime = 0; // how fast to type
|
sleeptime = 0; // how fast to type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcat(readbuffer, "\033");
|
strcat(readbuffer, ESC);
|
||||||
}
|
}
|
||||||
readbuffer[0] = strlen(readbuffer + 1);
|
readbuffer[0] = strlen(readbuffer + 1);
|
||||||
cd1:
|
cd1:
|
||||||
|
@ -2868,7 +2868,7 @@ int main(int argc, char **argv)
|
|||||||
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||||
"\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:"
|
"\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:"
|
||||||
"\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] "
|
"\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] "
|
||||||
"\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]";
|
"\\!\\[\\e[36;1m\\]\\$ \\[\\E[m\\]";
|
||||||
#else
|
#else
|
||||||
"% ";
|
"% ";
|
||||||
#endif
|
#endif
|
||||||
|
@ -65,6 +65,8 @@
|
|||||||
/* If you want logging messages on /tmp/fbsplash.log... */
|
/* If you want logging messages on /tmp/fbsplash.log... */
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
|
#define ESC "\033"
|
||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
bool bdebug_messages; // enable/disable logging
|
bool bdebug_messages; // enable/disable logging
|
||||||
@ -514,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
if (fifo_filename && bCursorOff) {
|
if (fifo_filename && bCursorOff) {
|
||||||
// hide cursor (BEFORE any fb ops)
|
// hide cursor (BEFORE any fb ops)
|
||||||
full_write(STDOUT_FILENO, "\033[?25l", 6);
|
full_write(STDOUT_FILENO, ESC"[?25l", 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
fb_drawimage();
|
fb_drawimage();
|
||||||
@ -559,7 +561,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bCursorOff) // restore cursor
|
if (bCursorOff) // restore cursor
|
||||||
full_write(STDOUT_FILENO, "\033[?25h", 6);
|
full_write(STDOUT_FILENO, ESC"[?25h", 6);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@
|
|||||||
#define ESC "\033"
|
#define ESC "\033"
|
||||||
/* The escape codes for highlighted and normal text */
|
/* The escape codes for highlighted and normal text */
|
||||||
#define HIGHLIGHT ESC"[7m"
|
#define HIGHLIGHT ESC"[7m"
|
||||||
#define NORMAL ESC"[0m"
|
#define NORMAL ESC"[m"
|
||||||
/* The escape code to home and clear to the end of screen */
|
/* The escape code to home and clear to the end of screen */
|
||||||
#define CLEAR ESC"[H"ESC"[J"
|
#define CLEAR ESC"[H"ESC"[J"
|
||||||
/* The escape code to clear to the end of line */
|
/* The escape code to clear to the end of line */
|
||||||
@ -1042,7 +1042,7 @@ static void reinitialize(void)
|
|||||||
open_file_and_read_lines();
|
open_file_and_read_lines();
|
||||||
#if ENABLE_FEATURE_LESS_ASK_TERMINAL
|
#if ENABLE_FEATURE_LESS_ASK_TERMINAL
|
||||||
if (G.winsize_err)
|
if (G.winsize_err)
|
||||||
printf("\033[999;999H" "\033[6n");
|
printf(ESC"[999;999H" ESC"[6n");
|
||||||
#endif
|
#endif
|
||||||
buffer_fill_and_print();
|
buffer_fill_and_print();
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
/* Max filename length of entry in /sys/devices subsystem */
|
/* Max filename length of entry in /sys/devices subsystem */
|
||||||
#define BIG_SYSNAME_LEN 16
|
#define BIG_SYSNAME_LEN 16
|
||||||
|
|
||||||
|
#define ESC "\033"
|
||||||
|
|
||||||
typedef unsigned long long ullong;
|
typedef unsigned long long ullong;
|
||||||
|
|
||||||
struct line {
|
struct line {
|
||||||
@ -776,8 +778,8 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the screen */
|
/* Home; clear screen */
|
||||||
printf("\033[H\033[J");
|
printf(ESC"[H" ESC"[J");
|
||||||
|
|
||||||
/* Clear C-state lines */
|
/* Clear C-state lines */
|
||||||
memset(&cstate_lines, 0, sizeof(cstate_lines));
|
memset(&cstate_lines, 0, sizeof(cstate_lines));
|
||||||
|
@ -117,6 +117,7 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
#define ESC "\033"
|
||||||
|
|
||||||
typedef struct top_status_t {
|
typedef struct top_status_t {
|
||||||
unsigned long vsz;
|
unsigned long vsz;
|
||||||
@ -580,7 +581,7 @@ static unsigned long display_header(int scr_width, int *lines_rem_p)
|
|||||||
meminfo[MI_BUFFERS],
|
meminfo[MI_BUFFERS],
|
||||||
meminfo[MI_CACHED]);
|
meminfo[MI_CACHED]);
|
||||||
/* Go to top & clear to the end of screen */
|
/* 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)--;
|
(*lines_rem_p)--;
|
||||||
|
|
||||||
/* Display CPU time split as percentage of total time.
|
/* Display CPU time split as percentage of total time.
|
||||||
@ -618,7 +619,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* what info of the processes is shown */
|
/* 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"
|
" PID PPID USER STAT VSZ %VSZ"
|
||||||
IF_FEATURE_TOP_SMP_PROCESS(" CPU")
|
IF_FEATURE_TOP_SMP_PROCESS(" CPU")
|
||||||
IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
|
IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
|
||||||
@ -802,7 +803,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p)
|
|||||||
meminfo[MI_ANONPAGES],
|
meminfo[MI_ANONPAGES],
|
||||||
meminfo[MI_MAPPED],
|
meminfo[MI_MAPPED],
|
||||||
meminfo[MI_MEMFREE]);
|
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,
|
snprintf(line_buf, LINE_BUF_SIZE,
|
||||||
" slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu",
|
" slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu",
|
||||||
@ -844,7 +845,7 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width)
|
|||||||
cp[6] = ch;
|
cp[6] = ch;
|
||||||
do *cp++ = ch; while (*cp == ' ');
|
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--;
|
lines_rem--;
|
||||||
|
|
||||||
if (lines_rem > ntop - G_scroll_ofs)
|
if (lines_rem > ntop - G_scroll_ofs)
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
#define ESC "\033"
|
||||||
|
|
||||||
// procps 2.0.18:
|
// procps 2.0.18:
|
||||||
// watch [-d] [-n seconds]
|
// watch [-d] [-n seconds]
|
||||||
// [--differences[=cumulative]] [--interval=seconds] command
|
// [--differences[=cumulative]] [--interval=seconds] command
|
||||||
@ -77,7 +79,7 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
header = NULL;
|
header = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
/* home; clear to the end of screen */
|
/* home; clear to the end of screen */
|
||||||
printf("\033[H""\033[J");
|
printf(ESC"[H" ESC"[J");
|
||||||
if (!(opt & 0x2)) { // no -t
|
if (!(opt & 0x2)) { // no -t
|
||||||
const unsigned time_len = sizeof("1234-67-90 23:56:89");
|
const unsigned time_len = sizeof("1234-67-90 23:56:89");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user