mirror of
https://github.com/nushell/reedline.git
synced 2024-09-11 15:55:50 +03:00
fix description line not truncating in columnar menu (#739)
* add builder functions * fix description wrap * fmt * fix
This commit is contained in:
parent
9f0095f150
commit
f2447364b9
@ -6,6 +6,7 @@ use crate::{
|
|||||||
Completer, Suggestion,
|
Completer, Suggestion,
|
||||||
};
|
};
|
||||||
use nu_ansi_term::ansi::RESET;
|
use nu_ansi_term::ansi::RESET;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Default values used as reference for the menu. These values are set during
|
/// 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
|
/// 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)
|
.unwrap_or(self.settings.color.text_style)
|
||||||
.prefix();
|
.prefix();
|
||||||
|
|
||||||
if index == self.index() {
|
|
||||||
if let Some(description) = &suggestion.description {
|
|
||||||
let left_text_size = self.longest_suggestion + self.default_details.col_padding;
|
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 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 {
|
||||||
format!(
|
format!(
|
||||||
"{}{}{}{}{}{}{:max$}{}{}{}{}{}{}",
|
"{}{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}{}",
|
||||||
suggestion_style_prefix,
|
suggestion_style_prefix,
|
||||||
self.settings.color.selected_match_style.prefix(),
|
self.settings.color.selected_match_style.prefix(),
|
||||||
match_str,
|
match_str,
|
||||||
@ -331,7 +336,6 @@ impl ColumnarMenu {
|
|||||||
.replace('\n', " "),
|
.replace('\n', " "),
|
||||||
RESET,
|
RESET,
|
||||||
self.end_of_line(column),
|
self.end_of_line(column),
|
||||||
max = left_text_size,
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
@ -350,10 +354,8 @@ impl ColumnarMenu {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if let Some(description) = &suggestion.description {
|
} 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!(
|
format!(
|
||||||
"{}{}{}{}{}{:max$}{}{}{}{}{}",
|
"{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}",
|
||||||
suggestion_style_prefix,
|
suggestion_style_prefix,
|
||||||
self.settings.color.match_style.prefix(),
|
self.settings.color.match_style.prefix(),
|
||||||
match_str,
|
match_str,
|
||||||
@ -369,7 +371,6 @@ impl ColumnarMenu {
|
|||||||
.replace('\n', " "),
|
.replace('\n', " "),
|
||||||
RESET,
|
RESET,
|
||||||
self.end_of_line(column),
|
self.end_of_line(column),
|
||||||
max = left_text_size,
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user