From 9aafcb2b9a743f0f6afa722184e96b8a672064ea Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sat, 9 Jul 2022 00:16:09 +0530 Subject: Reuse table in picker --- helix-tui/src/text.rs | 13 +++++++++++++ helix-tui/src/widgets/table.rs | 14 +++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'helix-tui') diff --git a/helix-tui/src/text.rs b/helix-tui/src/text.rs index ccdafad5..6970634b 100644 --- a/helix-tui/src/text.rs +++ b/helix-tui/src/text.rs @@ -436,6 +436,19 @@ impl<'a> From>> for Text<'a> { } } +impl<'a> From> for String { + fn from(text: Text<'a>) -> String { + let lines: Vec = text.lines.iter().map(String::from).collect(); + lines.join("\n") + } +} + +impl<'a> From<&Text<'a>> for String { + fn from(text: &Text<'a>) -> String { + let lines: Vec = text.lines.iter().map(String::from).collect(); + lines.join("\n") + } +} impl<'a> IntoIterator for Text<'a> { type Item = Spans<'a>; type IntoIter = std::vec::IntoIter; diff --git a/helix-tui/src/widgets/table.rs b/helix-tui/src/widgets/table.rs index a8f428a7..26860e5c 100644 --- a/helix-tui/src/widgets/table.rs +++ b/helix-tui/src/widgets/table.rs @@ -126,6 +126,14 @@ impl<'a> Row<'a> { fn total_height(&self) -> u16 { self.height.saturating_add(self.bottom_margin) } + + /// Returns the contents of cells as plain text, without styles and colors. + pub fn cell_text(&self) -> Vec { + self.cells + .iter() + .map(|cell| String::from(&cell.content)) + .collect() + } } /// A widget to display data in formatted columns. @@ -477,6 +485,9 @@ impl<'a> Table<'a> { }; let mut col = table_row_start_col; for (width, cell) in columns_widths.iter().zip(table_row.cells.iter()) { + if is_selected { + buf.set_style(table_row_area, self.highlight_style); + } render_cell( buf, cell, @@ -489,9 +500,6 @@ impl<'a> Table<'a> { ); col += *width + self.column_spacing; } - if is_selected { - buf.set_style(table_row_area, self.highlight_style); - } } } } -- cgit v1.2.3-70-g09d2