diff options
| author | Trim Bresilla | 2024-12-03 01:45:29 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:19 +0100 |
| commit | 86d48aa48b9951b6cbc471113844d16683051f8f (patch) | |
| tree | 91a1af8050312f5646170da00fab6972903fce12 /src/tui | |
| parent | eadd906fc25125a61811247262836b9afe8adee1 (diff) | |
| download | bibiman-86d48aa48b9951b6cbc471113844d16683051f8f.tar.gz bibiman-86d48aa48b9951b6cbc471113844d16683051f8f.zip | |
feat: implement entry management in Bibiman TUI
- Add `.devbox` to the `.gitignore` file
- Create a new backup file `devbox.json.back` with package and shell initialization configurations
- Introduce a new method `add_entry` in the Bibiman struct to manage adding entries
- Implement functionality to handle new entry submissions using `doi2bib`
- Update command actions to include `AddEntry`
- Add `AddEntry` as a new popup type in the TUI for creating entries
- Enhance the UI rendering to support the new entry popup with input fields and cursor positioning
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/commands.rs | 4 | ||||
| -rw-r--r-- | src/tui/popup.rs | 4 | ||||
| -rw-r--r-- | src/tui/ui.rs | 49 |
3 files changed, 57 insertions, 0 deletions
diff --git a/src/tui/commands.rs b/src/tui/commands.rs index a3049ee..626b11b 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, } @@ -118,6 +120,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 diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 890e5c8..9b91801 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -29,6 +29,7 @@ pub enum PopupKind { MessageConfirm, MessageError, Selection, + AddEntry, } #[derive(Debug, Default)] @@ -39,6 +40,8 @@ pub struct PopupArea { pub popup_scroll_pos: u16, pub popup_list: Vec<String>, pub popup_state: ListState, + pub add_entry_input: String, + pub add_entry_cursor_position: usize, } impl PopupArea { @@ -48,6 +51,7 @@ 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"), diff --git a/src/tui/ui.rs b/src/tui/ui.rs index cca87ce..8d7498a 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -181,6 +181,55 @@ 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)), + )]), + Line::from(app.bibiman.popup_area.add_entry_input.clone()), + ]; + let paragraph = Paragraph::new(content) + .block(block.clone()) + .style(Style::new().fg(Color::Indexed(args.colors.main_text_color))) + .wrap(Wrap { trim: false }); + + // Calculate popup size + let popup_width = area.width / 2; + let popup_height = 5; // Adjust as needed + let popup_area = popup_area(area, popup_width, popup_height); + + // Render the popup + frame.render_widget(Clear, popup_area); + 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(); |
