diff --git a/src/history.cpp b/src/history.cpp index 554d521bf..0f07f566f 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -794,11 +794,10 @@ void history_t::add(const wcstring &str, history_identifier_t ident, bool pendin bool icompare_pred(wchar_t a, wchar_t b) { return std::tolower(a) == std::tolower(b); } bool icompare(wcstring const &a, wcstring const &b) { - if (a.length() == b.length()) { - return std::equal(b.begin(), b.end(), a.begin(), icompare_pred); - } else { + if (a.length() != b.length()) { return false; } + return std::equal(b.begin(), b.end(), a.begin(), icompare_pred); } // Remove matching history entries from our list of new items. This only supports literal, diff --git a/src/output.cpp b/src/output.cpp index 271ddae5f..039d32ce5 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -66,33 +66,32 @@ static bool write_color_escape(char *todo, unsigned char idx, bool is_fg) { if (term_supports_color_natively(idx)) { // Use tparm to emit color escape. writembs(tparm(todo, idx)); - return true; - } else { - // We are attempting to bypass the term here. Generate the ANSI escape sequence ourself. - char buff[16] = ""; - if (idx < 16) { - // this allows the non-bright color to happen instead of no color working at all when - // a bright is attempted when only colors 0-7 are supported. - // TODO: enter bold mode in builtin_set_color in the same circumstance- doing that - // combined - // 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); - } else { - snprintf(buff, sizeof buff, "\x1b[%d;5;%dm", is_fg ? 38 : 48, idx); - } - - int (*writer)(char) = output_get_writer(); - if (writer) { - for (size_t i = 0; buff[i]; i++) { - writer(buff[i]); - } - } - return true; } + + // We are attempting to bypass the term here. Generate the ANSI escape sequence ourself. + char buff[16] = ""; + if (idx < 16) { + // this allows the non-bright color to happen instead of no color working at all when a + // bright is attempted when only colors 0-7 are supported. + // + // TODO: enter bold mode in builtin_set_color in the same circumstance- doing that combined + // 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); + } else { + snprintf(buff, sizeof buff, "\x1b[%d;5;%dm", is_fg ? 38 : 48, idx); + } + + int (*writer)(char) = output_get_writer(); + if (writer) { + for (size_t i = 0; buff[i]; i++) { + writer(buff[i]); + } + } + + return true; } static bool write_foreground_color(unsigned char idx) { @@ -121,21 +120,22 @@ bool write_color(rgb_color_t color, bool is_fg) { // Indexed or non-24 bit color. unsigned char idx = index_for_color(color); return (is_fg ? write_foreground_color : write_background_color)(idx); - } else { - // 24 bit! No tparm here, just ANSI escape sequences. - // Foreground: ^[38;2;;;m - // Background: ^[48;2;;;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], - rgb.rgb[2]); - int (*writer)(char) = output_get_writer(); - if (writer) { - for (size_t i = 0; buff[i]; i++) { - writer(buff[i]); - } + } + + // 24 bit! No tparm here, just ANSI escape sequences. + // Foreground: ^[38;2;;;m + // Background: ^[48;2;;;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], + rgb.rgb[2]); + int (*writer)(char) = output_get_writer(); + if (writer) { + for (size_t i = 0; buff[i]; i++) { + writer(buff[i]); } } + return true; } diff --git a/src/parser.cpp b/src/parser.cpp index da5680a75..8a7eefe01 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -564,11 +564,11 @@ bool parser_t::job_remove(job_t *j) { if (iter != my_job_list.end()) { my_job_list.erase(iter); return true; - } else { - debug(1, _(L"Job inconsistency")); - sanity_lose(); - return false; } + + debug(1, _(L"Job inconsistency")); + sanity_lose(); + return false; } void parser_t::job_promote(job_t *job) { diff --git a/src/reader.cpp b/src/reader.cpp index dc610a8c7..2fd5a3b77 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2212,10 +2212,10 @@ static void reader_super_highlight_me_plenty(int match_highlight_pos_adjust, boo } bool shell_is_exiting() { - if (shell_is_interactive()) + if (shell_is_interactive()) { return job_list_is_empty() && data != NULL && data->end_loop; - else - return end_loop; + } + return end_loop; } /// This function is called when the main loop notices that end_loop has been set while in diff --git a/src/wutil.cpp b/src/wutil.cpp index 572f8e510..25556c92f 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -185,11 +185,11 @@ bool set_cloexec(int fd) { int flags = fcntl(fd, F_GETFD, 0); if (flags < 0) { return false; - } else if (flags & FD_CLOEXEC) { - return true; - } else { - return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) >= 0; } + if (flags & FD_CLOEXEC) { + return true; + } + return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) >= 0; } static int wopen_internal(const wcstring &pathname, int flags, mode_t mode, bool cloexec) {