diff options
| author | lukeflo | 2025-06-30 16:33:01 +0200 |
|---|---|---|
| committer | lukeflo | 2025-06-30 16:33:01 +0200 |
| commit | 3a40bbb367a79dc3660c12aa7f62e3efc378ea22 (patch) | |
| tree | 3dfa3e13207b0bb134765d8a9288ff28b10e2a14 /src | |
| parent | 8ea28b55f0c6ba210ddcd6a964c8f56d3e6e25ff (diff) | |
| download | bibiman-3a40bbb367a79dc3660c12aa7f62e3efc378ea22.tar.gz bibiman-3a40bbb367a79dc3660c12aa7f62e3efc378ea22.zip | |
update README: note feature
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.rs | 2 | ||||
| -rw-r--r-- | src/bibiman.rs | 32 | ||||
| -rw-r--r-- | src/bibiman/entries.rs | 5 | ||||
| -rw-r--r-- | src/config.rs | 4 | ||||
| -rw-r--r-- | src/tui/ui.rs | 39 |
5 files changed, 53 insertions, 29 deletions
@@ -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