diff options
| author | lukeflo | 2024-12-16 13:46:24 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:19 +0100 |
| commit | bf93bbee1b59c9804a01a7476e12264bbbcf5f40 (patch) | |
| tree | e8b1454a9c85e6932b443a34a4a18a02b71bfccc /src/tui | |
| parent | a6fca1fcf164142d84d09242b9d95a1da0b2d2d9 (diff) | |
| download | bibiman-bf93bbee1b59c9804a01a7476e12264bbbcf5f40.tar.gz bibiman-bf93bbee1b59c9804a01a7476e12264bbbcf5f40.zip | |
rewrite add-entry via DOI workflow
+ split some functions to fit with different popups
+ select if append to file (and to which) or create new file
+ error handling if resolving doi ist not possible
+ error handling for wront doi patterns
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/commands.rs | 10 | ||||
| -rw-r--r-- | src/tui/popup.rs | 8 | ||||
| -rw-r--r-- | src/tui/ui.rs | 27 |
3 files changed, 17 insertions, 28 deletions
diff --git a/src/tui/commands.rs b/src/tui/commands.rs index f7fd75b..0e00f95 100644 --- a/src/tui/commands.rs +++ b/src/tui/commands.rs @@ -112,7 +112,6 @@ impl From<KeyEvent> for CmdAction { Self::SelectPrevRow(5) } else { Self::Nothing - // Self::Open(OpenRessource::WebLink) } } // Scroll info/preview area @@ -132,15 +131,6 @@ impl From<KeyEvent> for CmdAction { // Switch selected area KeyCode::Tab => Self::ToggleArea, KeyCode::BackTab => Self::ToggleArea, - // // Enter search mode - // KeyCode::Char('/') => Self::Input(InputCmdAction::Enter), - // KeyCode::Char('f') => { - // if key_event.modifiers == KeyModifiers::CONTROL { - // Self::Input(InputCmdAction::Enter) - // } else { - // Self::Nothing - // } - // } // Enter search mode KeyCode::Char('/') => Self::SearchList, KeyCode::Char('f') => { diff --git a/src/tui/popup.rs b/src/tui/popup.rs index afe0cfc..352b328 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -28,7 +28,8 @@ pub enum PopupKind { Help, MessageConfirm, MessageError, - Selection, + SelectRes, + SelectFile, AddEntry, } @@ -40,6 +41,7 @@ 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, } @@ -51,7 +53,6 @@ impl PopupArea { ("TAB: ", "Toggle areas (Entries, Keywords)"), ("/|Ctrl+f: ", "Enter search mode"), ("q|Ctrl+c: ", "Quit bibiman"), - ("a: ", "Add new entry"), ("?: ", "Show help"), ("Entry Table", "sub"), ("j,k|↓,↑: ", "Select next/previous entry"), @@ -64,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"), @@ -123,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 e3fddfd..6a3b8de 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -212,25 +212,14 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { let doi_lines = paragraph.line_count(area.width / 2); // Calculate popup size - let popup_width = area.width / 2; + 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, 2); + render_cursor(app, frame, popup_area, 6, doi_lines as u16 - 1); frame.render_widget(paragraph, popup_area); - - // // Set the cursor position - // if app.input_mode { - // // Calculate cursor x and y - // let input_prefix_len = "Title: ".len() as u16 + 1; // +1 for padding - // let cursor_x = popup_area.x - // + input_prefix_len - // + app.bibiman.popup_area.add_entry_cursor_position as u16; - // let cursor_y = popup_area.y + 1; // Line after 'Title: ' - // frame.set_cursor_position(Position::new(cursor_x, cursor_y)); - // } } Some(PopupKind::MessageConfirm) => { let area = frame.area(); @@ -294,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::SelectRes) | Some(PopupKind::SelectFile) => { let list_items: Vec<ListItem> = app .bibiman .popup_area @@ -303,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::SelectRes) = app.bibiman.popup_area.popup_kind { + " Open " + } else if let Some(PopupKind::SelectFile) = 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( |
