switch from \1xb to \e in the code

Using `\e` is clearer and shorter than `\x1b`. It's also consistent with how
we write related control chars; e.g., we don't write `\x0a` we write '\n'.
This commit is contained in:
Kurtis Rader 2016-12-23 16:37:00 -08:00
parent 58347d494a
commit 7c40abe4a6
10 changed files with 30 additions and 31 deletions

View file

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

View file

@ -312,7 +312,7 @@ void builtin_printf_state_t::print_esc_char(wchar_t c) {
break;
}
case L'e': { // escape
this->append_output(L'\x1B');
this->append_output(L'\e');
break;
}
case L'f': { // form feed

View file

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

View file

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

View file

@ -119,7 +119,7 @@ static void err(const wchar_t *blah, ...) {
// Show errors in red.
if (colorize) {
fputs("\x1b[31m", stdout);
fputs("\e[31m", stdout);
}
wprintf(L"Error: ");
vwprintf(blah, va);
@ -127,7 +127,7 @@ static void err(const wchar_t *blah, ...) {
// Return to normal color.
if (colorize) {
fputs("\x1b[0m", stdout);
fputs("\e[0m", stdout);
}
wprintf(L"\n");
@ -1117,26 +1117,25 @@ static void test_escape_sequences(void) {
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"\x1b[2J") != 4)
if (escape_code_length(L"\e[2J") != 4)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\x1b[38;5;123mABC") != strlen("\x1b[38;5;123m"))
if (escape_code_length(L"\e[38;5;123mABC") != strlen("\e[38;5;123m"))
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\x1b@") != 2)
if (escape_code_length(L"\e@") != 2)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
// iTerm2 escape sequences.
if (escape_code_length(L"\x1b]50;CurrentDir=/tmp/foo\x07NOT_PART_OF_SEQUENCE") != 25)
if (escape_code_length(L"\e]50;CurrentDir=/tmp/foo\x07NOT_PART_OF_SEQUENCE") != 25)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\x1b]50;SetMark\x07NOT_PART_OF_SEQUENCE") != 13)
if (escape_code_length(L"\e]50;SetMark\x07NOT_PART_OF_SEQUENCE") != 13)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\x1b"
L"]6;1;bg;red;brightness;255\x07NOT_PART_OF_SEQUENCE") != 28)
if (escape_code_length(L"\e]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"\x1b]Pg4040ff\x1b\\NOT_PART_OF_SEQUENCE") != 12)
if (escape_code_length(L"\e]Pg4040ff\e\\NOT_PART_OF_SEQUENCE") != 12)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\x1b]blahblahblah\x1b\\") != 16)
if (escape_code_length(L"\e]blahblahblah\e\\") != 16)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
if (escape_code_length(L"\x1b]blahblahblah\x07") != 15)
if (escape_code_length(L"\e]blahblahblah\x07") != 15)
err(L"test_escape_sequences failed on line %d\n", __LINE__);
}

View file

@ -28,7 +28,7 @@
#include "wutil.h"
/// Time in milliseconds to wait for another byte to be available for reading
/// after \x1b is read before assuming that escape key was pressed, and not an
/// after \e 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

@ -79,9 +79,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, "\x1b[%dm", ((idx > 7) ? 82 : 30) + idx + !is_fg * 10);
snprintf(buff, sizeof buff, "\e[%dm", ((idx > 7) ? 82 : 30) + idx + !is_fg * 10);
} else {
snprintf(buff, sizeof buff, "\x1b[%d;5;%dm", is_fg ? 38 : 48, idx);
snprintf(buff, sizeof buff, "\e[%d;5;%dm", is_fg ? 38 : 48, idx);
}
int (*writer)(char) = output_get_writer();
@ -127,7 +127,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, "\x1b[%d;2;%u;%u;%um", is_fg ? 38 : 48, rgb.rgb[0], rgb.rgb[1],
snprintf(buff, sizeof buff, "\e[%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

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

View file

@ -2719,7 +2719,7 @@ const wchar_t *reader_readline(int nchars) {
break;
}
// Escape was pressed.
case L'\x1b': {
case L'\e': {
if (data->search_mode) {
data->search_mode = NO_SEARCH;

View file

@ -118,7 +118,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"\x1b\\";
const wchar_t *const screen_name_end_sentinel = L"\e\\";
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.
@ -139,7 +139,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] == '\x1b')) {
if (code[cursor] == '\x07' || (code[cursor] == '\\' && code[cursor - 1] == '\e')) {
found = true;
break;
}
@ -199,12 +199,12 @@ static bool is_csi_style_escape_seq(const wchar_t *code, size_t *resulting_lengt
}
/// Returns the number of characters in the escape code starting at 'code' (which should initially
/// contain \x1b).
/// contain \e).
size_t escape_code_length(const wchar_t *code) {
assert(code != NULL);
// The only escape codes we recognize start with \x1b.
if (code[0] != L'\x1b') return 0;
// The only escape codes we recognize start with \e.
if (code[0] != L'\e') return 0;
size_t resulting_length = 0;
bool found = false;
@ -284,7 +284,7 @@ static prompt_layout_t calc_prompt_layout(const wchar_t *prompt) {
prompt_layout.line_count = 1;
for (j = 0; prompt[j]; j++) {
if (prompt[j] == L'\x1b') {
if (prompt[j] == L'\e') {
// This is the start of an escape code. Skip over it if it's at least one character
// long.
size_t escape_len = escape_code_length(&prompt[j]);