diff options
| author | lukeflo | 2024-12-23 21:03:48 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:48 +0100 |
| commit | 57126d7f42b871aa1835b056fbe74179c13e53b0 (patch) | |
| tree | bf81db50446aa7a8e06553f4e8aff97ea0cfb816 /src/tui | |
| parent | ad5c2cb586616eca99fc1db0efaaa0ff5aa97144 (diff) | |
| parent | 9a33a794167d60ce35030f007674f6e9424b1ff3 (diff) | |
| download | bibiman-57126d7f42b871aa1835b056fbe74179c13e53b0.tar.gz bibiman-57126d7f42b871aa1835b056fbe74179c13e53b0.zip | |
Merge branch 'add-entry-via-doi'
+ implement the functionality to add an entry via DOI
+ responsive error messages if resolving of DOI don't work
+ keep changes to choosen file to minimum
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/commands.rs | 10 | ||||
| -rw-r--r-- | src/tui/popup.rs | 10 | ||||
| -rw-r--r-- | src/tui/ui.rs | 59 |
3 files changed, 68 insertions, 11 deletions
diff --git a/src/tui/commands.rs b/src/tui/commands.rs index a3049ee..0e00f95 100644 --- a/src/tui/commands.rs +++ b/src/tui/commands.rs @@ -69,6 +69,8 @@ pub enum CmdAction { Exit, // Show keybindings ShowHelp, + // Add new entry + AddEntry, // Do nothing. Nothing, } @@ -110,7 +112,6 @@ impl From<KeyEvent> for CmdAction { Self::SelectPrevRow(5) } else { Self::Nothing - // Self::Open(OpenRessource::WebLink) } } // Scroll info/preview area @@ -118,6 +119,8 @@ impl From<KeyEvent> for CmdAction { KeyCode::PageUp => Self::ScrollInfoUp, // Exit App KeyCode::Char('q') => Self::Exit, + // Add new entry + KeyCode::Char('a') => Self::AddEntry, KeyCode::Char('c') | KeyCode::Char('C') => { if key_event.modifiers == KeyModifiers::CONTROL { Self::Exit @@ -129,15 +132,14 @@ impl From<KeyEvent> for CmdAction { KeyCode::Tab => Self::ToggleArea, KeyCode::BackTab => Self::ToggleArea, // Enter search mode - KeyCode::Char('/') => Self::Input(InputCmdAction::Enter), + KeyCode::Char('/') => Self::SearchList, KeyCode::Char('f') => { if key_event.modifiers == KeyModifiers::CONTROL { - Self::Input(InputCmdAction::Enter) + Self::SearchList } else { Self::Nothing } } - // KeyCode::Backspace => Self::Input(InputCommand::Resume(Event::Key(key_event))), // Confirm selection KeyCode::Enter => Self::Confirm, // Reset lists/tables diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 890e5c8..78a0719 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -28,7 +28,9 @@ pub enum PopupKind { Help, MessageConfirm, MessageError, - Selection, + OpenRes, + AppendToFile, + AddEntry, } #[derive(Debug, Default)] @@ -39,6 +41,9 @@ pub struct PopupArea { pub popup_scroll_pos: u16, pub popup_list: Vec<String>, pub popup_state: ListState, + pub popup_sel_item: String, + // pub add_entry_input: String, + // pub add_entry_cursor_position: usize, } impl PopupArea { @@ -60,6 +65,7 @@ impl PopupArea { ("e: ", "Open editor at selected entry"), ("o: ", "Open with selected entry associated PDF"), ("u: ", "Open DOI/URL of selected entry"), + ("a: ", "Add new entry"), ("ESC: ", "Reset all lists"), ("Keyword List", "sub"), ("j,k|↓,↑: ", "Select next/previous item"), @@ -119,7 +125,7 @@ impl PopupArea { pub fn popup_selection(&mut self, items: Vec<String>) { self.popup_list = items; - self.popup_kind = Some(PopupKind::Selection); + // self.popup_kind = Some(PopupKind::SelectRes); self.is_popup = true; } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index cca87ce..4f64338 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -181,6 +181,46 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { frame.render_widget(Clear, popup_area); frame.render_widget(par, popup_area) } + + Some(PopupKind::AddEntry) => { + let area = frame.area(); + + let block = Block::bordered() + .title_top(" Add Entry ".bold()) + .title_bottom(" (ESC) ━ (ENTER) ".bold()) + .title_alignment(Alignment::Center) + .style( + Style::new() + .fg(Color::Indexed(args.colors.main_text_color)) + .bg(Color::Indexed(args.colors.popup_bg_color)), + ) + .border_set(symbols::border::THICK) + .border_style(Style::new().fg(Color::Indexed(args.colors.entry_color))); + + // Prepare the input fields + let content = vec![Line::from(vec![ + Span::styled( + "DOI: ", + Style::new().fg(Color::Indexed(args.colors.entry_color)), + ), + Span::raw(app.input.value().to_string().clone()), + ])]; + let paragraph = Paragraph::new(content) + .block(block.clone()) + .style(Style::new().fg(Color::Indexed(args.colors.main_text_color))) + .wrap(Wrap { trim: false }); + + let doi_lines = paragraph.line_count(area.width / 2); + // Calculate popup size + let popup_width = area.width / 4 * 3; + let popup_height = doi_lines as u16; // Adjust as needed + let popup_area = popup_area(area, popup_width, popup_height); + + // Render the popup + frame.render_widget(Clear, popup_area); + render_cursor(app, frame, popup_area, 6, doi_lines as u16 - 1); + frame.render_widget(paragraph, popup_area); + } Some(PopupKind::MessageConfirm) => { let area = frame.area(); @@ -243,7 +283,7 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { frame.render_widget(Clear, popup_area); frame.render_widget(&content, popup_area) } - Some(PopupKind::Selection) => { + Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { let list_items: Vec<ListItem> = app .bibiman .popup_area @@ -252,8 +292,16 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .map(|item| ListItem::from(item.to_owned())) .collect(); + let title = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind { + " Open " + } else if let Some(PopupKind::AppendToFile) = app.bibiman.popup_area.popup_kind { + " Select file to append entry " + } else { + " Select " + }; + let block = Block::bordered() - .title_top(" Open ".bold()) + .title_top(title.bold()) .title_bottom(" (j,k|↓,↑) ━ (ENTER) ━ (ESC) ".bold()) .title_alignment(Alignment::Center) .style( @@ -327,7 +375,7 @@ pub fn render_footer(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rec ])) .block(block); - render_cursor(app, frame, rect, title_lenght + 1); + render_cursor(app, frame, rect, title_lenght + 1, 1); frame.render_widget(search_string, rect); } @@ -986,12 +1034,13 @@ pub fn render_taglist(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Re } /// Render the cursor when in InputMode -fn render_cursor(app: &mut App, frame: &mut Frame, area: Rect, x_offset: u16) { +fn render_cursor(app: &mut App, frame: &mut Frame, area: Rect, x_offset: u16, y_offset: u16) { let scroll = app.input.visual_scroll(area.width as usize); if app.input_mode { let (x, y) = ( area.x + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + x_offset, - area.bottom().saturating_sub(1), + // area.bottom().saturating_sub(1) + y_offset, + area.bottom().saturating_sub(y_offset), ); frame.render_widget( Clear, |
