aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/menu.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/ui/menu.rs')
-rw-r--r--helix-term/src/ui/menu.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs
index b9c1f9de..e92578c5 100644
--- a/helix-term/src/ui/menu.rs
+++ b/helix-term/src/ui/menu.rs
@@ -4,7 +4,7 @@ use crate::{
compositor::{Callback, Component, Compositor, Context, Event, EventResult},
ctrl, key, shift,
};
-use tui::{buffer::Buffer as Surface, text::Spans, widgets::Table};
+use tui::{buffer::Buffer as Surface, widgets::Table};
pub use tui::widgets::{Cell, Row};
@@ -18,28 +18,24 @@ pub trait Item {
/// Additional editor state that is used for label calculation.
type Data;
- fn label(&self, data: &Self::Data) -> Spans;
+ fn format(&self, data: &Self::Data) -> Row;
fn sort_text(&self, data: &Self::Data) -> Cow<str> {
- let label: String = self.label(data).into();
+ let label: String = self.format(data).cell_text().collect();
label.into()
}
fn filter_text(&self, data: &Self::Data) -> Cow<str> {
- let label: String = self.label(data).into();
+ let label: String = self.format(data).cell_text().collect();
label.into()
}
-
- fn row(&self, data: &Self::Data) -> Row {
- Row::new(vec![Cell::from(self.label(data))])
- }
}
impl Item for PathBuf {
/// Root prefix to strip.
type Data = PathBuf;
- fn label(&self, root_path: &Self::Data) -> Spans {
+ fn format(&self, root_path: &Self::Data) -> Row {
self.strip_prefix(root_path)
.unwrap_or(self)
.to_string_lossy()
@@ -144,10 +140,10 @@ impl<T: Item> Menu<T> {
let n = self
.options
.first()
- .map(|option| option.row(&self.editor_data).cells.len())
+ .map(|option| option.format(&self.editor_data).cells.len())
.unwrap_or_default();
let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
- let row = option.row(&self.editor_data);
+ let row = option.format(&self.editor_data);
// maintain max for each column
for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) {
let width = cell.content.width();
@@ -331,7 +327,9 @@ impl<T: Item + 'static> Component for Menu<T> {
(a + b - 1) / b
}
- let rows = options.iter().map(|option| option.row(&self.editor_data));
+ let rows = options
+ .iter()
+ .map(|option| option.format(&self.editor_data));
let table = Table::new(rows)
.style(style)
.highlight_style(selected)