aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlukeflo2024-11-01 12:55:03 +0100
committerlukeflo2024-11-01 12:55:03 +0100
commitc7034560c408f48a16a10546ed8d04ae879ab9ef (patch)
treea9ac9533638aef87fb72d0963510f901dbf7ff33 /src
parentf55e1d90ca522f86f8f57d44c17dbd45d8fdf97e (diff)
downloadbibiman-c7034560c408f48a16a10546ed8d04ae879ab9ef.tar.gz
bibiman-c7034560c408f48a16a10546ed8d04ae879ab9ef.zip
subtitle field, const for info value styles
Diffstat (limited to 'src')
-rw-r--r--src/bibiman/bibisetup.rs17
-rw-r--r--src/bibiman/entries.rs8
-rw-r--r--src/tui/ui.rs37
3 files changed, 50 insertions, 12 deletions
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs
index abc91e4..a743856 100644
--- a/src/bibiman/bibisetup.rs
+++ b/src/bibiman/bibisetup.rs
@@ -50,6 +50,7 @@ pub struct BibiData {
pub abstract_text: String,
pub doi_url: String,
pub filepath: String,
+ pub subtitle: Option<String>,
}
impl BibiSetup {
@@ -99,6 +100,7 @@ impl BibiSetup {
abstract_text: Self::get_abstract(&k, &bibliography),
doi_url: Self::get_weblink(&k, &bibliography),
filepath: Self::get_filepath(&k, &bibliography),
+ subtitle: Self::get_subtitle(&k, &bibliography),
})
.collect()
}
@@ -276,4 +278,19 @@ impl BibiSetup {
file
}
}
+
+ pub fn get_subtitle(citekey: &str, biblio: &Bibliography) -> Option<String> {
+ if biblio.get(&citekey).unwrap().subtitle().is_ok() {
+ Some(
+ biblio
+ .get(&citekey)
+ .unwrap()
+ .subtitle()
+ .unwrap()
+ .format_verbatim(),
+ )
+ } else {
+ None
+ }
+ }
}
diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs
index 695ad24..7b19c38 100644
--- a/src/bibiman/entries.rs
+++ b/src/bibiman/entries.rs
@@ -76,6 +76,7 @@ impl EntryTable {
abstract_text: e.abstract_text,
doi_url: e.doi_url,
filepath: e.filepath,
+ subtitle: e.subtitle,
})
.collect();
@@ -140,6 +141,7 @@ pub struct EntryTableItem {
pub abstract_text: String,
pub doi_url: String,
pub filepath: String,
+ pub subtitle: Option<String>,
}
impl EntryTableItem {
@@ -200,6 +202,10 @@ impl EntryTableItem {
pub fn filepath(&self) -> &str {
&self.filepath
}
+
+ pub fn subtitle(&self) -> &str {
+ &self.subtitle.as_ref().unwrap()
+ }
}
#[cfg(test)]
@@ -230,6 +236,7 @@ mod tests {
abstract_text: "An abstract".to_string(),
doi_url: "www.text.org".to_string(),
filepath: "/home/test".to_string(),
+ subtitle: None,
};
let entry_vec = EntryTableItem::ref_vec(&mut entry);
@@ -245,6 +252,7 @@ mod tests {
abstract_text: "An abstract".to_string(),
doi_url: "www.text.org".to_string(),
filepath: "/home/test".to_string(),
+ subtitle: None,
};
let entry_vec_editors = EntryTableItem::ref_vec(&mut entry_editors);
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 6c110a0..7ee6670 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -62,6 +62,13 @@ const HEADER_FOOTER_BG: Color = Color::Indexed(235);
const SCROLLBAR_UPPER_CORNER: Option<&str> = Some("┓");
const SCROLLBAR_LOWER_CORNER: Option<&str> = Some("┛");
+const INFO_STYLE_AUTHOR: Style = Style::new().fg(Color::Green);
+const INFO_STYLE_TITLE: Style = Style::new().fg(Color::Magenta);
+const INFO_STYLE_YEAR: Style = Style::new().fg(Color::LightMagenta);
+const INFO_STYLE_DOI: Style = Style::new().fg(TEXT_FG_COLOR);
+const INFO_STYLE_FILE: Style = Style::new().fg(TEXT_FG_COLOR);
+const INFO_STYLE_ABSTRACT: Style = Style::new().fg(TEXT_FG_COLOR);
+
pub const fn alternate_colors(i: usize) -> Color {
if i % 2 == 0 {
NORMAL_ROW_BG
@@ -503,15 +510,24 @@ pub fn render_selected_item(app: &mut App, frame: &mut Frame, rect: Rect) {
lines.push(Line::from(vec![
Span::styled("Authors: ", style_value),
// Span::styled(cur_entry.authors.clone(), Style::new().green()),
- Span::styled(cur_entry.authors(), Style::new().green()),
- ]));
- lines.push(Line::from(vec![
- Span::styled("Title: ", style_value),
- Span::styled(cur_entry.title(), Style::new().magenta()),
+ Span::styled(cur_entry.authors(), INFO_STYLE_AUTHOR),
]));
+ if cur_entry.subtitle.is_some() {
+ lines.push(Line::from(vec![
+ Span::styled("Title: ", style_value),
+ Span::styled(cur_entry.title(), INFO_STYLE_TITLE),
+ Span::styled(": ", INFO_STYLE_TITLE),
+ Span::styled(cur_entry.subtitle(), INFO_STYLE_TITLE),
+ ]));
+ } else {
+ lines.push(Line::from(vec![
+ Span::styled("Title: ", style_value),
+ Span::styled(cur_entry.title(), INFO_STYLE_TITLE),
+ ]));
+ }
lines.push(Line::from(vec![
Span::styled("Year: ", style_value),
- Span::styled(cur_entry.year(), Style::new().light_magenta()),
+ Span::styled(cur_entry.year(), INFO_STYLE_YEAR),
]));
// Render keywords in info box in Markdown code style
if !cur_entry.keywords.is_empty() {
@@ -552,22 +568,19 @@ pub fn render_selected_item(app: &mut App, frame: &mut Frame, rect: Rect) {
if !cur_entry.doi_url.is_empty() {
lines.push(Line::from(vec![
Span::styled("DOI/URL: ", style_value_sec),
- Span::styled(
- cur_entry.doi_url(),
- Style::default().fg(TEXT_FG_COLOR).underlined(),
- ),
+ Span::styled(cur_entry.doi_url(), INFO_STYLE_DOI.underlined()),
]));
}
if !cur_entry.filepath.is_empty() {
lines.push(Line::from(vec![
Span::styled("File: ", style_value_sec),
- Span::styled(cur_entry.filepath(), Style::default().fg(TEXT_FG_COLOR)),
+ Span::styled(cur_entry.filepath(), INFO_STYLE_FILE),
]));
}
lines.push(Line::from(""));
lines.push(Line::from(vec![Span::styled(
cur_entry.abstract_text.clone(),
- Style::default().fg(TEXT_FG_COLOR),
+ INFO_STYLE_ABSTRACT,
)]));
lines
} else {