fix description line not truncating in columnar menu (#739)

* add builder functions

* fix description wrap

* fmt

* fix
This commit is contained in:
maxomatic458 2024-02-03 00:59:12 +01:00 committed by GitHub
parent 9f0095f150
commit f2447364b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ use crate::{
Completer, Suggestion,
};
use nu_ansi_term::ansi::RESET;
use unicode_width::UnicodeWidthStr;
/// Default values used as reference for the menu. These values are set during
/// the initial declaration of the menu and are always kept as reference for the
@ -308,12 +309,16 @@ impl ColumnarMenu {
.unwrap_or(self.settings.color.text_style)
.prefix();
let left_text_size = self.longest_suggestion + self.default_details.col_padding;
let right_text_size = self.get_width().saturating_sub(left_text_size);
let max_remaining = left_text_size.saturating_sub(match_str.width());
let max_match = max_remaining.saturating_sub(remaining_str.width());
if index == self.index() {
if let Some(description) = &suggestion.description {
let left_text_size = self.longest_suggestion + self.default_details.col_padding;
let right_text_size = self.get_width().saturating_sub(left_text_size);
format!(
"{}{}{}{}{}{}{:max$}{}{}{}{}{}{}",
"{}{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}{}",
suggestion_style_prefix,
self.settings.color.selected_match_style.prefix(),
match_str,
@ -331,7 +336,6 @@ impl ColumnarMenu {
.replace('\n', " "),
RESET,
self.end_of_line(column),
max = left_text_size,
)
} else {
format!(
@ -350,10 +354,8 @@ impl ColumnarMenu {
)
}
} else if let Some(description) = &suggestion.description {
let left_text_size = self.longest_suggestion + self.default_details.col_padding;
let right_text_size = self.get_width().saturating_sub(left_text_size);
format!(
"{}{}{}{}{}{:max$}{}{}{}{}{}",
"{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}",
suggestion_style_prefix,
self.settings.color.match_style.prefix(),
match_str,
@ -369,7 +371,6 @@ impl ColumnarMenu {
.replace('\n', " "),
RESET,
self.end_of_line(column),
max = left_text_size,
)
} else {
format!(