From d3bb2a718aa69bf58331a833a7dad07cb2e1dbcc Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 16 Jul 2013 13:25:42 -0700 Subject: [PATCH] Make printf support \e as the escape character https://github.com/fish-shell/fish-shell/issues/910 --- builtin_printf.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin_printf.cpp b/builtin_printf.cpp index e164f8193..f6cef3d6c 100644 --- a/builtin_printf.cpp +++ b/builtin_printf.cpp @@ -26,6 +26,7 @@ \a = alert (bell) \b = backspace \c = produce no further output + \e = escape \f = form feed \n = new line \r = carriage return @@ -319,6 +320,9 @@ void builtin_printf_state_t::print_esc_char(wchar_t c) case L'c': /* Cancel the rest of the output. */ this->early_exit = true; break; + case L'e': /* Escape */ + this->append_output(L'\x1B'); + break; case L'f': /* Form feed. */ this->append_output(L'\f'); break; @@ -369,8 +373,10 @@ long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0) esc_value = esc_value * 8 + octal_to_bin(*p); this->append_format_output(L"%c", esc_value); } - else if (*p && wcschr(L"\"\\abcfnrtv", *p)) + else if (*p && wcschr(L"\"\\abcefnrtv", *p)) + { print_esc_char(*p++); + } else if (*p == L'u' || *p == L'U') { wchar_t esc_char = *p;