From 6e029cd013ce27fdea2922dbecc38a0aa380742b Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 21 Oct 2024 14:44:44 +0200 Subject: render keywords in entry info box --- src/frontend/ui.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/frontend/ui.rs b/src/frontend/ui.rs index 6fab1d1..45ccd60 100644 --- a/src/frontend/ui.rs +++ b/src/frontend/ui.rs @@ -15,6 +15,8 @@ // along with this program. If not, see . ///// +use color_eyre::owo_colors::OwoColorize; +use itertools::Itertools; use ratatui::{ buffer::Buffer, layout::{Alignment, Constraint, Layout, Rect}, @@ -33,6 +35,7 @@ use crate::frontend::{app::App, keywords::TagListItem}; use super::{ app::{CurrentArea, FormerArea}, entries::EntryTableColumn, + keywords, }; const MAIN_BLUE_COLOR: Color = Color::Indexed(39); @@ -452,6 +455,33 @@ impl App { Span::styled("Year: ", style_value), Span::styled(cur_entry.year(), Style::new().light_magenta()), ])); + // Render keywords in info box in Markdown code style + if !cur_entry.keywords.is_empty() { + let kw: Vec<&str> = cur_entry + .keywords + .split(",") + .map(|k| k.trim()) + .filter(|k| !k.is_empty()) + .collect(); + let mut content = vec![Span::styled("Keywords: ", style_value)]; + for k in kw { + // Add half block highlighted in bg color to enlarge block + content.push(Span::raw("▐").fg(HEADER_FOOTER_BG)); + content.push(Span::styled( + k, + Style::default().bg(HEADER_FOOTER_BG).fg( + // Highlight selected keyword green + if self.tag_list.selected_keywords.iter().any(|e| e == k) { + Color::Green + } else { + TEXT_FG_COLOR + }, + ), + )); + content.push(Span::raw("▌").fg(HEADER_FOOTER_BG)); + } + lines.push(Line::from(content)) + } if !cur_entry.doi_url.is_empty() || !cur_entry.filepath.is_empty() { lines.push(Line::raw("")); } -- cgit v1.2.3