From 1af9b8e430038f9c8e7754832986906648911278 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 27 Jul 2022 20:25:12 +0200 Subject: [PATCH] Prefix history pager results with a fake prompt This makes it easy to see where the individual commands start. Perhaps we can get rid of this once we have syntax highlighting for the commands in the history pager, or if we add timestamps as descriptions. --- src/pager.cpp | 11 +++++++++-- src/pager.h | 3 ++- src/reader.cpp | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pager.cpp b/src/pager.cpp index 99d46f274..8eb0dee10 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -153,7 +153,10 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s highlight_role_t bg_role = modify_role(highlight_role_t::pager_background); highlight_spec_t bg = {highlight_role_t::normal, bg_role}; - highlight_spec_t prefix_col = {modify_role(highlight_role_t::pager_prefix), bg_role}; + highlight_spec_t prefix_col = { + modify_role(highlight_prefix ? highlight_role_t::pager_prefix + : highlight_role_t::pager_completion), + bg_role}; highlight_spec_t comp_col = {modify_role(highlight_role_t::pager_completion), bg_role}; highlight_spec_t desc_col = {modify_role(highlight_role_t::pager_description), bg_role}; @@ -392,7 +395,10 @@ void pager_t::set_completions(const completion_list_t &raw_completions) { have_unrendered_completions = true; } -void pager_t::set_prefix(const wcstring &pref) { prefix = pref; } +void pager_t::set_prefix(const wcstring &pref, bool highlight) { + prefix = pref; + highlight_prefix = highlight; +} void pager_t::set_term_size(termsize_t ts) { available_term_width = ts.width > 0 ? ts.width : 0; @@ -858,6 +864,7 @@ void pager_t::clear() { unfiltered_completion_infos.clear(); completion_infos.clear(); prefix.clear(); + highlight_prefix = false; selected_completion_idx = PAGER_SELECTION_NONE; fully_disclosed = false; search_field_shown = false; diff --git a/src/pager.h b/src/pager.h index 9b65cc031..4fca05790 100644 --- a/src/pager.h +++ b/src/pager.h @@ -121,6 +121,7 @@ class pager_t { bool have_unrendered_completions = false; wcstring prefix; + bool highlight_prefix = false; bool completion_try_print(size_t cols, const wcstring &prefix, const comp_info_list_t &lst, page_rendering_t *rendering, size_t suggested_start_row) const; @@ -145,7 +146,7 @@ class pager_t { void set_completions(const completion_list_t &raw_completions); // Sets the prefix. - void set_prefix(const wcstring &pref); + void set_prefix(const wcstring &pref, bool highlight = true); // Sets the terminal size. void set_term_size(termsize_t ts); diff --git a/src/reader.cpp b/src/reader.cpp index 91e8b916a..8f9052f73 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3754,7 +3754,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat this->history_pager_history_index_end = 0; // Update the pager data. pager.set_search_field_shown(true); - pager.set_prefix(L""); + pager.set_prefix(MB_CUR_MAX > 1 ? L"► " : L"> ", false /* highlight */); // Update the search field, which triggers the actual history search. insert_string(&pager.search_field_line, command_line.text()); break;