From fdfbf550144ef69ecc6003760fbb39466ec08637 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 29 Jun 2025 12:26:27 +0200 Subject: Some basic function rewriting for matching different file types --- src/config.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index f5f2dd0..6abcfd1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,6 +56,12 @@ const DEFAULT_CONFIG: &str = r##" ## Use absolute paths (~ for HOME works). Otherwise, loading might not work. # pdf_path = "/path/to/pdf/folder" +## Path to folder (with subfolders) containing note files with the basename of +## the format "citekey.extension". Other basenames are not accepted. The possible +## extensions can be set through the "note_extensions" array. +# note_path = "/path/to/notes/folder" +# note_extensions = [ "md", "txt", "org" ] + # [colors] ## Default values for dark-themed terminal ## Possible values are: @@ -90,6 +96,8 @@ pub struct General { pub url_opener: String, pub file_prefix: Option, pub pdf_path: Option, + pub note_path: Option, + pub note_extensions: Option>, } /// Substruct [colors] in config.toml @@ -117,6 +125,8 @@ impl Default for BibiConfig { url_opener: select_opener(), file_prefix: None, pdf_path: None, + note_path: None, + note_extensions: None, }, colors: Self::dark_colors(), } @@ -133,6 +143,8 @@ impl BibiConfig { url_opener: select_opener(), file_prefix: None, pdf_path: None, + note_path: None, + note_extensions: None, }, colors: if args.light_theme { Self::light_colors() -- cgit v1.2.3 From 4ca8417812db530cd157fe5b1de70f6e74e9c400 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 12:54:01 +0200 Subject: UI implementation of notes --- src/bibiman/bibisetup.rs | 1 + src/config.rs | 18 ++++++++++++++++++ src/tui/ui.rs | 28 +++++++++++++++++++--------- 3 files changed, 38 insertions(+), 9 deletions(-) (limited to 'src/config.rs') diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index e79960c..61144a1 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -76,6 +76,7 @@ impl BibiData { }; vec![ + "", { if self.short_author.is_empty() { self.authors() diff --git a/src/config.rs b/src/config.rs index 6abcfd1..c30d8d1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -113,6 +113,12 @@ pub struct Colors { pub bar_bg_color: Color, pub popup_bg_color: Color, pub selected_row_bg_color: Color, + pub note_color: Color, + pub file_color: Color, + pub link_color: Color, + pub author_color: Color, + pub title_color: Color, + pub year_color: Color, } impl Default for BibiConfig { @@ -187,6 +193,12 @@ impl BibiConfig { bar_bg_color: Color::Indexed(235), popup_bg_color: Color::Indexed(234), selected_row_bg_color: Color::Indexed(237), + note_color: Color::Indexed(123), + file_color: Color::Indexed(209), + link_color: Color::Indexed(33), + author_color: Color::Indexed(38), + title_color: Color::Indexed(37), + year_color: Color::Indexed(135), } } @@ -203,6 +215,12 @@ impl BibiConfig { confirm_color: Color::Indexed(22), warn_color: Color::Indexed(124), selected_row_bg_color: Color::Indexed(107), + note_color: Color::Indexed(123), + file_color: Color::Indexed(209), + link_color: Color::Indexed(27), + author_color: Color::Indexed(38), + title_color: Color::Indexed(37), + year_color: Color::Indexed(135), } } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index ebebe4c..95b9f2c 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -580,6 +580,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .bg(cfg.colors.bar_bg_color); let header = Row::new(vec![ + Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), Cell::from( Line::from(vec![{ Span::raw("Author") }, { if let Some(EntryTableColumn::Authors) = @@ -725,6 +726,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec let entry_table = Table::new( rows, [ + Constraint::Length(4), Constraint::Percentage(20), Constraint::Fill(1), Constraint::Length( @@ -793,7 +795,10 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, lines.push(Line::from(vec![ Span::styled("Authors: ", style_value), // Span::styled(cur_entry.authors.clone(), Style::new().green()), - Span::styled(cur_entry.authors(), Style::new().fg(cfg.colors.info_color)), + Span::styled( + cur_entry.authors(), + Style::new().fg(cfg.colors.author_color), + ), ])); if cur_entry.subtitle.is_some() { lines.push(Line::from(vec![ @@ -801,19 +806,19 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, Span::styled( cur_entry.title(), Style::new() - .fg(cfg.colors.entry_color) + .fg(cfg.colors.title_color) .add_modifier(Modifier::ITALIC), ), Span::styled( ": ", Style::new() - .fg(cfg.colors.entry_color) + .fg(cfg.colors.title_color) .add_modifier(Modifier::ITALIC), ), Span::styled( cur_entry.subtitle(), Style::new() - .fg(cfg.colors.entry_color) + .fg(cfg.colors.title_color) .add_modifier(Modifier::ITALIC), ), ])); @@ -823,14 +828,14 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, Span::styled( cur_entry.title(), Style::new() - .fg(cfg.colors.entry_color) + .fg(cfg.colors.title_color) .add_modifier(Modifier::ITALIC), ), ])); } lines.push(Line::from(vec![ Span::styled("Year: ", style_value), - Span::styled(cur_entry.year(), Style::new().fg(cfg.colors.keyword_color)), + Span::styled(cur_entry.year(), Style::new().fg(cfg.colors.year_color)), ])); // Render keywords in info box in Markdown code style if !cur_entry.keywords.is_empty() { @@ -873,7 +878,7 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, Span::styled("DOI/URL: ", style_value), Span::styled( cur_entry.doi_url(), - Style::new().fg(cfg.colors.main_text_color).underlined(), + Style::new().fg(cfg.colors.link_color).underlined(), ), ])); } @@ -882,7 +887,7 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, Span::styled("File: ", style_value), Span::styled( p.iter().map(|f| f.to_str().unwrap()).join("; "), - Style::new().fg(cfg.colors.main_text_color), + Style::new().fg(cfg.colors.file_color), ), ])); } @@ -913,7 +918,12 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, // We show the list item's info under the list in this paragraph let block = Block::bordered() - .title(Line::raw(" Entry Information ").centered().bold()) + .title( + Line::raw(" Entry Information ") + .centered() + .bold() + .fg(cfg.colors.info_color), + ) .border_set(symbols::border::PLAIN) .border_style(Style::new().fg(cfg.colors.main_text_color)) .padding(Padding::horizontal(1)); -- cgit v1.2.3 From 1b79ba0fb9f4a1d96c0de1fbf6ab42d8e1b0873c Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 14:59:39 +0200 Subject: colored symbols for attachements, basic implementation --- src/bibiman/bibisetup.rs | 67 ++++++++++++++++++++++++++++++++++++++++-------- src/config.rs | 9 +++++++ src/tui/ui.rs | 63 +++++++++++++++++++++++++++------------------ 3 files changed, 104 insertions(+), 35 deletions(-) (limited to 'src/config.rs') diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index 61144a1..61d1fcf 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -56,12 +56,22 @@ pub struct BibiData { pub file_field: bool, pub subtitle: Option, pub notes: Option>, + pub symbols: [String; 3], +} + +#[derive(Debug, Clone, PartialEq)] +pub struct BibiRow { + pub authors: String, + pub title: String, + pub year: String, + pub pubtype: String, + pub symbols: [String; 3], } impl BibiData { // This functions decides which fields are rendered in the entry table // Fields which should be usable but not visible can be left out - pub fn ref_vec(&mut self) -> Vec<&str> { + pub fn ref_vec(&mut self, cfg: &BibiConfig) -> BibiRow { self.short_author = match self.authors.split_once(",") { Some((first, _rest)) => { if self.authors().contains("(ed.)") { @@ -75,19 +85,35 @@ impl BibiData { None => String::from(""), }; - vec![ - "", - { + self.symbols = self.create_symbols(cfg); + + // vec![ + // { + // if self.short_author.is_empty() { + // self.authors() + // } else { + // &self.short_author + // } + // }, + // self.title(), + // self.year(), + // self.pubtype(), + // &self.symbols, + // ] + + BibiRow { + authors: { if self.short_author.is_empty() { - self.authors() + self.authors().to_string() } else { - &self.short_author + self.short_author.clone() } }, - self.title(), - self.year(), - self.pubtype(), - ] + title: self.title().to_string(), + year: self.year().to_string(), + pubtype: self.pubtype().to_string(), + symbols: self.symbols.clone(), + } } pub fn entry_id(&self) -> &u32 { @@ -133,6 +159,26 @@ impl BibiData { pub fn subtitle(&self) -> &str { self.subtitle.as_ref().unwrap() } + + fn create_symbols(&self, cfg: &BibiConfig) -> [String; 3] { + [ + if self.file_field || self.filepath.is_some() { + cfg.general.file_symbol.clone() + } else { + " ".to_string() + }, + if self.doi_url.is_some() { + cfg.general.link_symbol.clone() + } else { + " ".to_string() + }, + if self.notes.is_some() { + cfg.general.note_symbol.clone() + } else { + " ".to_string() + }, + ] + } } impl BibiSetup { @@ -248,6 +294,7 @@ impl BibiSetup { } else { None }, + symbols: [String::new(), String::new(), String::new()], } }) .collect() diff --git a/src/config.rs b/src/config.rs index c30d8d1..6723ce0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -98,6 +98,9 @@ pub struct General { pub pdf_path: Option, pub note_path: Option, pub note_extensions: Option>, + pub note_symbol: String, + pub file_symbol: String, + pub link_symbol: String, } /// Substruct [colors] in config.toml @@ -133,6 +136,9 @@ impl Default for BibiConfig { pdf_path: None, note_path: None, note_extensions: None, + note_symbol: String::from("N"), + file_symbol: String::from("F"), + link_symbol: String::from("L"), }, colors: Self::dark_colors(), } @@ -151,6 +157,9 @@ impl BibiConfig { pdf_path: None, note_path: None, note_extensions: None, + note_symbol: String::from("N"), + file_symbol: String::from("F"), + link_symbol: String::from("L"), }, colors: if args.light_theme { Self::light_colors() diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 95b9f2c..970a71d 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -580,7 +580,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .bg(cfg.colors.bar_bg_color); let header = Row::new(vec![ - Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), + // Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), Cell::from( Line::from(vec![{ Span::raw("Author") }, { if let Some(EntryTableColumn::Authors) = @@ -699,34 +699,46 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .iter_mut() .enumerate() .map(|(_i, data)| { - let item = data.ref_vec(); - item.into_iter() - .map(|content| Cell::from(Text::from(content.to_string()))) - .collect::() - .style( - // Style::new().fg(color_list( - // args, - // i as i32, - // app.bibiman - // .entry_table - // .entry_table_state - // .selected() - // .unwrap_or(0) as i32, - // args.colors.highlight_text_color, - // 20, - // )), - Style::new().fg(if let CurrentArea::EntryArea = app.bibiman.current_area { - cfg.colors.highlight_text_color - } else { - cfg.colors.main_text_color - }), - ) - .height(1) + let item = data.ref_vec(cfg); + + let row = Row::new(vec![ + Cell::from(Line::from(item.authors)), + Cell::from(Line::from(item.title)), + Cell::from(Line::from(item.year)), + Cell::from(Line::from(item.pubtype)), + Cell::from(Line::from(vec![ + Span::styled( + item.symbols[0].clone(), + Style::new().fg(cfg.colors.file_color), + ), + Span::styled( + item.symbols[1].clone(), + Style::new().fg(cfg.colors.link_color), + ), + Span::styled( + item.symbols[2].clone(), + Style::new().fg(cfg.colors.note_color), + ), + ])), + ]); + + // let row = item + // .into_iter() + // .map(|content| Cell::from(Text::from(content.to_string()))) + // .collect::(); + + row.style( + Style::new().fg(if let CurrentArea::EntryArea = app.bibiman.current_area { + cfg.colors.highlight_text_color + } else { + cfg.colors.main_text_color + }), + ) + .height(1) }); let entry_table = Table::new( rows, [ - Constraint::Length(4), Constraint::Percentage(20), Constraint::Fill(1), Constraint::Length( @@ -739,6 +751,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec }, ), Constraint::Percentage(10), + Constraint::Length(4), ], ) .block(block) -- cgit v1.2.3 From 614a20a12138f6691f8472b8c8657cf62b6730fb Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 15:45:14 +0200 Subject: implemented symbols for attachements --- src/bibiman/bibisetup.rs | 42 +++++++++++++++++------------------ src/config.rs | 11 +++++++++ src/tui/ui.rs | 34 +++++++++++++++------------- tests/note-files/aristotle_physics.md | 0 tests/test-config.toml | 11 +++++++++ 5 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 tests/note-files/aristotle_physics.md (limited to 'src/config.rs') diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index 61d1fcf..1f8a912 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -56,16 +56,16 @@ pub struct BibiData { pub file_field: bool, pub subtitle: Option, pub notes: Option>, - pub symbols: [String; 3], + pub symbols: [Option; 3], } #[derive(Debug, Clone, PartialEq)] -pub struct BibiRow { - pub authors: String, - pub title: String, - pub year: String, - pub pubtype: String, - pub symbols: [String; 3], +pub struct BibiRow<'a> { + pub authors: &'a str, + pub title: &'a str, + pub year: &'a str, + pub pubtype: &'a str, + pub symbols: &'a [Option; 3], } impl BibiData { @@ -104,15 +104,15 @@ impl BibiData { BibiRow { authors: { if self.short_author.is_empty() { - self.authors().to_string() + self.authors() } else { - self.short_author.clone() + &self.short_author } }, - title: self.title().to_string(), - year: self.year().to_string(), - pubtype: self.pubtype().to_string(), - symbols: self.symbols.clone(), + title: self.title(), + year: self.year(), + pubtype: self.pubtype(), + symbols: &self.symbols, } } @@ -160,22 +160,22 @@ impl BibiData { self.subtitle.as_ref().unwrap() } - fn create_symbols(&self, cfg: &BibiConfig) -> [String; 3] { + fn create_symbols(&self, cfg: &BibiConfig) -> [Option; 3] { [ if self.file_field || self.filepath.is_some() { - cfg.general.file_symbol.clone() + Some(cfg.general.file_symbol.clone()) } else { - " ".to_string() + None }, if self.doi_url.is_some() { - cfg.general.link_symbol.clone() + Some(cfg.general.link_symbol.clone()) } else { - " ".to_string() + None }, if self.notes.is_some() { - cfg.general.note_symbol.clone() + Some(cfg.general.note_symbol.clone()) } else { - " ".to_string() + None }, ] } @@ -294,7 +294,7 @@ impl BibiSetup { } else { None }, - symbols: [String::new(), String::new(), String::new()], + symbols: [None, None, None], } }) .collect() diff --git a/src/config.rs b/src/config.rs index 6723ce0..f67cb9d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -62,6 +62,11 @@ const DEFAULT_CONFIG: &str = r##" # note_path = "/path/to/notes/folder" # note_extensions = [ "md", "txt", "org" ] +## Symbols/chars to show if not has specific attachement +# note_symbol = "N" +# file_symbol = "F" +# link_symbol = "L" + # [colors] ## Default values for dark-themed terminal ## Possible values are: @@ -78,6 +83,12 @@ const DEFAULT_CONFIG: &str = r##" # bar_bg_color = "234" # popup_bg_color = "234" # selected_row_bg_color = "237" +# note_color = "123" +# file_color = "209" +# link_color = "27" +# author_color = "38" +# title_color = "37" +# year_color = "135" "##; /// Main struct of the config file. Contains substructs/headings in toml diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 970a71d..5904f88 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -701,25 +701,24 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .map(|(_i, data)| { let item = data.ref_vec(cfg); + let mut symbol_vec = vec![]; + + if let Some(f) = &item.symbols[0] { + symbol_vec.push(Span::styled(f, Style::new().fg(cfg.colors.file_color))); + } + if let Some(l) = &item.symbols[1] { + symbol_vec.push(Span::styled(l, Style::new().fg(cfg.colors.link_color))); + } + if let Some(n) = &item.symbols[2] { + symbol_vec.push(Span::styled(n, Style::new().fg(cfg.colors.note_color))) + } + let row = Row::new(vec![ Cell::from(Line::from(item.authors)), Cell::from(Line::from(item.title)), Cell::from(Line::from(item.year)), Cell::from(Line::from(item.pubtype)), - Cell::from(Line::from(vec![ - Span::styled( - item.symbols[0].clone(), - Style::new().fg(cfg.colors.file_color), - ), - Span::styled( - item.symbols[1].clone(), - Style::new().fg(cfg.colors.link_color), - ), - Span::styled( - item.symbols[2].clone(), - Style::new().fg(cfg.colors.note_color), - ), - ])), + Cell::from(Line::from(symbol_vec)), ]); // let row = item @@ -751,7 +750,12 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec }, ), Constraint::Percentage(10), - Constraint::Length(4), + Constraint::Length( + (cfg.general.file_symbol.chars().count() + + cfg.general.link_symbol.chars().count() + + cfg.general.note_symbol.chars().count() + + 1) as u16, + ), ], ) .block(block) diff --git a/tests/note-files/aristotle_physics.md b/tests/note-files/aristotle_physics.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-config.toml b/tests/test-config.toml index 99d1d00..51bd4e6 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -27,6 +27,11 @@ pdf_path = "tests/pdf-files" note_path = "tests/note-files" note_extensions = [ "md", "txt" ] +## Symbols/chars to show if not has specific attachement + file_symbol = " " + link_symbol = "󰌹 " + note_symbol = "󰧮" + # [colors] ## Default values for dark-themed terminal ## Possible values are: @@ -43,3 +48,9 @@ note_extensions = [ "md", "txt" ] # bar_bg_color = "234" # popup_bg_color = "234" # selected_row_bg_color = "237" +# note_color = "123" +# file_color = "209" +# link_color = "27" +# author_color = "38" +# title_color = "37" +# year_color = "135" -- cgit v1.2.3 From 3a40bbb367a79dc3660c12aa7f62e3efc378ea22 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 16:33:01 +0200 Subject: update README: note feature --- README.md | 33 +++++++++++++++++++++++++-------- src/app.rs | 2 +- src/bibiman.rs | 32 ++++++++++++++++++++++++++++---- src/bibiman/entries.rs | 5 +++-- src/config.rs | 4 ++-- src/tui/ui.rs | 39 +++++++++++++++++++-------------------- 6 files changed, 78 insertions(+), 37 deletions(-) (limited to 'src/config.rs') diff --git a/README.md b/README.md index 5bc40b3..4f0e505 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,16 @@ file_prefix = "/some/path/prefix" # of the format "citekey.pdf". Other PDF basenames are not accepted. # Use absolute paths (~ for HOME works). Otherwise, loading might not work. pdf_path = "/path/to/pdf-folder" +## Path to folder (with subfolders) containing note files with the basename of +## the format "citekey.extension". Other basenames are not accepted. The possible +## extensions can be set through the "note_extensions" array. +note_path = "path/to/note-files" +note_extensions = [ "md", "txt" ] + +## Symbols/chars to show if not has specific attachement + file_symbol = " " + link_symbol = "󰌹 " + note_symbol = "󰧮" ``` `bibfiles` @@ -246,13 +256,14 @@ pdf_path = "/path/to/pdf-folder" created through the `pdf_path` variable. Thus, it is safe to mix both approaches if wanted! -`pdf_path` +`pdf_path` and `note_path` -: The `pdf_path` is used as path wich is recursivley searched for files which - basename consists of the an entrys `citekey` plus a `.pdf` ending - (case-insensitive). Every file which matches this pattern for an existing - `citekey` is associated with the particular entry for the current `bibiman` - session and can be opened from within. +: The `pdf_path`/`note_path` is used as path wich is recursivley searched for + files which basename consists of the an entrys `citekey` plus a `.pdf` ending + or one of the specified note endinfs (case-insensitive). Every file which + matches this pattern for an existing `citekey` is associated with the + particular entry for the current `bibiman` session and can be opened from + within. ### Color Configuration @@ -272,6 +283,12 @@ warn_color = "124" bar_bg_color = "234" popup_bg_color = "234" selected_row_bg_color = "237" +note_color = "123" +file_color = "209" +link_color = "27" +author_color = "38" +title_color = "37" +year_color = "135" ``` Colors can be set through three different methods: @@ -309,7 +326,7 @@ These are the current features, the list will be updated: - [x] **Add Entry via DOI**. - [x] **Implement config file** for setting some default values like main bibfile, PDF-opener, or editor -- [ ] **Open related notes file** for specific entry. +- [x] **Open related notes file** for specific entry. - [ ] **Support Hayagriva(`.yaml`)** format as input (_on hold for now_, because the Hayagriva Yaml style doesn't offer keywords; s. issue in [Hayagriva repo](https://github.com/typst/hayagriva/issues/240)). @@ -346,7 +363,7 @@ Use the following keybindings to manage the TUI: There are some shortcuts to select an item from the opening/yanking popup without navigating the list: -- `o-o`|`o-l`: directly opens the first file/link for the selected entry. +- `o-o`|`o-l`|`o-n`: directly opens the first file|link|note for the selected entry. - `y-y`: directly yanks the citekey of the selected entry to the clipboard. ## Search diff --git a/src/app.rs b/src/app.rs index 496896a..18a97e6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -83,7 +83,7 @@ impl App { } else if let Some(PopupKind::YankItem) | Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind { - self.bibiman.fast_selection(cfg, key_event.code)?; + self.bibiman.fast_selection(cfg, &mut tui, key_event.code)?; } let command = if self.input_mode { CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) diff --git a/src/bibiman.rs b/src/bibiman.rs index e1e97ed..9cc9280 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -367,9 +367,9 @@ impl Bibiman { .entry_table_state .selected_column() .unwrap() - == 3 + == 4 { - self.entry_table.entry_table_state.select_first_column(); + self.entry_table.entry_table_state.select_column(Some(1)); } else { self.entry_table.entry_table_state.select_next_column(); } @@ -396,7 +396,7 @@ impl Bibiman { .entry_table_state .selected_column() .unwrap() - == 0 + == 1 { self.entry_table.entry_table_state.select_last_column(); } else { @@ -788,11 +788,17 @@ impl Bibiman { /// /// `o` -> opens the first file of the `filepath` `Vec` for the current entry /// `l` -> opens the link of the current entry + /// `n` -> opens the first note /// /// **Yanking popup** /// /// `y` -> yanks the citekey for the current entry - pub fn fast_selection(&mut self, cfg: &BibiConfig, key_code: KeyCode) -> Result<()> { + pub fn fast_selection( + &mut self, + cfg: &BibiConfig, + tui: &mut Tui, + key_code: KeyCode, + ) -> Result<()> { if let CurrentArea::PopupArea = self.current_area { let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); match self.popup_area.popup_kind { @@ -817,6 +823,24 @@ impl Bibiman { } } } + KeyCode::Char('n') => { + let file = self.entry_table.entry_table_items[entry_idx].notes.clone(); + if file.is_some() { + let file = expand_home(&PathBuf::from(file.unwrap()[0].clone())); + // let object: OsString = popup_entry.into(); + if file.is_file() { + self.open_connected_note(cfg, tui, &file.into_os_string())?; + self.close_popup(); + } else { + self.open_popup( + PopupKind::MessageError, + Some("No valid file path: "), + Some(file.to_str().unwrap()), + None, + )?; + } + } + } KeyCode::Char('l') => { if self.entry_table.entry_table_items[entry_idx] .doi_url diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs index e0c230b..9b536fd 100644 --- a/src/bibiman/entries.rs +++ b/src/bibiman/entries.rs @@ -47,8 +47,9 @@ impl EntryTable { // entry_table let entry_table_state = TableState::default() .with_selected(0) - .with_selected_column(0) - .with_selected_cell(Some((0, 0))); + .with_selected_column(1) + // other two values above are ignored, if selected cell isn't fitting + .with_selected_cell(Some((0, 1))); let entry_scroll_state = ScrollbarState::new(entry_table_items.len()); let entry_info_scroll_state = ScrollbarState::default(); Self { diff --git a/src/config.rs b/src/config.rs index f67cb9d..278f4b1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -85,7 +85,7 @@ const DEFAULT_CONFIG: &str = r##" # selected_row_bg_color = "237" # note_color = "123" # file_color = "209" -# link_color = "27" +# link_color = "39" # author_color = "38" # title_color = "37" # year_color = "135" @@ -215,7 +215,7 @@ impl BibiConfig { selected_row_bg_color: Color::Indexed(237), note_color: Color::Indexed(123), file_color: Color::Indexed(209), - link_color: Color::Indexed(33), + link_color: Color::Indexed(39), author_color: Color::Indexed(38), title_color: Color::Indexed(37), year_color: Color::Indexed(135), diff --git a/src/tui/ui.rs b/src/tui/ui.rs index ac44d09..3c83935 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -580,7 +580,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .bg(cfg.colors.bar_bg_color); let header = Row::new(vec![ - // Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), + Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), Cell::from( Line::from(vec![{ Span::raw("Author") }, { if let Some(EntryTableColumn::Authors) = @@ -704,21 +704,30 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec let mut symbol_vec = vec![]; if let Some(f) = &item.symbols[0] { - symbol_vec.push(Span::styled(f, Style::new().fg(cfg.colors.file_color))); + symbol_vec.push(Span::styled( + f, + Style::new().fg(cfg.colors.file_color).bold(), + )); } if let Some(l) = &item.symbols[1] { - symbol_vec.push(Span::styled(l, Style::new().fg(cfg.colors.link_color))); + symbol_vec.push(Span::styled( + l, + Style::new().fg(cfg.colors.link_color).bold(), + )); } if let Some(n) = &item.symbols[2] { - symbol_vec.push(Span::styled(n, Style::new().fg(cfg.colors.note_color))) + symbol_vec.push(Span::styled( + n, + Style::new().fg(cfg.colors.note_color).bold(), + )) } let row = Row::new(vec![ + Cell::from(Line::from(symbol_vec)), Cell::from(Line::from(item.authors)), Cell::from(Line::from(item.title)), Cell::from(Line::from(item.year)), Cell::from(Line::from(item.pubtype)), - Cell::from(Line::from(symbol_vec)), ]); // let row = item @@ -738,6 +747,11 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec let entry_table = Table::new( rows, [ + Constraint::Length( + (cfg.general.file_symbol.chars().count() + + cfg.general.link_symbol.chars().count() + + cfg.general.note_symbol.chars().count()) as u16, + ), Constraint::Percentage(20), Constraint::Fill(1), Constraint::Length( @@ -750,12 +764,6 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec }, ), Constraint::Percentage(10), - Constraint::Length( - (cfg.general.file_symbol.chars().count() - + cfg.general.link_symbol.chars().count() - + cfg.general.note_symbol.chars().count() - + 1) as u16, - ), ], ) .block(block) @@ -917,15 +925,6 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, ), ])); } - // if cur_entry.filepath.is_some() { - // lines.push(Line::from(vec![ - // Span::styled("File: ", style_value), - // Span::styled( - // cur_entry.filepath().to_string_lossy(), - // Style::new().fg(cfg.colors.main_text_color), - // ), - // ])); - // } lines.push(Line::from("")); lines.push(Line::from(vec![Span::styled( cur_entry.abstract_text.clone(), -- cgit v1.2.3 From 5ebecf2ea9d0fb9c57b264d7cd1c6e92b36d30e8 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Fri, 4 Jul 2025 14:41:47 +0200 Subject: `PopupItem::Citekey` impl --- src/app.rs | 8 ++++---- src/config.rs | 4 ++++ src/tui/popup.rs | 1 + src/tui/ui.rs | 28 ++++++++++++++++------------ 4 files changed, 25 insertions(+), 16 deletions(-) (limited to 'src/config.rs') diff --git a/src/app.rs b/src/app.rs index d645dbe..d475328 100644 --- a/src/app.rs +++ b/src/app.rs @@ -314,7 +314,7 @@ impl App { let mut items = vec![( "Citekey: ".to_string(), entry.citekey.clone(), - PopupItem::Default, + PopupItem::Citekey, )]; if entry.doi_url.is_some() { items.push(( @@ -365,7 +365,7 @@ impl App { { if entry.doi_url.is_some() { items.push(( - "Weblink (DOI/URL): ".into(), + format!("{} ", cfg.general.link_symbol.clone().trim()), entry.doi_url.unwrap().clone(), PopupItem::Link, )) @@ -373,7 +373,7 @@ impl App { if entry.filepath.is_some() { entry.filepath.unwrap().iter().for_each(|p| { items.push(( - "File (PDF/EPUB): ".into(), + format!("{} ", cfg.general.file_symbol.clone().trim()), // p.clone().into_string().unwrap(), if entry.file_field && cfg.general.file_prefix.is_some() { cfg.general @@ -394,7 +394,7 @@ impl App { if entry.notes.is_some() { entry.notes.unwrap().iter().for_each(|n| { items.push(( - "Note: ".into(), + format!("{} ", cfg.general.note_symbol.clone().trim()), n.clone().into_string().unwrap(), PopupItem::Notefile, )); diff --git a/src/config.rs b/src/config.rs index 278f4b1..1f6c619 100644 --- a/src/config.rs +++ b/src/config.rs @@ -81,6 +81,7 @@ const DEFAULT_CONFIG: &str = r##" # confirm_color = "47" # warn_color = "124" # bar_bg_color = "234" +# popup_fg_color = "43" # popup_bg_color = "234" # selected_row_bg_color = "237" # note_color = "123" @@ -125,6 +126,7 @@ pub struct Colors { pub confirm_color: Color, pub warn_color: Color, pub bar_bg_color: Color, + pub popup_fg_color: Color, pub popup_bg_color: Color, pub selected_row_bg_color: Color, pub note_color: Color, @@ -211,6 +213,7 @@ impl BibiConfig { confirm_color: Color::Indexed(47), warn_color: Color::Indexed(124), bar_bg_color: Color::Indexed(235), + popup_fg_color: Color::Indexed(43), popup_bg_color: Color::Indexed(234), selected_row_bg_color: Color::Indexed(237), note_color: Color::Indexed(123), @@ -231,6 +234,7 @@ impl BibiConfig { keyword_color: Color::Indexed(58), info_color: Color::Indexed(57), bar_bg_color: Color::Indexed(144), + popup_fg_color: Color::Indexed(43), popup_bg_color: Color::Indexed(187), confirm_color: Color::Indexed(22), warn_color: Color::Indexed(124), diff --git a/src/tui/popup.rs b/src/tui/popup.rs index da44744..4aaa2c1 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -45,6 +45,7 @@ pub enum PopupItem { Bibfile, Entryfile, Notefile, + Citekey, Link, Default, None, diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 2c30154..0a34e51 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -281,18 +281,22 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { .iter() .map( |(mes, obj, i)| { - let style = match i { - PopupItem::Bibfile => Style::new().fg(cfg.colors.entry_color), - PopupItem::Entryfile => Style::new().fg(cfg.colors.file_color), - PopupItem::Notefile => Style::new().fg(cfg.colors.note_color), - PopupItem::Link => Style::new().fg(cfg.colors.link_color), - PopupItem::Default => Style::new(), - PopupItem::None => Style::new(), + let style: Color = match i { + PopupItem::Bibfile => cfg.colors.entry_color, + PopupItem::Citekey => cfg.colors.entry_color, + PopupItem::Entryfile => cfg.colors.file_color, + PopupItem::Notefile => cfg.colors.note_color, + PopupItem::Link => cfg.colors.link_color, + PopupItem::Default => cfg.colors.main_text_color, + PopupItem::None => cfg.colors.main_text_color, }; - ListItem::from(Line::from(vec![ - Span::styled(mes, style.bold()), - Span::raw(obj), - ])) + ListItem::from( + Line::from(vec![ + Span::styled(mes, Style::new().bold()), + Span::raw(obj), + ]) + .fg(style), + ) }, // ListItem::from(mes.to_owned() + obj) ) .collect(); @@ -325,7 +329,7 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { .bg(cfg.colors.popup_bg_color), ) .border_set(symbols::border::THICK) - .border_style(Style::new().fg(cfg.colors.keyword_color)); + .border_style(Style::new().fg(cfg.colors.popup_fg_color)); let list = List::new(list_items).block(block).highlight_style( Style::new() -- cgit v1.2.3