aboutsummaryrefslogtreecommitdiff
path: root/src/bibiman.rs
diff options
context:
space:
mode:
authorTrim Bresilla2024-12-03 01:45:29 +0100
committerlukeflo2024-12-23 21:03:19 +0100
commit86d48aa48b9951b6cbc471113844d16683051f8f (patch)
tree91a1af8050312f5646170da00fab6972903fce12 /src/bibiman.rs
parenteadd906fc25125a61811247262836b9afe8adee1 (diff)
downloadbibiman-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/bibiman.rs')
-rw-r--r--src/bibiman.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs
index bba3eec..ee52207 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -23,10 +23,13 @@ use crate::tui::Tui;
use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList};
use arboard::Clipboard;
use color_eyre::eyre::{Ok, Result};
+use doi2bib;
use editor_command::EditorBuilder;
+use futures::executor::block_on;
use ratatui::widgets::ScrollbarState;
use std::fs;
use std::process::Command;
+use std::result::Result::Ok as AOk;
use tui_input::Input;
pub mod bibisetup;
@@ -107,6 +110,31 @@ impl Bibiman {
self.popup_area.popup_kind = Some(PopupKind::Help);
}
+ pub fn add_entry(&mut self) {
+ if let CurrentArea::EntryArea = self.current_area {
+ self.former_area = Some(FormerArea::EntryArea);
+ } else if let CurrentArea::TagArea = self.current_area {
+ self.former_area = Some(FormerArea::TagArea);
+ }
+ self.popup_area.is_popup = true;
+ self.current_area = CurrentArea::PopupArea;
+ self.popup_area.popup_kind = Some(PopupKind::AddEntry);
+ }
+
+ pub fn handle_new_entry_submission(&mut self) {
+ let new_entry_title = self.popup_area.add_entry_input.trim();
+ let doi2bib = doi2bib::Doi2Bib::new().unwrap();
+ let new_entry_future = doi2bib.resolve_doi(new_entry_title);
+ let new_entry = block_on(new_entry_future);
+
+ if let AOk(entry) = new_entry {
+ println!("New entry: {:?}", entry);
+ // Add logic here to integrate the new entry into your application
+ } else {
+ self.popup_area.popup_kind = Some(PopupKind::MessageError);
+ self.popup_area.popup_message = "Failed to add new entry".to_string();
+ }
+ }
pub fn close_popup(&mut self) {
// Reset all popup fields to default values
self.popup_area = PopupArea::default();