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/app.rs | |
| 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/app.rs')
| -rw-r--r-- | src/app.rs | 73 |
1 files changed, 67 insertions, 6 deletions
@@ -23,6 +23,7 @@ use crate::tui::commands::InputCmdAction; use crate::tui::popup::PopupKind; use crate::tui::{self, Tui}; use crate::{bibiman::Bibiman, tui::commands::CmdAction}; +use ratatui::crossterm::event::KeyCode; use std::ffi::OsStr; use std::path::PathBuf; use std::process::{Command, Stdio}; @@ -78,14 +79,71 @@ impl App { } else if let Some(PopupKind::MessageError) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup() - } - let command = if self.input_mode { - CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) + } else if let Some(PopupKind::AddEntry) = self.bibiman.popup_area.popup_kind { + // Handle key events for AddEntry popup + match key_event.code { + KeyCode::Char(c) => { + let index = self.bibiman.popup_area.add_entry_cursor_position; + self.bibiman.popup_area.add_entry_input.insert(index, c); + self.bibiman.popup_area.add_entry_cursor_position += 1; + } + KeyCode::Backspace => { + if self.bibiman.popup_area.add_entry_cursor_position > 0 { + self.bibiman.popup_area.add_entry_cursor_position -= 1; + let index = self.bibiman.popup_area.add_entry_cursor_position; + self.bibiman.popup_area.add_entry_input.remove(index); + } + } + KeyCode::Left => { + if self.bibiman.popup_area.add_entry_cursor_position > 0 { + self.bibiman.popup_area.add_entry_cursor_position -= 1; + } + } + KeyCode::Right => { + if self.bibiman.popup_area.add_entry_cursor_position + < self.bibiman.popup_area.add_entry_input.len() + { + self.bibiman.popup_area.add_entry_cursor_position += 1; + } + } + KeyCode::Enter => { + // Handle submission of the new entry + self.bibiman.handle_new_entry_submission(); + self.bibiman.close_popup(); + self.input_mode = false; + } + KeyCode::Esc => { + // Close the popup without saving + self.bibiman.close_popup(); + self.input_mode = false; + } + _ => {} + } } else { - CmdAction::from(key_event) - }; - self.run_command(command, args, &mut tui)? + let command = if self.input_mode { + CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) + } else { + CmdAction::from(key_event) + }; + self.run_command(command, args, &mut tui)? + } } + // Event::Key(key_event) => { + // // Automatically close message popups on next keypress + // if let Some(PopupKind::MessageConfirm) = self.bibiman.popup_area.popup_kind { + // self.bibiman.close_popup() + // } else if let Some(PopupKind::MessageError) = self.bibiman.popup_area.popup_kind + // { + // self.bibiman.close_popup() + // } + + // let command = if self.input_mode { + // CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) + // } else { + // CmdAction::from(key_event) + // }; + // self.run_command(command, args, &mut tui)? + // } Event::Mouse(mouse_event) => { self.run_command(CmdAction::from(mouse_event), args, &mut tui)? } @@ -312,6 +370,9 @@ impl App { } } } + CmdAction::AddEntry => { + self.bibiman.add_entry(); + } CmdAction::ShowHelp => { self.bibiman.show_help(); } |
