Skip to content

Commit

Permalink
fix description line not truncating in columnar menu (#739)
Browse files Browse the repository at this point in the history
* add builder functions

* fix description wrap

* fmt

* fix
  • Loading branch information
maxomatic458 authored Feb 2, 2024
1 parent 9f0095f commit f244736
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/menu/columnar_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -331,7 +336,6 @@ impl ColumnarMenu {
.replace('\n', " "),
RESET,
self.end_of_line(column),
max = left_text_size,
)
} else {
format!(
Expand All @@ -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,
Expand All @@ -369,7 +371,6 @@ impl ColumnarMenu {
.replace('\n', " "),
RESET,
self.end_of_line(column),
max = left_text_size,
)
} else {
format!(
Expand Down

0 comments on commit f244736

Please sign in to comment.