From 86d48aa48b9951b6cbc471113844d16683051f8f Mon Sep 17 00:00:00 2001 From: Trim Bresilla Date: Tue, 3 Dec 2024 01:45:29 +0100 Subject: 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 --- src/bibiman.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/bibiman.rs') 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(); -- cgit v1.2.3 From 98deb23810ba4142082f82939f25d44d3094a34f Mon Sep 17 00:00:00 2001 From: Trim Bresilla Date: Tue, 3 Dec 2024 02:23:09 +0100 Subject: feat: finalize basic "AddEntry" to add from DOI - Modify the `handle_new_entry_submission` method to accept additional arguments. - Add error handling for failed inserts when appending to the file. - Introduce a new method `append_to_file` to handle file appending logic. - Update file handling to ensure new entries are correctly written to the specified file. --- src/app.rs | 2 +- src/bibiman.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src/bibiman.rs') diff --git a/src/app.rs b/src/app.rs index ae45355..a200448 100644 --- a/src/app.rs +++ b/src/app.rs @@ -108,7 +108,7 @@ impl App { } KeyCode::Enter => { // Handle submission of the new entry - self.bibiman.handle_new_entry_submission(); + self.bibiman.handle_new_entry_submission(args); self.bibiman.close_popup(); self.input_mode = false; } diff --git a/src/bibiman.rs b/src/bibiman.rs index ee52207..e176bfa 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -28,6 +28,8 @@ use editor_command::EditorBuilder; use futures::executor::block_on; use ratatui::widgets::ScrollbarState; use std::fs; +use std::fs::OpenOptions; +use std::io::Write; use std::process::Command; use std::result::Result::Ok as AOk; use tui_input::Input; @@ -121,20 +123,25 @@ impl Bibiman { self.popup_area.popup_kind = Some(PopupKind::AddEntry); } - pub fn handle_new_entry_submission(&mut self) { + pub fn handle_new_entry_submission(&mut self, args: &CLIArgs) { 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 + // TODO: Add error handling for failed insert + if self.append_to_file(args, &entry.to_string()).is_err() { + self.popup_area.popup_kind = Some(PopupKind::MessageError); + self.popup_area.popup_message = "Failed to add new entry".to_string(); + } + // TODO: Add error handling for failed DOI lookup } 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(); @@ -414,6 +421,21 @@ impl Bibiman { Ok(()) } + /// Appends a string to the appropriate BibLaTeX file. + pub fn append_to_file(&mut self, args: &CLIArgs, content: &str) -> Result<()> { + // Determine the file path to append to + let file_path = args.files.first().unwrap(); + // Open the file in append mode + let mut file = OpenOptions::new().append(true).open(file_path).unwrap(); + // Optionally, add a newline before the content + file.write_all(b"\n")?; + // Write the content to the file + file.write_all(content.as_bytes())?; + // Update the database and the lists to reflect the new content + self.update_lists(args); + Ok(()) + } + // Search entry list pub fn search_entries(&mut self) { // Use snapshot of entry list saved when starting the search -- cgit v1.2.3 From 0c32c96fcfb8daa1c5061596542f76d355f27acd Mon Sep 17 00:00:00 2001 From: Trim Bresilla Date: Tue, 3 Dec 2024 11:33:58 +0100 Subject: feat: enhance BibTeX entry formatting and file handling - Remove the documentation comment for the `append_to_file` function. - Format the content before writing it to the file in the `append_to_file` function. - Add a new function `format_bibtex_entry` to enhance the readability of raw BibTeX entries. - Implement logic to properly parse and format BibTeX entries in the `format_bibtex_entry` function. --- src/bibiman.rs | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 3 deletions(-) (limited to 'src/bibiman.rs') diff --git a/src/bibiman.rs b/src/bibiman.rs index e176bfa..778048f 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -421,7 +421,6 @@ impl Bibiman { Ok(()) } - /// Appends a string to the appropriate BibLaTeX file. pub fn append_to_file(&mut self, args: &CLIArgs, content: &str) -> Result<()> { // Determine the file path to append to let file_path = args.files.first().unwrap(); @@ -429,13 +428,86 @@ impl Bibiman { let mut file = OpenOptions::new().append(true).open(file_path).unwrap(); // Optionally, add a newline before the content file.write_all(b"\n")?; - // Write the content to the file - file.write_all(content.as_bytes())?; + // Format the content + let formatted_content = Self::format_bibtex_entry(content); + // Write the formatted content to the file + file.write_all(formatted_content.as_bytes())?; // Update the database and the lists to reflect the new content self.update_lists(args); Ok(()) } + /// Formats a raw BibTeX entry string for better readability. + pub fn format_bibtex_entry(entry: &str) -> String { + let mut formatted = String::new(); + // Find the position of the first '{' + if let Some(start_brace_pos) = entry.find('{') { + // Copy the preamble (e.g., '@article{') + let preamble = &entry[..start_brace_pos + 1]; + formatted.push_str(preamble); + formatted.push('\n'); // Add newline + // Now get the content inside the braces + let rest = &entry[start_brace_pos + 1..]; + // Remove the last '}' at the end + let rest = rest.trim_end(); + let rest = if rest.ends_with('}') { + &rest[..rest.len() - 1] + } else { + rest + }; + // Now we need to split the rest by commas, but commas can be inside braces or quotes + // We'll parse the fields properly + let mut fields = Vec::new(); + let mut current_field = String::new(); + let mut brace_level = 0; + let mut in_quotes = false; + for c in rest.chars() { + match c { + '{' if !in_quotes => { + brace_level += 1; + current_field.push(c); + } + '}' if !in_quotes => { + brace_level -= 1; + current_field.push(c); + } + '"' => { + in_quotes = !in_quotes; + current_field.push(c); + } + ',' if brace_level == 0 && !in_quotes => { + // Outside of braces and quotes, comma separates fields + fields.push(current_field.trim().to_string()); + current_field.clear(); + } + _ => { + current_field.push(c); + } + } + } + // Add the last field + if !current_field.trim().is_empty() { + fields.push(current_field.trim().to_string()); + } + + // Now reconstruct the entry with proper indentation + for (i, field) in fields.iter().enumerate() { + formatted.push_str(" "); + formatted.push_str(field); + // Add a comma if it's not the last field + if i < fields.len() - 1 { + formatted.push(','); + } + formatted.push('\n'); + } + formatted.push('}'); // Close the entry + formatted + } else { + // No opening brace found, return the entry as is + entry.to_string() + } + } + // Search entry list pub fn search_entries(&mut self) { // Use snapshot of entry list saved when starting the search -- cgit v1.2.3 From 9c0ad228a34d842cf21e88f8d99e5c2b5f51e93c Mon Sep 17 00:00:00 2001 From: Trim Bresilla Date: Tue, 3 Dec 2024 16:08:25 +0100 Subject: feat: add 'file={}' entry in BibTex - Improve error handling for failed file appends by formatting content before appending. - Modify the `format_bibtex_entry` function to accept a file path argument. - Add a new `file` field to the formatted BibTeX entry. - Ensure the formatted content is written to the file correctly. --- src/bibiman.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/bibiman.rs') diff --git a/src/bibiman.rs b/src/bibiman.rs index 778048f..19eaf4b 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -131,7 +131,9 @@ impl Bibiman { if let AOk(entry) = new_entry { // TODO: Add error handling for failed insert - if self.append_to_file(args, &entry.to_string()).is_err() { + let formatted_content = Self::format_bibtex_entry(&entry, ""); + + if self.append_to_file(args, &formatted_content).is_err() { self.popup_area.popup_kind = Some(PopupKind::MessageError); self.popup_area.popup_message = "Failed to add new entry".to_string(); } @@ -429,21 +431,21 @@ impl Bibiman { // Optionally, add a newline before the content file.write_all(b"\n")?; // Format the content - let formatted_content = Self::format_bibtex_entry(content); // Write the formatted content to the file - file.write_all(formatted_content.as_bytes())?; + file.write_all(content.as_bytes())?; // Update the database and the lists to reflect the new content self.update_lists(args); Ok(()) } /// Formats a raw BibTeX entry string for better readability. - pub fn format_bibtex_entry(entry: &str) -> String { + pub fn format_bibtex_entry(entry: &str, file_path: &str) -> String { let mut formatted = String::new(); // Find the position of the first '{' if let Some(start_brace_pos) = entry.find('{') { // Copy the preamble (e.g., '@article{') let preamble = &entry[..start_brace_pos + 1]; + let preamble = preamble.trim_start(); formatted.push_str(preamble); formatted.push('\n'); // Add newline // Now get the content inside the braces @@ -490,6 +492,10 @@ impl Bibiman { fields.push(current_field.trim().to_string()); } + // Add the new 'file' field + let file_field = format!("file = {{{}}}", file_path); + fields.push(file_field); + // Now reconstruct the entry with proper indentation for (i, field) in fields.iter().enumerate() { formatted.push_str(" "); -- cgit v1.2.3 From bcde4e631f28d4610738df65353cf9b319d4b98a Mon Sep 17 00:00:00 2001 From: Trim Bresilla Date: Wed, 4 Dec 2024 12:38:59 +0100 Subject: fix: hande better eyre's OK and std's OK - Remove unnecessary aliasing of Result to AOk - Simplify the import statement for Result from color_eyre - Update error handling for the new entry resolution process --- src/bibiman.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/bibiman.rs') diff --git a/src/bibiman.rs b/src/bibiman.rs index 19eaf4b..232fd9e 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -22,7 +22,7 @@ use crate::tui::popup::{PopupArea, PopupKind}; use crate::tui::Tui; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; -use color_eyre::eyre::{Ok, Result}; +use color_eyre::eyre::Result; use doi2bib; use editor_command::EditorBuilder; use futures::executor::block_on; @@ -31,7 +31,7 @@ use std::fs; use std::fs::OpenOptions; use std::io::Write; use std::process::Command; -use std::result::Result::Ok as AOk; +use std::result::Result::Ok; use tui_input::Input; pub mod bibisetup; @@ -129,7 +129,7 @@ impl Bibiman { let new_entry_future = doi2bib.resolve_doi(new_entry_title); let new_entry = block_on(new_entry_future); - if let AOk(entry) = new_entry { + if let Ok(entry) = new_entry { // TODO: Add error handling for failed insert let formatted_content = Self::format_bibtex_entry(&entry, ""); -- cgit v1.2.3 From be72bac936515007b4fd9a30632f62ee19839bf8 Mon Sep 17 00:00:00 2001 From: Trim Bresilla Date: Wed, 4 Dec 2024 13:01:10 +0100 Subject: feat: handle better arXiv's "citation key" imported from DOI - Add a new dependency `rand` version `0.8` to the project - Modify the `format_bibtex_entry` function for better readability and citation key cleaning - Introduce logic to clean the citation key by retaining only alphanumerical characters and underscores - Limit the citation key to the last 14 characters if it exceeds that length - Add a new `file` field to the BibTeX entry using the provided file path --- Cargo.lock | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/bibiman.rs | 45 +++++++++++++++++++++++++++++++++------ 3 files changed, 106 insertions(+), 7 deletions(-) (limited to 'src/bibiman.rs') diff --git a/Cargo.lock b/Cargo.lock index f00bd10..8b9dbb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,6 +105,7 @@ dependencies = [ "itertools", "lexopt", "nucleo-matcher", + "rand", "ratatui", "signal-hook", "tokio", @@ -159,6 +160,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "byteorder-lite" version = "0.1.0" @@ -1496,6 +1503,15 @@ dependencies = [ "miniz_oxide 0.8.0", ] +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.87" @@ -1523,6 +1539,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "ratatui" version = "0.29.0" @@ -2772,6 +2818,27 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zerofrom" version = "0.1.5" diff --git a/Cargo.toml b/Cargo.toml index ffd4cca..9d6dba3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ doi2bib = "0.2.0" # doi = "0.3.0" editor-command = "0.1.1" futures = "0.3.30" +rand = "0.8" itertools = "0.13.0" lexopt = "0.3.0" nucleo-matcher = "0.3.1" diff --git a/src/bibiman.rs b/src/bibiman.rs index 232fd9e..10dab1e 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -441,24 +441,26 @@ impl Bibiman { /// Formats a raw BibTeX entry string for better readability. pub fn format_bibtex_entry(entry: &str, file_path: &str) -> String { let mut formatted = String::new(); + // Find the position of the first '{' if let Some(start_brace_pos) = entry.find('{') { - // Copy the preamble (e.g., '@article{') + // Extract the preamble (e.g., '@article{') let preamble = &entry[..start_brace_pos + 1]; let preamble = preamble.trim_start(); formatted.push_str(preamble); formatted.push('\n'); // Add newline - // Now get the content inside the braces + + // Get the content inside the braces let rest = &entry[start_brace_pos + 1..]; - // Remove the last '}' at the end + // Remove the last '}' at the end, if present let rest = rest.trim_end(); let rest = if rest.ends_with('}') { &rest[..rest.len() - 1] } else { rest }; - // Now we need to split the rest by commas, but commas can be inside braces or quotes - // We'll parse the fields properly + + // Parse the fields, considering braces and quotes let mut fields = Vec::new(); let mut current_field = String::new(); let mut brace_level = 0; @@ -492,11 +494,41 @@ impl Bibiman { fields.push(current_field.trim().to_string()); } + // **Conditionally Clean the Citation Key** + if let Some(citation_key) = fields.get_mut(0) { + // Check if the citation key contains any non-alphanumerical characters except underscores + let needs_cleaning = citation_key + .chars() + .any(|c| !c.is_alphanumeric() && c != '_'); + if needs_cleaning { + // Retain only alphanumerical characters and underscores + let cleaned_key: String = citation_key + .chars() + .filter(|c| c.is_alphanumeric() || *c == '_') + .collect(); + // If the cleaned key is longer than 14 characters, retain only the last 14 + let limited_key = if cleaned_key.len() > 14 { + cleaned_key + .chars() + .rev() + .take(14) + .collect::() + .chars() + .rev() + .collect() + } else { + cleaned_key + }; + // Replace the original citation key with the cleaned and possibly limited key + *citation_key = limited_key; + } + } + // Add the new 'file' field let file_field = format!("file = {{{}}}", file_path); fields.push(file_field); - // Now reconstruct the entry with proper indentation + // Reconstruct the entry with proper indentation for (i, field) in fields.iter().enumerate() { formatted.push_str(" "); formatted.push_str(field); @@ -513,7 +545,6 @@ impl Bibiman { entry.to_string() } } - // Search entry list pub fn search_entries(&mut self) { // Use snapshot of entry list saved when starting the search -- cgit v1.2.3 From a6fca1fcf164142d84d09242b9d95a1da0b2d2d9 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 15 Dec 2024 13:21:42 +0100 Subject: use input struct, place cursor at pos --- src/app.rs | 99 ++++++++++++++++++++++++++++--------------------- src/bibiman.rs | 4 +- src/tui/popup.rs | 4 +- src/tui/ui.rs | 41 ++++++++++---------- tests/biblatex-test.bib | 13 +++++++ 5 files changed, 95 insertions(+), 66 deletions(-) (limited to 'src/bibiman.rs') diff --git a/src/app.rs b/src/app.rs index 2834e61..bcdef39 100644 --- a/src/app.rs +++ b/src/app.rs @@ -79,47 +79,49 @@ impl App { } else if let Some(PopupKind::MessageError) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup() - } 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(args); - self.bibiman.close_popup(); - self.input_mode = false; - } - KeyCode::Esc => { - // Close the popup without saving - self.bibiman.close_popup(); - self.input_mode = false; - } - _ => {} - } - } else { + } + // 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(args, &self.input); + // self.bibiman.close_popup(); + // self.input_mode = false; + // } + // KeyCode::Esc => { + // // Close the popup without saving + // self.bibiman.close_popup(); + // self.input_mode = false; + // } + // _ => {} + // } + // } + else { let command = if self.input_mode { CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) } else { @@ -183,18 +185,28 @@ impl App { // self.bibiman.enter_search_area(); } InputCmdAction::Confirm => { - self.input = Input::default(); - self.input_mode = false; // Logic for TABS to be added if let CurrentArea::SearchArea = self.bibiman.current_area { self.bibiman.confirm_search(); + } else if let CurrentArea::PopupArea = self.bibiman.current_area { + match self.bibiman.popup_area.popup_kind { + Some(PopupKind::AddEntry) => { + self.bibiman.handle_new_entry_submission(args, &self.input); + self.bibiman.close_popup(); + } + _ => {} + } } + self.input = Input::default(); + self.input_mode = false; } InputCmdAction::Exit => { self.input = Input::default(); self.input_mode = false; if let CurrentArea::SearchArea = self.bibiman.current_area { self.bibiman.break_search(); + } else if let CurrentArea::PopupArea = self.bibiman.current_area { + self.bibiman.close_popup(); } } }, @@ -380,6 +392,7 @@ impl App { } } CmdAction::AddEntry => { + self.input_mode = true; self.bibiman.add_entry(); } CmdAction::ShowHelp => { diff --git a/src/bibiman.rs b/src/bibiman.rs index 10dab1e..4e6e5e8 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -123,8 +123,8 @@ impl Bibiman { self.popup_area.popup_kind = Some(PopupKind::AddEntry); } - pub fn handle_new_entry_submission(&mut self, args: &CLIArgs) { - let new_entry_title = self.popup_area.add_entry_input.trim(); + pub fn handle_new_entry_submission(&mut self, args: &CLIArgs, doi_string: &Input) { + let new_entry_title = doi_string.value(); let doi2bib = doi2bib::Doi2Bib::new().unwrap(); let new_entry_future = doi2bib.resolve_doi(new_entry_title); let new_entry = block_on(new_entry_future); diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 9b91801..afe0cfc 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -40,8 +40,8 @@ pub struct PopupArea { pub popup_scroll_pos: u16, pub popup_list: Vec, pub popup_state: ListState, - pub add_entry_input: String, - pub add_entry_cursor_position: usize, + // pub add_entry_input: String, + // pub add_entry_cursor_position: usize, } impl PopupArea { diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 8d7498a..e3fddfd 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -198,37 +198,39 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .border_style(Style::new().fg(Color::Indexed(args.colors.entry_color))); // Prepare the input fields - let content = vec![ - Line::from(vec![Span::styled( + 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()), - ]; + ), + 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 / 2; - let popup_height = 5; // Adjust as needed + 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); 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)); - } + // // 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(); @@ -376,7 +378,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); } @@ -1035,12 +1037,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, diff --git a/tests/biblatex-test.bib b/tests/biblatex-test.bib index b366fc3..d64b980 100644 --- a/tests/biblatex-test.bib +++ b/tests/biblatex-test.bib @@ -376,3 +376,16 @@ date = {2006}, indextitle = {Palladium pincer complexes}, } + +@article{ + 034780862i9pet, + doi = {10.34780/862I-9PET}, + url = {https://publications.dainst.org/journals/aa/article/view/4444}, + author = {Kammerer-Grothaus, Helke}, + keywords = {Topographie, Grabbauten, Nachleben, Tomba Baccelli}, + language = {de}, + title = {Die ›Tomba Baccelli‹ an der Via Latina in Rom}, + publisher = {Archäologischer Anzeiger}, + year = {2024}, + file = {} +} \ No newline at end of file -- cgit v1.2.3 From bf93bbee1b59c9804a01a7476e12264bbbcf5f40 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 16 Dec 2024 13:46:24 +0100 Subject: 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 --- Cargo.lock | 3 +- Cargo.toml | 1 + src/app.rs | 188 +++++++++++++++++++++++------------------ src/bibiman.rs | 94 +++++++++++---------- src/main.rs | 4 +- src/tui/commands.rs | 10 --- src/tui/popup.rs | 8 +- src/tui/ui.rs | 27 +++--- tests/biblatex-test.bib | 13 --- tests/multi-files/bibfile1.bib | 14 +++ 10 files changed, 191 insertions(+), 171 deletions(-) (limited to 'src/bibiman.rs') diff --git a/Cargo.lock b/Cargo.lock index 8b9dbb7..81b976f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -107,6 +107,7 @@ dependencies = [ "nucleo-matcher", "rand", "ratatui", + "regex", "signal-hook", "tokio", "tokio-util", diff --git a/Cargo.toml b/Cargo.toml index 9d6dba3..34ec65f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ tokio = { version = "1.39.3", features = ["full"] } tokio-util = "0.7.12" tui-input = "0.11.0" walkdir = "2.5.0" +regex = "1.11.1" diff --git a/src/app.rs b/src/app.rs index bcdef39..a3691d6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -17,15 +17,18 @@ use crate::bibiman::{CurrentArea, FormerArea}; use color_eyre::eyre::{Context, Ok, Result}; +use regex::Regex; // use super::Event; use crate::cliargs::CLIArgs; 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 core::panic; use std::ffi::OsStr; -use std::path::PathBuf; +use std::fs::{File, OpenOptions}; +use std::io::Write; +use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use tui::Event; use tui_input::backend::crossterm::EventHandler; @@ -59,7 +62,7 @@ impl App { }) } - pub async fn run(&mut self, args: &CLIArgs) -> Result<()> { + pub async fn run(&mut self, args: &mut CLIArgs) -> Result<()> { let mut tui = tui::Tui::new()?; tui.enter()?; @@ -80,72 +83,13 @@ impl App { { self.bibiman.close_popup() } - // 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(args, &self.input); - // self.bibiman.close_popup(); - // self.input_mode = false; - // } - // KeyCode::Esc => { - // // Close the popup without saving - // self.bibiman.close_popup(); - // self.input_mode = false; - // } - // _ => {} - // } - // } - else { - 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)? - } + 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)? } @@ -169,7 +113,7 @@ impl App { self.running = false; } - pub fn run_command(&mut self, cmd: CmdAction, args: &CLIArgs, tui: &mut Tui) -> Result<()> { + pub fn run_command(&mut self, cmd: CmdAction, args: &mut CLIArgs, tui: &mut Tui) -> Result<()> { match cmd { CmdAction::Input(cmd) => match cmd { InputCmdAction::Nothing => {} @@ -191,8 +135,19 @@ impl App { } else if let CurrentArea::PopupArea = self.bibiman.current_area { match self.bibiman.popup_area.popup_kind { Some(PopupKind::AddEntry) => { - self.bibiman.handle_new_entry_submission(args, &self.input); + let doi = self.input.value(); self.bibiman.close_popup(); + self.input_mode = false; + // Check if the DOI pattern is valid. If not, show warning and break + if doi.starts_with("10.") || doi.starts_with("http") { + self.bibiman.handle_new_entry_submission(args, doi); + } else { + self.bibiman.popup_area.popup_message( + "No valid DOI pattern: ", + doi, + false, + ); + } } _ => {} } @@ -218,13 +173,15 @@ impl App { CurrentArea::TagArea => { self.bibiman.select_next_tag(amount); } - CurrentArea::PopupArea => { - if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { + CurrentArea::PopupArea => match self.bibiman.popup_area.popup_kind { + Some(PopupKind::Help) => { self.bibiman.popup_area.popup_scroll_down(); - } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind { + } + Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => { self.bibiman.popup_area.popup_state.scroll_down_by(1) } - } + _ => {} + }, _ => {} }, CmdAction::SelectPrevRow(amount) => match self.bibiman.current_area { @@ -235,13 +192,15 @@ impl App { CurrentArea::TagArea => { self.bibiman.select_previous_tag(amount); } - CurrentArea::PopupArea => { - if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { + CurrentArea::PopupArea => match self.bibiman.popup_area.popup_kind { + Some(PopupKind::Help) => { self.bibiman.popup_area.popup_scroll_up(); - } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind { + } + Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => { self.bibiman.popup_area.popup_state.scroll_up_by(1) } - } + _ => {} + }, _ => {} }, CmdAction::SelectNextCol => { @@ -290,8 +249,10 @@ impl App { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.popup_area.popup_scroll_pos = 0; self.bibiman.close_popup() - } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::SelectRes) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup() + } else if let Some(PopupKind::SelectFile) = self.bibiman.popup_area.popup_kind { + self.bibiman.close_popup(); } } else { self.bibiman.reset_current_list(); @@ -303,7 +264,7 @@ impl App { } else if let CurrentArea::PopupArea = self.bibiman.current_area { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); - } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::SelectRes) = self.bibiman.popup_area.popup_kind { // Index of selected entry let entry_idx = self .bibiman @@ -330,6 +291,55 @@ impl App { }; // run command to open file/Url self.bibiman.close_popup() + } else if let Some(PopupKind::SelectFile) = self.bibiman.popup_area.popup_kind { + // Index of selected popup field + let popup_idx = self.bibiman.popup_area.popup_state.selected().unwrap(); + + // regex pattern to match citekey in fetched bibtexstring + let pattern = Regex::new(r"\{([^\{\},]*),").unwrap(); + + let citekey = PathBuf::from( + pattern + .captures(&self.bibiman.popup_area.popup_sel_item) + .unwrap() + .get(1) + .unwrap() + .as_str(), + ); + + // Check if new file or existing file was choosen + let mut file = if self.bibiman.popup_area.popup_list[popup_idx] + .contains("Create new file") + { + // Get path of current files + let path: PathBuf = if args.files[0].is_file() { + args.files[0].parent().unwrap().to_owned() + } else { + dirs::home_dir().unwrap() // home dir as fallback + }; + + let citekey = citekey.with_extension("bib"); + + let newfile = path.join(citekey); + + args.files.push(newfile.clone()); + + File::create_new(newfile).unwrap() + } else { + let file_path = &args.files[popup_idx - 1]; + OpenOptions::new().append(true).open(file_path).unwrap() + }; + // Optionally, add a newline before the content + file.write_all(b"\n")?; + // Write content to file + file.write_all(self.bibiman.popup_area.popup_sel_item.as_bytes())?; + // Update the database and the lists to reflect the new content + self.bibiman.update_lists(args); + self.bibiman.close_popup(); + + // Select newly created entry + self.bibiman + .select_entry_by_citekey(citekey.to_str().unwrap()); } } } @@ -378,6 +388,7 @@ impl App { if entry.filepath.is_some() { items.push("File (PDF/EPUB)".to_owned()) } + self.bibiman.popup_area.popup_kind = Some(PopupKind::SelectRes); self.bibiman.popup_area.popup_selection(items); self.bibiman.former_area = Some(FormerArea::EntryArea); self.bibiman.current_area = CurrentArea::PopupArea; @@ -392,8 +403,10 @@ impl App { } } CmdAction::AddEntry => { - self.input_mode = true; - self.bibiman.add_entry(); + if let CurrentArea::EntryArea = self.bibiman.current_area { + self.input_mode = true; + self.bibiman.add_entry(); + } } CmdAction::ShowHelp => { self.bibiman.show_help(); @@ -498,4 +511,15 @@ mod test { assert_eq!(path, PathBuf::from(full_path)) } + + #[test] + fn regex_capture_citekey() { + let re = Regex::new(r"\{([^\{\},]*),").unwrap(); + + let bibstring = String::from("@article{citekey77_2001:!?, author = {Hanks, Tom}, title = {A great book}, year = {2001}}"); + + let result = re.captures(&bibstring).unwrap(); + + assert_eq!(result.get(1).unwrap().as_str(), "citekey77_2001:!?") + } } diff --git a/src/bibiman.rs b/src/bibiman.rs index 4e6e5e8..0dc64e0 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -22,7 +22,7 @@ use crate::tui::popup::{PopupArea, PopupKind}; use crate::tui::Tui; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; -use color_eyre::eyre::Result; +use color_eyre::eyre::{eyre, Result}; use doi2bib; use editor_command::EditorBuilder; use futures::executor::block_on; @@ -115,32 +115,32 @@ impl Bibiman { 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, args: &CLIArgs, doi_string: &Input) { - let new_entry_title = doi_string.value(); + ///Try to resolve entered DOI. If successfull, choose file where to append + ///the new entry via `append_to_file()` function. If not, show error popup + /// + ///The method needs two arguments: the CLIArgs struct and the `str` containing the DOI + pub fn handle_new_entry_submission(&mut self, args: &CLIArgs, doi_string: &str) { let doi2bib = doi2bib::Doi2Bib::new().unwrap(); - let new_entry_future = doi2bib.resolve_doi(new_entry_title); + let new_entry_future = doi2bib.resolve_doi(doi_string); let new_entry = block_on(new_entry_future); if let Ok(entry) = new_entry { - // TODO: Add error handling for failed insert - let formatted_content = Self::format_bibtex_entry(&entry, ""); - - if self.append_to_file(args, &formatted_content).is_err() { - self.popup_area.popup_kind = Some(PopupKind::MessageError); - self.popup_area.popup_message = "Failed to add new entry".to_string(); - } - // TODO: Add error handling for failed DOI lookup + // Save generated bibtex entry in structs field + self.popup_area.popup_sel_item = entry; + self.popup_area.popup_kind = Some(PopupKind::SelectFile); + self.append_to_file(args); + self.former_area = Some(FormerArea::EntryArea); + self.current_area = CurrentArea::PopupArea; + self.popup_area.popup_state.select(Some(0)) } else { - self.popup_area.popup_kind = Some(PopupKind::MessageError); - self.popup_area.popup_message = "Failed to add new entry".to_string(); + self.popup_area + .popup_message("Failed to add new entry", "", false); } } @@ -336,6 +336,26 @@ impl Bibiman { } } + pub fn select_entry_by_citekey(&mut self, citekey: &str) { + // Search for entry by matching citekeys + let mut idx_count = 0; + loop { + if idx_count == self.entry_table.entry_table_items.len() { + idx_count = 0; + break; + } else if self.entry_table.entry_table_items[idx_count] + .citekey + .contains(citekey) + { + break; + } + idx_count += 1 + } + + // Set selected entry to vec-index of match + self.entry_table.entry_table_state.select(Some(idx_count)); + } + pub fn run_editor(&mut self, args: &CLIArgs, tui: &mut Tui) -> Result<()> { // get filecontent and citekey for calculating line number let citekey: &str = &self.entry_table.entry_table_items @@ -404,38 +424,22 @@ impl Bibiman { // Update the database and the lists to show changes Self::update_lists(self, args); - // Search for entry, selected before editing, by matching citekeys - // Use earlier saved copy of citekey to match - let mut idx_count = 0; - loop { - if self.entry_table.entry_table_items[idx_count] - .citekey - .contains(citekey) - { - break; - } - idx_count += 1 - } - - // Set selected entry to vec-index of match - self.entry_table.entry_table_state.select(Some(idx_count)); + // Select entry which was selected before entering editor + self.select_entry_by_citekey(citekey); Ok(()) } - pub fn append_to_file(&mut self, args: &CLIArgs, content: &str) -> Result<()> { - // Determine the file path to append to - let file_path = args.files.first().unwrap(); - // Open the file in append mode - let mut file = OpenOptions::new().append(true).open(file_path).unwrap(); - // Optionally, add a newline before the content - file.write_all(b"\n")?; - // Format the content - // Write the formatted content to the file - file.write_all(content.as_bytes())?; - // Update the database and the lists to reflect the new content - self.update_lists(args); - Ok(()) + pub fn append_to_file(&mut self, args: &CLIArgs) { + let mut items = vec!["Create new file".to_owned()]; + if args.files.len() > 1 { + for f in args.files.clone() { + items.push(f.to_str().unwrap().to_owned()); + } + } else { + items.push(args.files.first().unwrap().to_str().unwrap().to_owned()); + } + self.popup_area.popup_selection(items); } /// Formats a raw BibTeX entry string for better readability. @@ -448,7 +452,7 @@ impl Bibiman { let preamble = &entry[..start_brace_pos + 1]; let preamble = preamble.trim_start(); formatted.push_str(preamble); - formatted.push('\n'); // Add newline + // formatted.push('\n'); // Add newline // Get the content inside the braces let rest = &entry[start_brace_pos + 1..]; diff --git a/src/main.rs b/src/main.rs index b1160e2..78c5075 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ pub mod tui; #[tokio::main] async fn main() -> Result<()> { // Parse CLI arguments - let parsed_args = CLIArgs::parse_args().unwrap(); + let mut parsed_args = CLIArgs::parse_args().unwrap(); // Print help if -h/--help flag is passed and exit if parsed_args.helparg { @@ -48,6 +48,6 @@ async fn main() -> Result<()> { // Create an application. let mut app = App::new(&parsed_args)?; - app.run(&parsed_args).await?; + app.run(&mut parsed_args).await?; Ok(()) } 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 for CmdAction { Self::SelectPrevRow(5) } else { Self::Nothing - // Self::Open(OpenRessource::WebLink) } } // Scroll info/preview area @@ -132,15 +131,6 @@ impl From 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, 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) { 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 = 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( diff --git a/tests/biblatex-test.bib b/tests/biblatex-test.bib index d64b980..b366fc3 100644 --- a/tests/biblatex-test.bib +++ b/tests/biblatex-test.bib @@ -376,16 +376,3 @@ date = {2006}, indextitle = {Palladium pincer complexes}, } - -@article{ - 034780862i9pet, - doi = {10.34780/862I-9PET}, - url = {https://publications.dainst.org/journals/aa/article/view/4444}, - author = {Kammerer-Grothaus, Helke}, - keywords = {Topographie, Grabbauten, Nachleben, Tomba Baccelli}, - language = {de}, - title = {Die ›Tomba Baccelli‹ an der Via Latina in Rom}, - publisher = {Archäologischer Anzeiger}, - year = {2024}, - file = {} -} \ No newline at end of file diff --git a/tests/multi-files/bibfile1.bib b/tests/multi-files/bibfile1.bib index 31d81bc..230a517 100644 --- a/tests/multi-files/bibfile1.bib +++ b/tests/multi-files/bibfile1.bib @@ -11,3 +11,17 @@ langidopts = {variant=american}, annotation = {A \texttt{collection} entry providing the excerpt information for the \texttt{doody} entry. Note the format of the \texttt{pages} field}, } + +@book{ + Bernal_2001, + title={Black Athena Writes Back: Martin Bernal Responds to His Critics}, + ISBN={9780822380078}, + url={http://dx.doi.org/10.1515/9780822380078}, + DOI={10.1515/9780822380078}, + publisher={Duke University Press}, + author={Bernal, Martin}, + editor={Moore, David Chioni}, + year={2001}, + month=sep, + file = {} +} \ No newline at end of file -- cgit v1.2.3 From 6ff6b82e0fcea4344db8b17ea5be2d72b3d9d9f2 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 23 Dec 2024 19:07:24 +0100 Subject: better error messages for doi-add --- README.md | 2 +- src/app.rs | 42 ++++++++++++++++++++++++------------------ src/bibiman.rs | 4 ++-- src/tui/popup.rs | 4 ++-- src/tui/ui.rs | 6 +++--- 5 files changed, 32 insertions(+), 26 deletions(-) (limited to 'src/bibiman.rs') diff --git a/README.md b/README.md index bf1749e..069b6d4 100644 --- a/README.md +++ b/README.md @@ -116,8 +116,8 @@ my personal workflow. There are more to come, the list will be updated: - [x] **Scrollbar** for better navigating. - [x] **Sort Entries** by column (`Authors`, `Title`, `Year`, `Pubtype`) - [x] **Load multiple files** into one session. +- [x] **Add Entry via DOI** as formatted code. - [ ] **Open related notes file** for specific entry. -- [ ] **Add Entry via DOI** as formatted code. - [ ] **Implement config file** for setting some default values like main bibfile, PDF-opener, or editor - [ ] **Support Hayagriva(`.yaml`)** format as input (_on hold for now_, because diff --git a/src/app.rs b/src/app.rs index a3691d6..a3b0522 100644 --- a/src/app.rs +++ b/src/app.rs @@ -139,7 +139,12 @@ impl App { self.bibiman.close_popup(); self.input_mode = false; // Check if the DOI pattern is valid. If not, show warning and break - if doi.starts_with("10.") || doi.starts_with("http") { + if doi.starts_with("10.") + || doi.starts_with("https://doi.org") + || doi.starts_with("https://dx.doi.org") + || doi.starts_with("http://doi.org") + || doi.starts_with("http://dx.doi.org") + { self.bibiman.handle_new_entry_submission(args, doi); } else { self.bibiman.popup_area.popup_message( @@ -177,7 +182,7 @@ impl App { Some(PopupKind::Help) => { self.bibiman.popup_area.popup_scroll_down(); } - Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => { + Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { self.bibiman.popup_area.popup_state.scroll_down_by(1) } _ => {} @@ -196,7 +201,7 @@ impl App { Some(PopupKind::Help) => { self.bibiman.popup_area.popup_scroll_up(); } - Some(PopupKind::SelectRes) | Some(PopupKind::SelectFile) => { + Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { self.bibiman.popup_area.popup_state.scroll_up_by(1) } _ => {} @@ -249,9 +254,10 @@ impl App { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.popup_area.popup_scroll_pos = 0; self.bibiman.close_popup() - } else if let Some(PopupKind::SelectRes) = self.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup() - } else if let Some(PopupKind::SelectFile) = self.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind + { self.bibiman.close_popup(); } } else { @@ -264,7 +270,7 @@ impl App { } else if let CurrentArea::PopupArea = self.bibiman.current_area { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); - } else if let Some(PopupKind::SelectRes) = self.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind { // Index of selected entry let entry_idx = self .bibiman @@ -291,26 +297,27 @@ impl App { }; // run command to open file/Url self.bibiman.close_popup() - } else if let Some(PopupKind::SelectFile) = self.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind + { // Index of selected popup field let popup_idx = self.bibiman.popup_area.popup_state.selected().unwrap(); // regex pattern to match citekey in fetched bibtexstring let pattern = Regex::new(r"\{([^\{\},]*),").unwrap(); - let citekey = PathBuf::from( - pattern - .captures(&self.bibiman.popup_area.popup_sel_item) - .unwrap() - .get(1) - .unwrap() - .as_str(), - ); + let citekey = pattern + .captures(&self.bibiman.popup_area.popup_sel_item) + .unwrap() + .get(1) + .unwrap() + .as_str() + .to_string(); // Check if new file or existing file was choosen let mut file = if self.bibiman.popup_area.popup_list[popup_idx] .contains("Create new file") { + let citekey = PathBuf::from(&citekey); // Get path of current files let path: PathBuf = if args.files[0].is_file() { args.files[0].parent().unwrap().to_owned() @@ -338,8 +345,7 @@ impl App { self.bibiman.close_popup(); // Select newly created entry - self.bibiman - .select_entry_by_citekey(citekey.to_str().unwrap()); + self.bibiman.select_entry_by_citekey(&citekey); } } } @@ -388,7 +394,7 @@ impl App { if entry.filepath.is_some() { items.push("File (PDF/EPUB)".to_owned()) } - self.bibiman.popup_area.popup_kind = Some(PopupKind::SelectRes); + self.bibiman.popup_area.popup_kind = Some(PopupKind::OpenRes); self.bibiman.popup_area.popup_selection(items); self.bibiman.former_area = Some(FormerArea::EntryArea); self.bibiman.current_area = CurrentArea::PopupArea; diff --git a/src/bibiman.rs b/src/bibiman.rs index 0dc64e0..5d6aa30 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -133,14 +133,14 @@ impl Bibiman { if let Ok(entry) = new_entry { // Save generated bibtex entry in structs field self.popup_area.popup_sel_item = entry; - self.popup_area.popup_kind = Some(PopupKind::SelectFile); + self.popup_area.popup_kind = Some(PopupKind::AppendToFile); self.append_to_file(args); self.former_area = Some(FormerArea::EntryArea); self.current_area = CurrentArea::PopupArea; self.popup_area.popup_state.select(Some(0)) } else { self.popup_area - .popup_message("Failed to add new entry", "", false); + .popup_message("Can't find DOI: ", &doi_string, false); } } diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 352b328..78a0719 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -28,8 +28,8 @@ pub enum PopupKind { Help, MessageConfirm, MessageError, - SelectRes, - SelectFile, + OpenRes, + AppendToFile, AddEntry, } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 6a3b8de..4f64338 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -283,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::SelectRes) | Some(PopupKind::SelectFile) => { + Some(PopupKind::OpenRes) | Some(PopupKind::AppendToFile) => { let list_items: Vec = app .bibiman .popup_area @@ -292,9 +292,9 @@ 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 { + let title = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind { " Open " - } else if let Some(PopupKind::SelectFile) = app.bibiman.popup_area.popup_kind { + } else if let Some(PopupKind::AppendToFile) = app.bibiman.popup_area.popup_kind { " Select file to append entry " } else { " Select " -- cgit v1.2.3 From 8333136cb770cbfbb7be2160fd85687493d96ea4 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 23 Dec 2024 20:41:55 +0100 Subject: collect code for adding entries and opening files in method --- src/app.rs | 91 ++--------------------------------------------- src/bibiman.rs | 94 +++++++++++++++++++++++++++++++++++++++++++++++-- tests/biblatex-test.bib | 2 +- 3 files changed, 95 insertions(+), 92 deletions(-) (limited to 'src/bibiman.rs') diff --git a/src/app.rs b/src/app.rs index a3b0522..2240e8f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -17,7 +17,6 @@ use crate::bibiman::{CurrentArea, FormerArea}; use color_eyre::eyre::{Context, Ok, Result}; -use regex::Regex; // use super::Event; use crate::cliargs::CLIArgs; use crate::tui::commands::InputCmdAction; @@ -26,9 +25,7 @@ use crate::tui::{self, Tui}; use crate::{bibiman::Bibiman, tui::commands::CmdAction}; use core::panic; use std::ffi::OsStr; -use std::fs::{File, OpenOptions}; -use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process::{Command, Stdio}; use tui::Event; use tui_input::backend::crossterm::EventHandler; @@ -271,81 +268,10 @@ impl App { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind { - // Index of selected entry - let entry_idx = self - .bibiman - .entry_table - .entry_table_state - .selected() - .unwrap(); - - // Index of selected popup field - let popup_idx = self.bibiman.popup_area.popup_state.selected().unwrap(); - - // Choose ressource depending an selected popup field - if self.bibiman.popup_area.popup_list[popup_idx].contains("Weblink") { - let object = - self.bibiman.entry_table.entry_table_items[entry_idx].doi_url(); - let url = prepare_weblink(object); - open_connected_link(&url)?; - } else if self.bibiman.popup_area.popup_list[popup_idx].contains("File") { - let object = - self.bibiman.entry_table.entry_table_items[entry_idx].filepath(); - open_connected_file(object)?; - } else { - eprintln!("Unable to find ressource to open"); - }; - // run command to open file/Url - self.bibiman.close_popup() + self.bibiman.open_connected_res()?; } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { - // Index of selected popup field - let popup_idx = self.bibiman.popup_area.popup_state.selected().unwrap(); - - // regex pattern to match citekey in fetched bibtexstring - let pattern = Regex::new(r"\{([^\{\},]*),").unwrap(); - - let citekey = pattern - .captures(&self.bibiman.popup_area.popup_sel_item) - .unwrap() - .get(1) - .unwrap() - .as_str() - .to_string(); - - // Check if new file or existing file was choosen - let mut file = if self.bibiman.popup_area.popup_list[popup_idx] - .contains("Create new file") - { - let citekey = PathBuf::from(&citekey); - // Get path of current files - let path: PathBuf = if args.files[0].is_file() { - args.files[0].parent().unwrap().to_owned() - } else { - dirs::home_dir().unwrap() // home dir as fallback - }; - - let citekey = citekey.with_extension("bib"); - - let newfile = path.join(citekey); - - args.files.push(newfile.clone()); - - File::create_new(newfile).unwrap() - } else { - let file_path = &args.files[popup_idx - 1]; - OpenOptions::new().append(true).open(file_path).unwrap() - }; - // Optionally, add a newline before the content - file.write_all(b"\n")?; - // Write content to file - file.write_all(self.bibiman.popup_area.popup_sel_item.as_bytes())?; - // Update the database and the lists to reflect the new content - self.bibiman.update_lists(args); - self.bibiman.close_popup(); - - // Select newly created entry - self.bibiman.select_entry_by_citekey(&citekey); + self.bibiman.append_entry_to_file(args)? } } } @@ -517,15 +443,4 @@ mod test { assert_eq!(path, PathBuf::from(full_path)) } - - #[test] - fn regex_capture_citekey() { - let re = Regex::new(r"\{([^\{\},]*),").unwrap(); - - let bibstring = String::from("@article{citekey77_2001:!?, author = {Hanks, Tom}, title = {A great book}, year = {2001}}"); - - let result = re.captures(&bibstring).unwrap(); - - assert_eq!(result.get(1).unwrap().as_str(), "citekey77_2001:!?") - } } diff --git a/src/bibiman.rs b/src/bibiman.rs index 5d6aa30..754e8f6 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -15,6 +15,7 @@ // along with this program. If not, see . ///// +use crate::app; use crate::bibiman::entries::EntryTableColumn; use crate::bibiman::{bibisetup::*, search::BibiSearch}; use crate::cliargs::CLIArgs; @@ -22,14 +23,16 @@ use crate::tui::popup::{PopupArea, PopupKind}; use crate::tui::Tui; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::Result; use doi2bib; use editor_command::EditorBuilder; use futures::executor::block_on; use ratatui::widgets::ScrollbarState; +use regex::Regex; use std::fs; -use std::fs::OpenOptions; +use std::fs::{File, OpenOptions}; use std::io::Write; +use std::path::PathBuf; use std::process::Command; use std::result::Result::Ok; use tui_input::Input; @@ -442,6 +445,80 @@ impl Bibiman { self.popup_area.popup_selection(items); } + pub fn append_entry_to_file(&mut self, args: &mut CLIArgs) -> Result<()> { + // Index of selected popup field + let popup_idx = self.popup_area.popup_state.selected().unwrap(); + + // regex pattern to match citekey in fetched bibtexstring + let pattern = Regex::new(r"\{([^\{\},]*),").unwrap(); + + let citekey = pattern + .captures(&self.popup_area.popup_sel_item) + .unwrap() + .get(1) + .unwrap() + .as_str() + .to_string(); + + // Check if new file or existing file was choosen + let mut file = if self.popup_area.popup_list[popup_idx].contains("Create new file") { + let citekey = PathBuf::from(&citekey); + // Get path of current files + let path: PathBuf = if args.files[0].is_file() { + args.files[0].parent().unwrap().to_owned() + } else { + dirs::home_dir().unwrap() // home dir as fallback + }; + + let citekey = citekey.with_extension("bib"); + + let newfile = path.join(citekey); + + args.files.push(newfile.clone()); + + File::create_new(newfile).unwrap() + } else { + let file_path = &args.files[popup_idx - 1]; + OpenOptions::new().append(true).open(file_path).unwrap() + }; + // Optionally, add a newline before the content + file.write_all(b"\n")?; + // Write content to file + file.write_all(self.popup_area.popup_sel_item.as_bytes())?; + // Update the database and the lists to reflect the new content + self.update_lists(args); + self.close_popup(); + + // Select newly created entry + self.select_entry_by_citekey(&citekey); + + Ok(()) + } + + pub fn open_connected_res(&mut self) -> Result<()> { + // Index of selected entry + let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); + + // Index of selected popup field + let popup_idx = self.popup_area.popup_state.selected().unwrap(); + + // Choose ressource depending an selected popup field + if self.popup_area.popup_list[popup_idx].contains("Weblink") { + let object = self.entry_table.entry_table_items[entry_idx].doi_url(); + let url = app::prepare_weblink(object); + app::open_connected_link(&url)?; + } else if self.popup_area.popup_list[popup_idx].contains("File") { + let object = self.entry_table.entry_table_items[entry_idx].filepath(); + app::open_connected_file(object)?; + } else { + eprintln!("Unable to find ressource to open"); + }; + // run command to open file/Url + self.close_popup(); + + Ok(()) + } + /// Formats a raw BibTeX entry string for better readability. pub fn format_bibtex_entry(entry: &str, file_path: &str) -> String { let mut formatted = String::new(); @@ -757,7 +834,7 @@ impl Bibiman { #[cfg(test)] mod tests { - // use super::*; + use super::*; #[test] fn citekey_pattern() { @@ -765,4 +842,15 @@ mod tests { assert_eq!(citekey, "{a_key_2001,") } + + #[test] + fn regex_capture_citekey() { + let re = Regex::new(r"\{([^\{\},]*),").unwrap(); + + let bibstring = String::from("@article{citekey77_2001:!?, author = {Hanks, Tom}, title = {A great book}, year = {2001}}"); + + let result = re.captures(&bibstring).unwrap(); + + assert_eq!(result.get(1).unwrap().as_str(), "citekey77_2001:!?") + } } diff --git a/tests/biblatex-test.bib b/tests/biblatex-test.bib index b366fc3..d0fc0a6 100644 --- a/tests/biblatex-test.bib +++ b/tests/biblatex-test.bib @@ -65,7 +65,7 @@ author = {Aristotle}, location = {New York}, publisher = {G. P. Putnam}, - url = {infobooks.org/authors/classic/aristotle-books/#Physic}, + url = {https://www.infobooks.org/authors/classic/aristotle-books/#Physic}, date = {1929}, translator = {Wicksteed, P. H. and Cornford, F. M.}, keywords = {primary, ancient, philosophy}, -- cgit v1.2.3 From 9a33a794167d60ce35030f007674f6e9424b1ff3 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 23 Dec 2024 21:02:00 +0100 Subject: replace doi2bib with ureq crate --- Cargo.lock | 578 +++------------------------------------------------------ Cargo.toml | 2 +- src/bibiman.rs | 19 +- 3 files changed, 40 insertions(+), 559 deletions(-) (limited to 'src/bibiman.rs') diff --git a/Cargo.lock b/Cargo.lock index 81b976f..ddd8f7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,12 +57,6 @@ dependencies = [ "x11rb", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.4.0" @@ -99,7 +93,6 @@ dependencies = [ "color-eyre", "crossterm", "dirs", - "doi2bib", "editor-command", "futures", "itertools", @@ -112,6 +105,7 @@ dependencies = [ "tokio", "tokio-util", "tui-input", + "ureq", "walkdir", ] @@ -149,12 +143,6 @@ dependencies = [ "objc2", ] -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - [[package]] name = "bytemuck" version = "1.19.0" @@ -290,7 +278,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -392,17 +380,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "doi2bib" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca60cb06bb91c55c99ff39794dafda71dd27d0d7dae2bc1b51acbd709e261fd" -dependencies = [ - "once_cell", - "regex", - "reqwest", -] - [[package]] name = "downcast-rs" version = "1.2.1" @@ -424,15 +401,6 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -508,15 +476,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared 0.1.1", -] - [[package]] name = "foreign-types" version = "0.5.0" @@ -524,7 +483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared 0.3.1", + "foreign-types-shared", ] [[package]] @@ -538,12 +497,6 @@ dependencies = [ "syn", ] -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -675,25 +628,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.15.0" @@ -726,118 +660,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" - -[[package]] -name = "hyper" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.27.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" -dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", - "tokio", - "tokio-rustls", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", -] - [[package]] name = "icu_collections" version = "1.5.0" @@ -1022,12 +844,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ipnet" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" - [[package]] name = "itertools" version = "0.13.0" @@ -1049,16 +865,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" -[[package]] -name = "js-sys" -version = "0.3.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -1140,12 +946,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1184,23 +984,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nix" version = "0.28.0" @@ -1362,50 +1145,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types 0.3.2", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -1640,49 +1379,6 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "reqwest" -version = "0.12.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-tls", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "system-configuration", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "windows-registry", -] - [[package]] name = "ring" version = "0.17.8" @@ -1723,22 +1419,15 @@ version = "0.23.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" dependencies = [ + "log", "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", "zeroize", ] -[[package]] -name = "rustls-pemfile" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "rustls-pki-types" version = "1.10.0" @@ -1777,15 +1466,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -1798,29 +1478,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.6.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.210" @@ -1841,30 +1498,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.133" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -2004,15 +1637,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" -dependencies = [ - "futures-core", -] - [[package]] name = "synstructure" version = "0.13.1" @@ -2024,27 +1648,6 @@ dependencies = [ "syn", ] -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags 2.6.0", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tempfile" version = "3.13.0" @@ -2153,27 +1756,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" -dependencies = [ - "rustls", - "rustls-pki-types", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.12" @@ -2187,12 +1769,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - [[package]] name = "tracing" version = "0.1.40" @@ -2248,12 +1824,6 @@ dependencies = [ "petgraph", ] -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - [[package]] name = "tui-input" version = "0.11.0" @@ -2320,6 +1890,22 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "url", + "webpki-roots", +] + [[package]] name = "url" version = "2.5.4" @@ -2349,12 +1935,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "walkdir" version = "2.5.0" @@ -2365,89 +1945,12 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" -dependencies = [ - "cfg-if", - "once_cell", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" -dependencies = [ - "cfg-if", - "js-sys", - "once_cell", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" - [[package]] name = "wayland-backend" version = "0.3.7" @@ -2522,13 +2025,12 @@ dependencies = [ ] [[package]] -name = "web-sys" -version = "0.3.74" +name = "webpki-roots" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ - "js-sys", - "wasm-bindgen", + "rustls-pki-types", ] [[package]] @@ -2568,36 +2070,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-registry" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" -dependencies = [ - "windows-result", - "windows-strings", - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-result" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-strings" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" -dependencies = [ - "windows-result", - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 34ec65f..ca1f146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ biblatex = "0.10.0" color-eyre = "0.6.3" crossterm = { version = "0.28.1", features = ["event-stream"] } dirs = "5.0.1" -doi2bib = "0.2.0" # doi = "0.3.0" editor-command = "0.1.1" futures = "0.3.30" @@ -36,3 +35,4 @@ tokio-util = "0.7.12" tui-input = "0.11.0" walkdir = "2.5.0" regex = "1.11.1" +ureq = "2.12.1" diff --git a/src/bibiman.rs b/src/bibiman.rs index 754e8f6..0c0d99b 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -24,7 +24,6 @@ use crate::tui::Tui; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; use color_eyre::eyre::Result; -use doi2bib; use editor_command::EditorBuilder; use futures::executor::block_on; use ratatui::widgets::ScrollbarState; @@ -129,12 +128,22 @@ impl Bibiman { /// ///The method needs two arguments: the CLIArgs struct and the `str` containing the DOI pub fn handle_new_entry_submission(&mut self, args: &CLIArgs, doi_string: &str) { - let doi2bib = doi2bib::Doi2Bib::new().unwrap(); - let new_entry_future = doi2bib.resolve_doi(doi_string); - let new_entry = block_on(new_entry_future); + let doi_string = if doi_string.starts_with("10.") { + "https://doi.org/".to_string() + doi_string + } else { + doi_string.to_owned() + }; + + // Send GET request to doi resolver + let doi_entry = ureq::get(&doi_string) + .set("Accept", "application/x-bibtex") + .call(); - if let Ok(entry) = new_entry { + if let Ok(entry) = doi_entry { // Save generated bibtex entry in structs field + let entry = entry + .into_string() + .expect("Couldn't parse fetched entry into string"); self.popup_area.popup_sel_item = entry; self.popup_area.popup_kind = Some(PopupKind::AppendToFile); self.append_to_file(args); -- cgit v1.2.3