aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlukeflo2025-01-29 21:24:41 +0100
committerlukeflo2025-01-29 21:24:41 +0100
commitebafb9827c8545a4f3d84db85ee61fb140254ef8 (patch)
tree7fb5435162625661f7f9cd7b92f7dbc9aa0090b0 /src
parentdd108698cfbfda6ba251c75f821f7a4ede9b0608 (diff)
downloadbibiman-ebafb9827c8545a4f3d84db85ee61fb140254ef8.tar.gz
bibiman-ebafb9827c8545a4f3d84db85ee61fb140254ef8.zip
Simplify codebase
+ Remove EntryTableItem struct + Simply use the initial generated BibiData struct + One simple `.clone()`, thus, replaces multiple iterations + Keep all other actions
Diffstat (limited to 'src')
-rw-r--r--src/bibiman.rs4
-rw-r--r--src/bibiman/entries.rs115
2 files changed, 5 insertions, 114 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs
index ee769c4..71288ce 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -332,9 +332,9 @@ impl Bibiman {
.citekey
.clone();
- // Add curly brace as prefix and comma as suffix that only
+ // Add comma as suffix that only
// main citekeys are matched, not other fields like crossref
- let citekey_pattern: String = format!("{{{},", citekey);
+ let citekey_pattern: String = format!("{},", citekey);
// Check if multiple files were passed to bibiman and
// return the correct file path
diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs
index 961e66d..b7c7c9b 100644
--- a/src/bibiman/entries.rs
+++ b/src/bibiman/entries.rs
@@ -15,8 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/////
-use std::ffi::{OsStr, OsString};
-
use crate::bibiman::bibisetup::BibiData;
use ratatui::widgets::{ScrollbarState, TableState};
@@ -44,8 +42,9 @@ pub struct EntryTable {
impl EntryTable {
pub fn new(entry_list: Vec<BibiData>) -> Self {
- // let entry_table_items = Self::set_entry_table(entry_list);
- let entry_table_items = entry_list;
+ let mut entry_table_items = entry_list;
+ entry_table_items.sort_by(|a, b| a.authors.to_lowercase().cmp(&b.authors.to_lowercase()));
+ // entry_table
let entry_table_state = TableState::default()
.with_selected(0)
.with_selected_column(0)
@@ -65,29 +64,6 @@ impl EntryTable {
}
}
- // pub fn set_entry_table(entry_list: &[BibiData]) -> Vec<EntryTableItem> {
- // let mut entry_table: Vec<EntryTableItem> = entry_list
- // .iter()
- // .map(|e| EntryTableItem {
- // id: e.id,
- // authors: &e.authors,
- // short_author: String::new(),
- // title: &e.title,
- // year: &e.year,
- // pubtype: &e.pubtype,
- // keywords: &e.keywords,
- // citekey: &e.citekey,
- // abstract_text: &e.abstract_text,
- // doi_url: e.doi_url.as_deref(),
- // filepath: e.filepath.clone(),
- // subtitle: e.subtitle.as_deref(),
- // })
- // .collect();
-
- // entry_table.sort_by(|a, b| a.authors.to_lowercase().cmp(&b.authors.to_lowercase()));
- // entry_table
- // }
-
pub fn sort_by_id(&mut self) {
if self.entry_table_sorted_by_col.is_some() {
self.entry_table_reversed_sort = false
@@ -152,91 +128,6 @@ impl EntryTable {
}
}
-// // Define contents of each entry table row
-// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
-// pub struct EntryTableItem {
-// pub id: u32,
-// pub authors: String,
-// pub short_author: String,
-// pub title: String,
-// pub year: String,
-// pub pubtype: String,
-// pub keywords: String,
-// pub citekey: String,
-// pub abstract_text: String,
-// pub doi_url: Option<String>,
-// pub filepath: Option<OsString>,
-// pub subtitle: Option<String>,
-// }
-
-// impl EntryTableItem {
-// // This functions decides which fields are rendered in the entry table
-// // Fields which should be usable but not visible can be left out
-// pub fn ref_vec(&mut self) -> Vec<&str> {
-// self.short_author = match self.authors.split_once(",") {
-// Some((first, _rest)) => {
-// if self.authors().contains("(ed.)") {
-// let first_author = format!("{} et al. (ed.)", first);
-// first_author
-// } else {
-// let first_author = format!("{} et al.", first);
-// first_author
-// }
-// }
-// None => String::from(""),
-// };
-
-// vec![
-// {
-// if self.short_author.is_empty() {
-// self.authors()
-// } else {
-// &self.short_author
-// }
-// },
-// self.title(),
-// self.year(),
-// self.pubtype(),
-// ]
-// }
-
-// pub fn entry_id(&self) -> &u32 {
-// &self.id
-// }
-
-// pub fn authors(&self) -> &str {
-// &self.authors
-// }
-
-// pub fn title(&self) -> &str {
-// &self.title
-// }
-
-// pub fn year(&self) -> &str {
-// &self.year
-// }
-
-// pub fn pubtype(&self) -> &str {
-// &self.pubtype
-// }
-
-// pub fn citekey(&self) -> &str {
-// &self.citekey
-// }
-
-// pub fn doi_url(&self) -> &str {
-// self.doi_url.as_ref().unwrap()
-// }
-
-// pub fn filepath(&self) -> &OsStr {
-// self.filepath.as_ref().unwrap()
-// }
-
-// pub fn subtitle(&self) -> &str {
-// self.subtitle.as_ref().unwrap()
-// }
-// }
-
#[cfg(test)]
mod tests {
use crate::bibiman::BibiData;