diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bibiman/bibisetup.rs | 67 | ||||
| -rw-r--r-- | src/config.rs | 9 | ||||
| -rw-r--r-- | src/tui/ui.rs | 63 |
3 files changed, 104 insertions, 35 deletions
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index 61144a1..61d1fcf 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -56,12 +56,22 @@ pub struct BibiData { pub file_field: bool, pub subtitle: Option<String>, pub notes: Option<Vec<OsString>>, + pub symbols: [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], } impl BibiData { // 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> { + pub fn ref_vec(&mut self, cfg: &BibiConfig) -> BibiRow { self.short_author = match self.authors.split_once(",") { Some((first, _rest)) => { if self.authors().contains("(ed.)") { @@ -75,19 +85,35 @@ impl BibiData { None => String::from(""), }; - vec![ - "", - { + self.symbols = self.create_symbols(cfg); + + // vec![ + // { + // if self.short_author.is_empty() { + // self.authors() + // } else { + // &self.short_author + // } + // }, + // self.title(), + // self.year(), + // self.pubtype(), + // &self.symbols, + // ] + + BibiRow { + authors: { if self.short_author.is_empty() { - self.authors() + self.authors().to_string() } else { - &self.short_author + self.short_author.clone() } }, - self.title(), - self.year(), - self.pubtype(), - ] + title: self.title().to_string(), + year: self.year().to_string(), + pubtype: self.pubtype().to_string(), + symbols: self.symbols.clone(), + } } pub fn entry_id(&self) -> &u32 { @@ -133,6 +159,26 @@ impl BibiData { pub fn subtitle(&self) -> &str { self.subtitle.as_ref().unwrap() } + + fn create_symbols(&self, cfg: &BibiConfig) -> [String; 3] { + [ + if self.file_field || self.filepath.is_some() { + cfg.general.file_symbol.clone() + } else { + " ".to_string() + }, + if self.doi_url.is_some() { + cfg.general.link_symbol.clone() + } else { + " ".to_string() + }, + if self.notes.is_some() { + cfg.general.note_symbol.clone() + } else { + " ".to_string() + }, + ] + } } impl BibiSetup { @@ -248,6 +294,7 @@ impl BibiSetup { } else { None }, + symbols: [String::new(), String::new(), String::new()], } }) .collect() diff --git a/src/config.rs b/src/config.rs index c30d8d1..6723ce0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -98,6 +98,9 @@ pub struct General { pub pdf_path: Option<PathBuf>, pub note_path: Option<PathBuf>, pub note_extensions: Option<Vec<String>>, + pub note_symbol: String, + pub file_symbol: String, + pub link_symbol: String, } /// Substruct [colors] in config.toml @@ -133,6 +136,9 @@ impl Default for BibiConfig { pdf_path: None, note_path: None, note_extensions: None, + note_symbol: String::from("N"), + file_symbol: String::from("F"), + link_symbol: String::from("L"), }, colors: Self::dark_colors(), } @@ -151,6 +157,9 @@ impl BibiConfig { pdf_path: None, note_path: None, note_extensions: None, + note_symbol: String::from("N"), + file_symbol: String::from("F"), + link_symbol: String::from("L"), }, colors: if args.light_theme { Self::light_colors() diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 95b9f2c..970a71d 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -580,7 +580,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .bg(cfg.colors.bar_bg_color); let header = Row::new(vec![ - Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), + // Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), Cell::from( Line::from(vec![{ Span::raw("Author") }, { if let Some(EntryTableColumn::Authors) = @@ -699,34 +699,46 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .iter_mut() .enumerate() .map(|(_i, data)| { - let item = data.ref_vec(); - item.into_iter() - .map(|content| Cell::from(Text::from(content.to_string()))) - .collect::<Row>() - .style( - // Style::new().fg(color_list( - // args, - // i as i32, - // app.bibiman - // .entry_table - // .entry_table_state - // .selected() - // .unwrap_or(0) as i32, - // args.colors.highlight_text_color, - // 20, - // )), - Style::new().fg(if let CurrentArea::EntryArea = app.bibiman.current_area { - cfg.colors.highlight_text_color - } else { - cfg.colors.main_text_color - }), - ) - .height(1) + let item = data.ref_vec(cfg); + + 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), + ), + ])), + ]); + + // let row = item + // .into_iter() + // .map(|content| Cell::from(Text::from(content.to_string()))) + // .collect::<Row>(); + + row.style( + Style::new().fg(if let CurrentArea::EntryArea = app.bibiman.current_area { + cfg.colors.highlight_text_color + } else { + cfg.colors.main_text_color + }), + ) + .height(1) }); let entry_table = Table::new( rows, [ - Constraint::Length(4), Constraint::Percentage(20), Constraint::Fill(1), Constraint::Length( @@ -739,6 +751,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec }, ), Constraint::Percentage(10), + Constraint::Length(4), ], ) .block(block) |
