Replace \e with \x1B, as the former is a gcc extension

While supported by gcc and clang, \e is a gcc-specific extension and not
formally defined in the C or C++ standards.

See [0] for a list of valid escapes.

[0]: https://stackoverflow.com/a/10220539/17027
This commit is contained in:
Mahmoud Al-Qudsi 2018-06-18 00:01:32 -05:00
parent d16d463e0d
commit dcced5f1bc
13 changed files with 40 additions and 40 deletions

View file

@ -214,7 +214,7 @@ int builtin_echo(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
break;
}
case L'e': {
wc = L'\e';
wc = L'\x1B';
break;
}
case L'f': {

View file

@ -26,7 +26,7 @@
// \a = alert (bell)
// \b = backspace
// \c = produce no further output
// \e = escape
// \x1B = escape
// \f = form feed
// \n = new line
// \r = carriage return
@ -317,7 +317,7 @@ void builtin_printf_state_t::print_esc_char(wchar_t c) {
break;
}
case L'e': { // escape
this->append_output(L'\e');
this->append_output(L'\x1B');
break;
}
case L'f': { // form feed

View file

@ -62,9 +62,9 @@ static const struct woption long_options[] = {{L"background", required_argument,
{NULL, 0, NULL, 0}};
#if __APPLE__
char sitm_esc[] = "\e[3m";
char ritm_esc[] = "\e[23m";
char dim_esc[] = "\e[2m";
char sitm_esc[] = "\x1B[3m";
char ritm_esc[] = "\x1B[23m";
char dim_esc[] = "\x1B[2m";
#endif
/// set_color builtin.

View file

@ -981,7 +981,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring
need_escape = need_complex_escape = 1;
break;
}
case L'\e': {
case L'\x1B': {
out += L'\\';
out += L'e';
need_escape = need_complex_escape = 1;
@ -1243,9 +1243,9 @@ size_t read_unquoted_escape(const wchar_t *input, wcstring *result, bool allow_i
}
break;
}
// \e means escape.
// \x1B means escape.
case L'e': {
result_char_or_none = L'\e';
result_char_or_none = L'\x1B';
break;
}
// \f means form feed.

View file

@ -132,7 +132,7 @@ static int is_quotable(const wchar_t *str) {
case L'\t':
case L'\r':
case L'\b':
case L'\e': {
case L'\x1B': {
return 0;
}
default: { return is_quotable(str + 1); }

View file

@ -40,7 +40,7 @@ struct config_paths_t determine_config_directory_paths(const char *argv0);
static const wchar_t *ctrl_symbolic_names[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, L"\\a", L"\\b", L"\\t", L"\\n",
L"\\v", L"\\f", L"\\r", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, L"\\e", NULL, NULL, NULL, NULL};
NULL, NULL, NULL, NULL, NULL, L"\\x1B", NULL, NULL, NULL, NULL};
static bool keep_running = true;
/// Return true if the recent sequence of characters indicates the user wants to exit the program.

View file

@ -125,7 +125,7 @@ static void err(const wchar_t *blah, ...) {
// Show errors in red.
if (colorize) {
fputws(L"\e[31m", stdout);
fputws(L"\x1B[31m", stdout);
}
fwprintf(stdout, L"Error: ");
vfwprintf(stdout, blah, va);
@ -133,7 +133,7 @@ static void err(const wchar_t *blah, ...) {
// Return to normal color.
if (colorize) {
fputws(L"\e[0m", stdout);
fputws(L"\x1B[0m", stdout);
}
fwprintf(stdout, L"\n");
@ -1398,25 +1398,25 @@ static void test_escape_sequences() {
if (escape_code_length(L"") != 0) err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"abcd") != 0)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e[2J") != 4)
if (escape_code_length(L"\x1B[2J") != 4)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e[38;5;123mABC") != strlen("\e[38;5;123m"))
if (escape_code_length(L"\x1B[38;5;123mABC") != strlen("\x1B[38;5;123m"))
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e@") != 2)
if (escape_code_length(L"\x1B@") != 2)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
// iTerm2 escape sequences.
if (escape_code_length(L"\e]50;CurrentDir=test/foo\x07NOT_PART_OF_SEQUENCE") != 25)
if (escape_code_length(L"\x1B]50;CurrentDir=test/foo\x07NOT_PART_OF_SEQUENCE") != 25)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e]50;SetMark\x07NOT_PART_OF_SEQUENCE") != 13)
if (escape_code_length(L"\x1B]50;SetMark\x07NOT_PART_OF_SEQUENCE") != 13)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e]6;1;bg;red;brightness;255\x07NOT_PART_OF_SEQUENCE") != 28)
if (escape_code_length(L"\x1B]6;1;bg;red;brightness;255\x07NOT_PART_OF_SEQUENCE") != 28)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e]Pg4040ff\e\\NOT_PART_OF_SEQUENCE") != 12)
if (escape_code_length(L"\x1B]Pg4040ff\x1B\\NOT_PART_OF_SEQUENCE") != 12)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e]blahblahblah\e\\") != 16)
if (escape_code_length(L"\x1B]blahblahblah\x1B\\") != 16)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\e]blahblahblah\x07") != 15)
if (escape_code_length(L"\x1B]blahblahblah\x07") != 15)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
}

View file

@ -265,10 +265,10 @@ void init_input() {
input_mapping_add(L"\x5", L"bind");
input_mapping_add(L"\x7f", L"backward-delete-char");
// Arrows - can't have functions, so *-or-search isn't available.
input_mapping_add(L"\e[A", L"up-line");
input_mapping_add(L"\e[B", L"down-line");
input_mapping_add(L"\e[C", L"forward-char");
input_mapping_add(L"\e[D", L"backward-char");
input_mapping_add(L"\x1B[A", L"up-line");
input_mapping_add(L"\x1B[B", L"down-line");
input_mapping_add(L"\x1B[C", L"forward-char");
input_mapping_add(L"\x1B[D", L"backward-char");
}
input_initialized = true;
@ -392,7 +392,7 @@ static bool input_mapping_is_match(const input_mapping_t &m) {
// If we just read an escape, we need to add a timeout for the next char,
// to distinguish between the actual escape key and an "alt"-modifier.
timed = (str[i] == L'\e');
timed = (str[i] == L'\x1B');
}
return true;

View file

@ -29,7 +29,7 @@
#include "wutil.h"
/// Time in milliseconds to wait for another byte to be available for reading
/// after \e is read before assuming that escape key was pressed, and not an
/// after \x1B is read before assuming that escape key was pressed, and not an
/// escape sequence.
#define WAIT_ON_ESCAPE_DEFAULT 300
static int wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT;

View file

@ -80,9 +80,9 @@ static bool write_color_escape(char *todo, unsigned char idx, bool is_fg) {
// with what we do here, will make the brights actually work for virtual consoles/ancient
// emulators.
if (max_colors == 8 && idx > 8) idx -= 8;
snprintf(buff, sizeof buff, "\e[%dm", ((idx > 7) ? 82 : 30) + idx + !is_fg * 10);
snprintf(buff, sizeof buff, "\x1B[%dm", ((idx > 7) ? 82 : 30) + idx + !is_fg * 10);
} else {
snprintf(buff, sizeof buff, "\e[%d;5;%dm", is_fg ? 38 : 48, idx);
snprintf(buff, sizeof buff, "\x1B[%d;5;%dm", is_fg ? 38 : 48, idx);
}
int (*writer)(char) = output_get_writer();
@ -131,7 +131,7 @@ bool write_color(rgb_color_t color, bool is_fg) {
// Background: ^[48;2;<r>;<g>;<b>m
color24_t rgb = color.to_color24();
char buff[128];
snprintf(buff, sizeof buff, "\e[%d;2;%u;%u;%um", is_fg ? 38 : 48, rgb.rgb[0], rgb.rgb[1],
snprintf(buff, sizeof buff, "\x1B[%d;2;%u;%u;%um", is_fg ? 38 : 48, rgb.rgb[0], rgb.rgb[1],
rgb.rgb[2]);
int (*writer)(char) = output_get_writer();
if (writer) {

View file

@ -476,7 +476,7 @@ static void format_job_info(const job_t *j, job_status_t status) {
if (cur_term) {
tputs(clr_eol, 1, &writeb);
} else {
fwprintf(stdout, L"\e[K");
fwprintf(stdout, L"\x1B[K");
}
fwprintf(stdout, L"\n");
}
@ -582,7 +582,7 @@ static int process_clean_after_marking(bool allow_interactive) {
if (cur_term != NULL) {
tputs(clr_eol, 1, &writeb);
} else {
fwprintf(stdout, L"\e[K"); // no term set up - do clr_eol manually
fwprintf(stdout, L"\x1B[K"); // no term set up - do clr_eol manually
}
fwprintf(stdout, L"\n");
}

View file

@ -687,7 +687,7 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) {
proc_push_interactive(0);
if (exec_subshell(fish_title_command, lst, false /* ignore exit status */) != -1 &&
!lst.empty()) {
fputws(L"\e]0;", stdout);
fputws(L"\x1B]0;", stdout);
for (size_t i = 0; i < lst.size(); i++) {
fputws(lst.at(i).c_str(), stdout);
}
@ -2687,7 +2687,7 @@ const wchar_t *reader_readline(int nchars) {
break;
}
// Escape was pressed.
case L'\e': {
case L'\x1B': {
if (data->search_mode != history_search_mode_t::none) {
data->search_mode = history_search_mode_t::none;

View file

@ -125,7 +125,7 @@ static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_len
}
#endif
const wchar_t *const screen_name_end_sentinel = L"\e\\";
const wchar_t *const screen_name_end_sentinel = L"\x1B\\";
const wchar_t *screen_name_end = wcsstr(&code[2], screen_name_end_sentinel);
if (screen_name_end == NULL) {
// Consider just <esc>k to be the code.
@ -146,7 +146,7 @@ static bool is_iterm2_escape_seq(const wchar_t *code, size_t *resulting_length)
size_t cursor = 2;
for (; code[cursor] != L'\0'; cursor++) {
// Consume a sequence of characters up to <esc>\ or <bel>.
if (code[cursor] == '\x07' || (code[cursor] == '\\' && code[cursor - 1] == '\e')) {
if (code[cursor] == '\x07' || (code[cursor] == '\\' && code[cursor - 1] == '\x1B')) {
found = true;
break;
}
@ -261,11 +261,11 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
}
/// Returns the number of characters in the escape code starting at 'code'. We only handle sequences
/// that begin with \e. If it doesn't we return zero. We also return zero if we don't recognize the
/// that begin with \x1B. If it doesn't we return zero. We also return zero if we don't recognize the
/// escape sequence based on querying terminfo and other heuristics.
size_t escape_code_length(const wchar_t *code) {
assert(code != NULL);
if (*code != L'\e') return 0;
if (*code != L'\x1B') return 0;
size_t esc_seq_len = cached_layouts.find_escape_code(code);
if (esc_seq_len) return esc_seq_len;
@ -313,7 +313,7 @@ static prompt_layout_t calc_prompt_layout(const wcstring &prompt, layout_cache_t
size_t current_line_width = 0;
for (int j = 0; prompt[j]; j++) {
if (prompt[j] == L'\e') {
if (prompt[j] == L'\x1B') {
// This is the start of an escape code. Skip over it if it's at least one char long.
size_t len = escape_code_length(&prompt[j]);
if (len > 0) j += len - 1;