From c6fe65bad33c8b988032e40e8fab78f735ab4687 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Fri, 29 Sep 2017 14:05:20 -0700 Subject: [PATCH] Make italics/dim work on MacOS Work around ancient terminfo on MacOS by hard-coding the correct escapes. Fixes #4436. --- src/builtin_set_color.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/builtin_set_color.cpp b/src/builtin_set_color.cpp index a4a5d12fc..b6d9e12bd 100644 --- a/src/builtin_set_color.cpp +++ b/src/builtin_set_color.cpp @@ -61,11 +61,32 @@ static const struct woption long_options[] = {{L"background", required_argument, {L"print-colors", no_argument, NULL, 'c'}, {NULL, 0, NULL, 0}}; +#if __APPLE__ +char sitm_esc[] = "\e[3m"; +char ritm_esc[] = "\e[23m"; +char dim_esc[] = "\e[2m"; +#endif + /// set_color builtin. int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // By the time this is called we should have initialized the curses subsystem. assert(curses_initialized); + // Hack in missing italics and dim capabilities omitted from MacOS xterm-256color terminfo + // Helps Terminal.app/iTerm + #if __APPLE__ + const auto term_prog = env_get(L"TERM_PROGRAM"); + if (!term_prog.missing_or_empty() && (term_prog->as_string() == L"Apple_Terminal" + || term_prog->as_string() == L"iTerm.app")) { + const auto term = env_get(L"TERM"); + if (!term.missing_or_empty() && (term->as_string() == L"xterm-256color")) { + enter_italics_mode = sitm_esc; + exit_italics_mode = ritm_esc; + enter_dim_mode = dim_esc; + } + } + #endif + // Variables used for parsing the argument list. wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv);