aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bibiman.rs10
-rw-r--r--src/bibiman/bibisetup.rs37
-rw-r--r--src/bibiman/entries.rs16
-rw-r--r--src/tui/ui.rs6
4 files changed, 35 insertions, 34 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs
index b07512d..a573ee7 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -375,7 +375,7 @@ impl Bibiman {
// Pass filepath as argument, pipe stdout and stderr to /dev/null
// to keep the TUI clean (where is it piped on Windows???)
let _ = Command::new(&cmd)
- .arg(&filepath)
+ .arg(&filepath.as_ref().unwrap())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
@@ -386,7 +386,11 @@ impl Bibiman {
pub fn open_doi_url(&mut self) -> Result<()> {
let idx = self.entry_table.entry_table_state.selected().unwrap();
- let web_adress = self.entry_table.entry_table_items[idx].doi_url.clone();
+ let web_adress = self.entry_table.entry_table_items[idx]
+ .doi_url
+ .as_ref()
+ .unwrap();
+ // .clone();
// Resolve strings using the resolving function of dx.doi.org, so the
// terminal is not blocked by the resolving process
@@ -397,7 +401,7 @@ impl Bibiman {
let prefix = "https://".to_string();
prefix + &web_adress
} else {
- web_adress
+ web_adress.to_string()
};
// Build command to execute browser. 'xdg-open' is Linux standard
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs
index e17997d..027e217 100644
--- a/src/bibiman/bibisetup.rs
+++ b/src/bibiman/bibisetup.rs
@@ -51,8 +51,8 @@ pub struct BibiData {
pub keywords: String,
pub citekey: String,
pub abstract_text: String,
- pub doi_url: String,
- pub filepath: String,
+ pub doi_url: Option<String>,
+ pub filepath: Option<String>,
pub subtitle: Option<String>,
}
@@ -219,10 +219,11 @@ impl BibiSetup {
}
pub fn get_year(citekey: &str, biblio: &Bibliography) -> String {
- let year = biblio.get(&citekey).unwrap();
+ let bib = biblio.get(&citekey).unwrap();
+ // let year = biblio.get(&citekey).unwrap();
let year = {
- if year.date().is_ok() {
- let year = year.date().unwrap().to_chunks().format_verbatim();
+ if bib.date().is_ok() {
+ let year = bib.date().unwrap().to_chunks().format_verbatim();
let year = year[..4].to_string();
year
} else {
@@ -274,26 +275,22 @@ impl BibiSetup {
text
}
- pub fn get_weblink(citekey: &str, biblio: &Bibliography) -> String {
- if let true = biblio.get(&citekey).unwrap().doi().is_ok() {
- let url = biblio.get(&citekey).unwrap().doi().unwrap();
- url
- } else if let true = biblio.get(&citekey).unwrap().url().is_ok() {
- let url = biblio.get(&citekey).unwrap().url().unwrap();
- url
+ pub fn get_weblink(citekey: &str, biblio: &Bibliography) -> Option<String> {
+ let bib = biblio.get(&citekey).unwrap();
+ if bib.doi().is_ok() {
+ Some(bib.doi().unwrap())
+ } else if bib.url().is_ok() {
+ Some(bib.url().unwrap())
} else {
- let url = "".to_string();
- url
+ None
}
}
- pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> String {
- if let true = biblio.get(&citekey).unwrap().file().is_ok() {
- let file = biblio.get(&citekey).unwrap().file().unwrap();
- file
+ pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> Option<String> {
+ if biblio.get(&citekey).unwrap().file().is_ok() {
+ Some(biblio.get(&citekey).unwrap().file().unwrap())
} else {
- let file = "".to_string();
- file
+ None
}
}
diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs
index 025b696..d8fadcc 100644
--- a/src/bibiman/entries.rs
+++ b/src/bibiman/entries.rs
@@ -139,8 +139,8 @@ pub struct EntryTableItem {
pub keywords: String,
pub citekey: String,
pub abstract_text: String,
- pub doi_url: String,
- pub filepath: String,
+ pub doi_url: Option<String>,
+ pub filepath: Option<String>,
pub subtitle: Option<String>,
}
@@ -196,11 +196,11 @@ impl EntryTableItem {
}
pub fn doi_url(&self) -> &str {
- &self.doi_url
+ &self.doi_url.as_ref().unwrap()
}
pub fn filepath(&self) -> &str {
- &self.filepath
+ &self.filepath.as_ref().unwrap()
}
pub fn subtitle(&self) -> &str {
@@ -234,8 +234,8 @@ mod tests {
keywords: "key1, key2".to_string(),
citekey: "miller_2000".to_string(),
abstract_text: "An abstract".to_string(),
- doi_url: "www.text.org".to_string(),
- filepath: "/home/test".to_string(),
+ doi_url: None,
+ filepath: None,
subtitle: None,
};
@@ -250,8 +250,8 @@ mod tests {
keywords: "key1, key2".to_string(),
citekey: "miller_2000".to_string(),
abstract_text: "An abstract".to_string(),
- doi_url: "www.text.org".to_string(),
- filepath: "/home/test".to_string(),
+ doi_url: None,
+ filepath: None,
subtitle: None,
};
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 79d1ecc..f2091a5 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -610,16 +610,16 @@ pub fn render_selected_item(app: &mut App, frame: &mut Frame, rect: Rect) {
}
lines.push(Line::from(content))
}
- if !cur_entry.doi_url.is_empty() || !cur_entry.filepath.is_empty() {
+ if cur_entry.doi_url.is_some() || cur_entry.filepath.is_some() {
lines.push(Line::raw(""));
}
- if !cur_entry.doi_url.is_empty() {
+ if cur_entry.doi_url.is_some() {
lines.push(Line::from(vec![
Span::styled("DOI/URL: ", style_value),
Span::styled(cur_entry.doi_url(), INFO_STYLE_DOI.underlined()),
]));
}
- if !cur_entry.filepath.is_empty() {
+ if cur_entry.filepath.is_some() {
lines.push(Line::from(vec![
Span::styled("File: ", style_value),
Span::styled(cur_entry.filepath(), INFO_STYLE_FILE),