aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bibiman/bibisetup.rs42
-rw-r--r--src/config.rs11
-rw-r--r--src/tui/ui.rs34
3 files changed, 51 insertions, 36 deletions
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs
index 61d1fcf..1f8a912 100644
--- a/src/bibiman/bibisetup.rs
+++ b/src/bibiman/bibisetup.rs
@@ -56,16 +56,16 @@ pub struct BibiData {
pub file_field: bool,
pub subtitle: Option<String>,
pub notes: Option<Vec<OsString>>,
- pub symbols: [String; 3],
+ pub symbols: [Option<String>; 3],
}
#[derive(Debug, Clone, PartialEq)]
-pub struct BibiRow {
- pub authors: String,
- pub title: String,
- pub year: String,
- pub pubtype: String,
- pub symbols: [String; 3],
+pub struct BibiRow<'a> {
+ pub authors: &'a str,
+ pub title: &'a str,
+ pub year: &'a str,
+ pub pubtype: &'a str,
+ pub symbols: &'a [Option<String>; 3],
}
impl BibiData {
@@ -104,15 +104,15 @@ impl BibiData {
BibiRow {
authors: {
if self.short_author.is_empty() {
- self.authors().to_string()
+ self.authors()
} else {
- self.short_author.clone()
+ &self.short_author
}
},
- title: self.title().to_string(),
- year: self.year().to_string(),
- pubtype: self.pubtype().to_string(),
- symbols: self.symbols.clone(),
+ title: self.title(),
+ year: self.year(),
+ pubtype: self.pubtype(),
+ symbols: &self.symbols,
}
}
@@ -160,22 +160,22 @@ impl BibiData {
self.subtitle.as_ref().unwrap()
}
- fn create_symbols(&self, cfg: &BibiConfig) -> [String; 3] {
+ fn create_symbols(&self, cfg: &BibiConfig) -> [Option<String>; 3] {
[
if self.file_field || self.filepath.is_some() {
- cfg.general.file_symbol.clone()
+ Some(cfg.general.file_symbol.clone())
} else {
- " ".to_string()
+ None
},
if self.doi_url.is_some() {
- cfg.general.link_symbol.clone()
+ Some(cfg.general.link_symbol.clone())
} else {
- " ".to_string()
+ None
},
if self.notes.is_some() {
- cfg.general.note_symbol.clone()
+ Some(cfg.general.note_symbol.clone())
} else {
- " ".to_string()
+ None
},
]
}
@@ -294,7 +294,7 @@ impl BibiSetup {
} else {
None
},
- symbols: [String::new(), String::new(), String::new()],
+ symbols: [None, None, None],
}
})
.collect()
diff --git a/src/config.rs b/src/config.rs
index 6723ce0..f67cb9d 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -62,6 +62,11 @@ const DEFAULT_CONFIG: &str = r##"
# note_path = "/path/to/notes/folder"
# note_extensions = [ "md", "txt", "org" ]
+## Symbols/chars to show if not has specific attachement
+# note_symbol = "N"
+# file_symbol = "F"
+# link_symbol = "L"
+
# [colors]
## Default values for dark-themed terminal
## Possible values are:
@@ -78,6 +83,12 @@ const DEFAULT_CONFIG: &str = r##"
# bar_bg_color = "234"
# popup_bg_color = "234"
# selected_row_bg_color = "237"
+# note_color = "123"
+# file_color = "209"
+# link_color = "27"
+# author_color = "38"
+# title_color = "37"
+# year_color = "135"
"##;
/// Main struct of the config file. Contains substructs/headings in toml
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 970a71d..5904f88 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -701,25 +701,24 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
.map(|(_i, data)| {
let item = data.ref_vec(cfg);
+ let mut symbol_vec = vec![];
+
+ if let Some(f) = &item.symbols[0] {
+ symbol_vec.push(Span::styled(f, Style::new().fg(cfg.colors.file_color)));
+ }
+ if let Some(l) = &item.symbols[1] {
+ symbol_vec.push(Span::styled(l, Style::new().fg(cfg.colors.link_color)));
+ }
+ if let Some(n) = &item.symbols[2] {
+ symbol_vec.push(Span::styled(n, Style::new().fg(cfg.colors.note_color)))
+ }
+
let row = Row::new(vec![
Cell::from(Line::from(item.authors)),
Cell::from(Line::from(item.title)),
Cell::from(Line::from(item.year)),
Cell::from(Line::from(item.pubtype)),
- Cell::from(Line::from(vec![
- Span::styled(
- item.symbols[0].clone(),
- Style::new().fg(cfg.colors.file_color),
- ),
- Span::styled(
- item.symbols[1].clone(),
- Style::new().fg(cfg.colors.link_color),
- ),
- Span::styled(
- item.symbols[2].clone(),
- Style::new().fg(cfg.colors.note_color),
- ),
- ])),
+ Cell::from(Line::from(symbol_vec)),
]);
// let row = item
@@ -751,7 +750,12 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
},
),
Constraint::Percentage(10),
- Constraint::Length(4),
+ Constraint::Length(
+ (cfg.general.file_symbol.chars().count()
+ + cfg.general.link_symbol.chars().count()
+ + cfg.general.note_symbol.chars().count()
+ + 1) as u16,
+ ),
],
)
.block(block)