Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 24, 2024
1 parent 221ab21 commit 5826d06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/completion/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,10 @@ pub struct Suggestion {
/// This helps to avoid that a completer repeats the complete suggestion.
pub append_whitespace: bool,
}

impl Suggestion {
/// Returns display if set, otherwise value.
pub fn display_or_value(&self) -> &String {
self.display.as_ref().unwrap_or(&self.value)
}
}
25 changes: 12 additions & 13 deletions src/menu/columnar_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl ColumnarMenu {
.reverse()
.prefix(),
self.color.selected_text_style.prefix(),
suggestion.display.as_ref().unwrap_or(&suggestion.value),
suggestion.display_or_value(),
RESET,
self.color.description_style.reverse().prefix(),
self.color.selected_text_style.prefix(),
Expand All @@ -373,7 +373,7 @@ impl ColumnarMenu {
.reverse()
.prefix(),
self.color.selected_text_style.prefix(),
suggestion.display.as_ref().unwrap_or(&suggestion.value),
suggestion.display_or_value(),
RESET,
"",
self.end_of_line(column),
Expand All @@ -386,7 +386,7 @@ impl ColumnarMenu {
format!(
"{}{:max$}{}{}{}{}{}",
suggestion.style.unwrap_or(self.color.text_style).prefix(),
suggestion.display.as_ref().unwrap_or(&suggestion.value),
suggestion.display_or_value(),
RESET,
self.color.description_style.prefix(),
description
Expand All @@ -402,7 +402,7 @@ impl ColumnarMenu {
format!(
"{}{}{}{}{:>empty$}{}{}",
suggestion.style.unwrap_or(self.color.text_style).prefix(),
suggestion.display.as_ref().unwrap_or(&suggestion.value),
suggestion.display_or_value(),
RESET,
self.color.description_style.prefix(),
"",
Expand All @@ -419,7 +419,7 @@ impl ColumnarMenu {
format!(
"{}{:max$}{}{}",
marker,
suggestion.display.as_ref().unwrap_or(&suggestion.value),
suggestion.display_or_value(),
description
.chars()
.take(empty_space)
Expand All @@ -436,7 +436,7 @@ impl ColumnarMenu {
format!(
"{}{}{:>empty$}{}",
marker,
suggestion.display.as_ref().unwrap_or(&suggestion.value),
suggestion.display_or_value(),
"",
self.end_of_line(column),
empty = empty_space.saturating_sub(marker.len()),
Expand Down Expand Up @@ -590,11 +590,7 @@ impl Menu for ColumnarMenu {
self.working_details.col_width = painter.screen_width() as usize;

self.longest_suggestion = self.get_values().iter().fold(0, |prev, suggestion| {
let suggestion_length = suggestion
.display
.as_ref()
.unwrap_or(&suggestion.value)
.len();
let suggestion_length = suggestion.display_or_value().len();
if prev >= suggestion_length {
prev
} else {
Expand All @@ -603,7 +599,8 @@ impl Menu for ColumnarMenu {
});
} else {
let max_width = self.get_values().iter().fold(0, |acc, suggestion| {
let str_len = suggestion.value.len() + self.default_details.col_padding;
let str_len =
suggestion.display_or_value().len() + self.default_details.col_padding;
if str_len > acc {
str_len
} else {
Expand Down Expand Up @@ -739,7 +736,9 @@ impl Menu for ColumnarMenu {
// Correcting the enumerate index based on the number of skipped values
let index = index + skip_values;
let column = index as u16 % self.get_cols();
let empty_space = self.get_width().saturating_sub(suggestion.value.len());
let empty_space = self
.get_width()
.saturating_sub(suggestion.display_or_value().len());

self.create_string(suggestion, index, column, empty_space, use_ansi_coloring)
})
Expand Down

0 comments on commit 5826d06

Please sign in to comment.