diff --git a/src/history/history.rs b/src/history/history.rs index 54da16656..745c08ef3 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -1114,6 +1114,8 @@ fn format_history_record( item: &HistoryItem, show_time_format: Option<&str>, null_terminate: bool, + parser: &Parser, + color_enabled: bool, ) -> WString { let mut result = WString::new(); let seconds = time_to_seconds(item.timestamp()); @@ -1139,7 +1141,16 @@ fn format_history_record( } } - result.push_utfstr(item.str()); + let mut command = item.str().to_owned(); + if color_enabled { + command = bytes2wcstring(&highlight_and_colorize( + &command, + &parser.context(), + parser.vars(), + )); + } + + result.push_utfstr(&command); result.push(if null_terminate { '\0' } else { '\n' }); result } @@ -1366,16 +1377,13 @@ pub fn search( return ControlFlow::Break(()); } remaining -= 1; - let mut formatted_record = - format_history_record(item, show_time_format, null_terminate); - - if color_enabled { - formatted_record = bytes2wcstring(&highlight_and_colorize( - &formatted_record, - &parser.context(), - parser.vars(), - )); - } + let formatted_record = format_history_record( + item, + show_time_format, + null_terminate, + parser, + color_enabled, + ); if reverse { // We need to collect this for later.