#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;
}
/* 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
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
} while (0)
+#define ESC "\033"
+
/*** Output code ***/
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) {
# 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
}
column += print_name(lpath) + 4;
free(lpath);
if (G_show_color) {
- printf("\033[0m");
+ printf(ESC"[m");
}
}
#if ENABLE_FEATURE_LS_FILETYPES
* 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
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;
#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) {
sleeptime = 0; // how fast to type
}
}
- strcat(readbuffer, "\033");
+ strcat(readbuffer, ESC);
}
readbuffer[0] = strlen(readbuffer + 1);
cd1:
#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
/* 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
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();
}
if (bCursorOff) // restore cursor
- full_write(STDOUT_FILENO, "\033[?25h", 6);
+ full_write(STDOUT_FILENO, ESC"[?25h", 6);
return EXIT_SUCCESS;
}
#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 */
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();
}
/* Max filename length of entry in /sys/devices subsystem */
#define BIG_SYSNAME_LEN 16
+#define ESC "\033"
+
typedef unsigned long long ullong;
struct line {
}
}
- /* 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));
#include "libbb.h"
+#define ESC "\033"
typedef struct top_status_t {
unsigned long vsz;
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.
#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")
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",
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)
#include "libbb.h"
+#define ESC "\033"
+
// procps 2.0.18:
// watch [-d] [-n seconds]
// [--differences[=cumulative]] [--interval=seconds] command
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");