aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.rs4
-rw-r--r--src/bibiman.rs6
-rw-r--r--src/config.rs164
-rw-r--r--src/main.rs13
-rw-r--r--src/tui/popup.rs21
-rw-r--r--src/tui/ui.rs243
6 files changed, 167 insertions, 284 deletions
diff --git a/src/app.rs b/src/app.rs
index 7869304..e41defc 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -357,7 +357,7 @@ impl App {
pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> {
// Build command to execute pdf-reader. 'xdg-open' is Linux standard
- let cmd = cfg.general.as_ref().unwrap().pdf_opener.as_ref().unwrap();
+ let cmd = &cfg.general.pdf_opener;
// If necessary, replace ~ with /home dir
let file = PathBuf::from(file);
@@ -377,7 +377,7 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> {
pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> {
// Build command to execute pdf-reader. 'xdg-open' is Linux standard
- let cmd = cfg.general.as_ref().unwrap().url_opener.as_ref().unwrap();
+ let cmd = &cfg.general.url_opener;
// 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)
diff --git a/src/bibiman.rs b/src/bibiman.rs
index b8ef2c6..e36d268 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -85,8 +85,8 @@ impl Bibiman {
// Constructs a new instance of [`App`].
pub fn new(args: &mut CLIArgs, cfg: &mut BibiConfig) -> Result<Self> {
let mut main_bibfiles: Vec<PathBuf> = args.pos_args.clone();
- if cfg.general.as_ref().unwrap().bibfiles.is_some() {
- main_bibfiles.append(cfg.general.as_mut().unwrap().bibfiles.as_mut().unwrap())
+ if cfg.general.bibfiles.is_some() {
+ main_bibfiles.append(cfg.general.bibfiles.as_mut().unwrap())
};
let main_bibfiles = cliargs::parse_files(main_bibfiles);
let main_biblio = BibiSetup::new(&main_bibfiles);
@@ -381,7 +381,7 @@ impl Bibiman {
tui.exit()?;
// Use VISUAL or EDITOR. Set "vi" as last fallback
let mut cmd: Command = EditorBuilder::new()
- .source(cfg.general.as_ref().unwrap().editor.clone())
+ .source(cfg.general.editor.as_ref())
.environment()
.source(Some("vi"))
.build()
diff --git a/src/config.rs b/src/config.rs
index faba5d8..e2c34b9 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -18,147 +18,95 @@
use std::path::PathBuf;
use color_eyre::eyre::Result;
-use config::{ConfigError, FileFormat};
+use figment::{
+ providers::{Format, Serialized, Toml},
+ Figment,
+};
use ratatui::style::Color;
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
use crate::cliargs::CLIArgs;
/// Main struct of the config file. Contains substructs/headings in toml
-#[derive(Debug, Clone, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BibiConfig {
- pub general: Option<General>,
- pub colors: Option<Colors>,
+ pub general: General,
+ pub colors: Colors,
}
/// Substruct [general] in config.toml
-#[derive(Debug, Clone, Deserialize)]
+#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct General {
pub bibfiles: Option<Vec<PathBuf>>,
pub editor: Option<String>,
- pub pdf_opener: Option<String>,
- pub url_opener: Option<String>,
+ pub pdf_opener: String,
+ pub url_opener: String,
}
/// Substruct [colors] in config.toml
-#[derive(Debug, Clone, Deserialize)]
+#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Colors {
- pub main_text_color: Option<Color>,
- pub highlight_text_color: Option<Color>,
- pub entry_color: Option<Color>,
- pub keyword_color: Option<Color>,
- pub info_color: Option<Color>,
- pub confirm_color: Option<Color>,
- pub warn_color: Option<Color>,
- pub bar_bg_color: Option<Color>,
- pub popup_bg_color: Option<Color>,
- pub selected_row_bg_color: Option<Color>,
+ pub main_text_color: Color,
+ pub highlight_text_color: Color,
+ pub entry_color: Color,
+ pub keyword_color: Color,
+ pub info_color: Color,
+ pub confirm_color: Color,
+ pub warn_color: Color,
+ pub bar_bg_color: Color,
+ pub popup_bg_color: Color,
+ pub selected_row_bg_color: Color,
}
impl Default for BibiConfig {
fn default() -> Self {
Self {
- general: Some(General {
+ general: General {
bibfiles: None,
editor: None,
- pdf_opener: Some(select_opener()),
- url_opener: Some(select_opener()),
- }),
- colors: Some(Colors {
- main_text_color: Some(Color::Indexed(250)),
- highlight_text_color: Some(Color::Indexed(254)),
- entry_color: Some(Color::Indexed(36)),
- keyword_color: Some(Color::Indexed(101)),
- info_color: Some(Color::Indexed(99)),
- confirm_color: Some(Color::Indexed(47)),
- warn_color: Some(Color::Indexed(124)),
- bar_bg_color: Some(Color::Indexed(235)),
- popup_bg_color: Some(Color::Indexed(234)),
- selected_row_bg_color: Some(Color::Indexed(237)),
- }),
+ pdf_opener: select_opener(),
+ url_opener: select_opener(),
+ },
+ colors: Colors {
+ main_text_color: Color::Indexed(250),
+ highlight_text_color: Color::Indexed(254),
+ entry_color: Color::Indexed(36),
+ keyword_color: Color::Indexed(101),
+ info_color: Color::Indexed(99),
+ confirm_color: Color::Indexed(47),
+ warn_color: Color::Indexed(124),
+ bar_bg_color: Color::Indexed(235),
+ popup_bg_color: Color::Indexed(234),
+ selected_row_bg_color: Color::Indexed(237),
+ },
}
}
}
impl BibiConfig {
- pub fn parse_config(&mut self, args: &CLIArgs) -> Result<()> {
- if args.cfg_path.is_file() {
- let cfg_file = Self::parse_cfg_file(args)?;
+ pub fn parse_config(args: &CLIArgs) -> Result<BibiConfig> {
+ let cfg_file: BibiConfig = if args.cfg_path.is_file() {
+ Figment::from(Serialized::defaults(BibiConfig::default()))
+ .merge(Toml::file(&args.cfg_path))
+ .extract()?
+ } else {
+ BibiConfig::default()
+ };
- if let Some(general) = cfg_file.general {
- if let Some(bibfiles) = general.bibfiles {
- self.general.as_mut().unwrap().bibfiles = Some(bibfiles)
- }
- if let Some(editor) = general.editor {
- self.general.as_mut().unwrap().editor = Some(editor)
- }
- if let Some(pdf_opener) = general.pdf_opener {
- self.general.as_mut().unwrap().pdf_opener = Some(pdf_opener)
- }
- if let Some(url_opener) = general.url_opener {
- self.general.as_mut().unwrap().url_opener = Some(url_opener)
- }
- }
-
- if let Some(colors) = cfg_file.colors {
- if let Some(main_text_color) = colors.main_text_color {
- self.colors.as_mut().unwrap().main_text_color = Some(main_text_color)
- }
- if let Some(highlight_text_color) = colors.highlight_text_color {
- self.colors.as_mut().unwrap().highlight_text_color = Some(highlight_text_color)
- }
- if let Some(entry_color) = colors.entry_color {
- self.colors.as_mut().unwrap().entry_color = Some(entry_color)
- }
- if let Some(keyword_color) = colors.keyword_color {
- self.colors.as_mut().unwrap().keyword_color = Some(keyword_color)
- }
- if let Some(info_color) = colors.info_color {
- self.colors.as_mut().unwrap().info_color = Some(info_color)
- }
- if let Some(confirm_color) = colors.confirm_color {
- self.colors.as_mut().unwrap().confirm_color = Some(confirm_color)
- }
- if let Some(warn_color) = colors.warn_color {
- self.colors.as_mut().unwrap().warn_color = Some(warn_color)
- }
- if let Some(bar_bg_color) = colors.bar_bg_color {
- self.colors.as_mut().unwrap().bar_bg_color = Some(bar_bg_color)
- }
- if let Some(popup_bg_color) = colors.popup_bg_color {
- self.colors.as_mut().unwrap().popup_bg_color = Some(popup_bg_color)
- }
- if let Some(selected_row_bg_color) = colors.selected_row_bg_color {
- self.colors.as_mut().unwrap().selected_row_bg_color =
- Some(selected_row_bg_color)
- }
- }
- }
-
- Ok(())
- }
-
- fn parse_cfg_file(args: &CLIArgs) -> Result<Self, ConfigError> {
- let mut cfg = config::Config::builder();
- cfg = cfg.add_source(
- config::File::from(args.cfg_path.clone())
- .format(FileFormat::Toml)
- .required(false),
- );
- cfg.build()?.try_deserialize()
+ Ok(cfg_file)
}
/// Activates the default color scheme for light background terminals
pub fn light_colors(&mut self) {
- self.colors.as_mut().unwrap().main_text_color = Some(Color::Indexed(235));
- self.colors.as_mut().unwrap().highlight_text_color = Some(Color::Indexed(232));
- self.colors.as_mut().unwrap().entry_color = Some(Color::Indexed(23));
- self.colors.as_mut().unwrap().keyword_color = Some(Color::Indexed(58));
- self.colors.as_mut().unwrap().info_color = Some(Color::Indexed(57));
- self.colors.as_mut().unwrap().bar_bg_color = Some(Color::Indexed(144));
- self.colors.as_mut().unwrap().popup_bg_color = Some(Color::Indexed(187));
- self.colors.as_mut().unwrap().confirm_color = Some(Color::Indexed(22));
- self.colors.as_mut().unwrap().selected_row_bg_color = Some(Color::Indexed(107));
+ self.colors.main_text_color = Color::Indexed(235);
+ self.colors.highlight_text_color = Color::Indexed(232);
+ self.colors.entry_color = Color::Indexed(23);
+ self.colors.keyword_color = Color::Indexed(58);
+ self.colors.info_color = Color::Indexed(57);
+ self.colors.bar_bg_color = Color::Indexed(144);
+ self.colors.popup_bg_color = Color::Indexed(187);
+ self.colors.confirm_color = Color::Indexed(22);
+ self.colors.selected_row_bg_color = Color::Indexed(107);
}
}
diff --git a/src/main.rs b/src/main.rs
index 3325f80..302ba7a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -46,14 +46,15 @@ async fn main() -> Result<()> {
}
// Build default config
- let mut cfg = BibiConfig::default();
+ // let mut cfg = BibiConfig::default();
- if parsed_args.light_theme {
- cfg.light_colors();
- }
- // Merge values from config file if present
- cfg.parse_config(&parsed_args)?;
+ // if parsed_args.light_theme {
+ // cfg.light_colors();
+ // }
+ // // Merge values from config file if present
+ // cfg.parse_config(&parsed_args)?;
+ let mut cfg = BibiConfig::parse_config(&parsed_args)?;
init_error_hooks()?;
// Create an application.
diff --git a/src/tui/popup.rs b/src/tui/popup.rs
index 6a2e8ff..f226429 100644
--- a/src/tui/popup.rs
+++ b/src/tui/popup.rs
@@ -89,31 +89,16 @@ impl PopupArea {
for (keys, help) in help {
if help == "first" {
helptext.push(Line::from(
- Span::raw(keys).bold().fg(cfg
- .colors
- .as_ref()
- .unwrap()
- .main_text_color
- .unwrap()),
+ Span::raw(keys).bold().fg(cfg.colors.main_text_color),
))
} else if help == "sub" {
helptext.push(Line::from(""));
helptext.push(Line::from(
- Span::raw(keys).bold().fg(cfg
- .colors
- .as_ref()
- .unwrap()
- .main_text_color
- .unwrap()),
+ Span::raw(keys).bold().fg(cfg.colors.main_text_color),
))
} else {
helptext.push(Line::from(vec![
- Span::raw(keys).bold().fg(cfg
- .colors
- .as_ref()
- .unwrap()
- .main_text_color
- .unwrap()),
+ Span::raw(keys).bold().fg(cfg.colors.main_text_color),
Span::raw(help),
]))
}
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 5fbe283..2d58aec 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -150,11 +150,11 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.title_alignment(Alignment::Center)
.style(
Style::new()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()),
+ .fg(cfg.colors.main_text_color)
+ .bg(cfg.colors.popup_bg_color),
)
.border_set(symbols::border::THICK)
- .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()));
+ .border_style(Style::new().fg(cfg.colors.entry_color));
let text: Text = PopupArea::popup_help(cfg);
@@ -191,23 +191,20 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.title_alignment(Alignment::Center)
.style(
Style::new()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()),
+ .fg(cfg.colors.main_text_color)
+ .bg(cfg.colors.popup_bg_color),
)
.border_set(symbols::border::THICK)
- .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()));
+ .border_style(Style::new().fg(cfg.colors.entry_color));
// Prepare the input fields
let content = vec![Line::from(vec![
- Span::styled(
- "DOI: ",
- Style::new().fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()),
- ),
+ Span::styled("DOI: ", Style::new().fg(cfg.colors.entry_color)),
Span::raw(app.input.value().to_string().clone()),
])];
let paragraph = Paragraph::new(content)
.block(block.clone())
- .style(Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()))
+ .style(Style::new().fg(cfg.colors.main_text_color))
.wrap(Wrap { trim: false });
let doi_lines = paragraph.line_count(area.width / 2);
@@ -225,21 +222,17 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
let area = frame.area();
let block = Block::bordered()
- .title_top(
- " Message "
- .bold()
- .fg(cfg.colors.as_ref().unwrap().confirm_color.unwrap()),
- )
- .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().confirm_color.unwrap()))
+ .title_top(" Message ".bold().fg(cfg.colors.confirm_color))
+ .border_style(Style::new().fg(cfg.colors.confirm_color))
.style(
Style::new()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()),
+ .fg(cfg.colors.main_text_color)
+ .bg(cfg.colors.popup_bg_color),
);
let content = Paragraph::new(app.bibiman.popup_area.popup_message.clone())
.block(block)
- .style(Style::new().fg(cfg.colors.as_ref().unwrap().confirm_color.unwrap()));
+ .style(Style::new().fg(cfg.colors.confirm_color));
// Calculate popup size. Width is number of string chars plus 2 for border
let popup_area = popup_area(
@@ -256,21 +249,17 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
let area = frame.area();
let block = Block::bordered()
- .title_top(
- " Warning "
- .bold()
- .fg(cfg.colors.as_ref().unwrap().warn_color.unwrap()),
- )
+ .title_top(" Warning ".bold().fg(cfg.colors.warn_color))
.border_style(Style::new().fg(Color::Red))
.style(
Style::new()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()),
+ .fg(cfg.colors.main_text_color)
+ .bg(cfg.colors.popup_bg_color),
);
let content = Paragraph::new(app.bibiman.popup_area.popup_message.clone())
.block(block)
- .style(Style::new().fg(cfg.colors.as_ref().unwrap().warn_color.unwrap()));
+ .style(Style::new().fg(cfg.colors.warn_color));
// Calculate popup size. Width is number of string chars plus 2 for border
let popup_area = popup_area(
@@ -306,15 +295,15 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.title_alignment(Alignment::Center)
.style(
Style::new()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()),
+ .fg(cfg.colors.main_text_color)
+ .bg(cfg.colors.popup_bg_color),
)
.border_set(symbols::border::THICK)
- .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()));
+ .border_style(Style::new().fg(cfg.colors.keyword_color));
let list = List::new(list_items).block(block).highlight_style(
Style::new()
- // .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ // .fg(cfg.colors.entry_color)
.add_modifier(Modifier::BOLD)
.add_modifier(Modifier::REVERSED),
);
@@ -333,7 +322,7 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
pub fn render_header(cfg: &BibiConfig, frame: &mut Frame, rect: Rect) {
let main_header = Paragraph::new("BIBIMAN – BibLaTeX manager TUI")
.bold()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.centered();
frame.render_widget(main_header, rect)
}
@@ -349,36 +338,29 @@ pub fn render_footer(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: R
let title_lenght: u16 = search_title.chars().count() as u16;
- let block = Block::new().padding(Padding::horizontal(1)).bg(cfg
- .colors
- .as_ref()
- .unwrap()
- .bar_bg_color
- .unwrap());
+ let block = Block::new()
+ .padding(Padding::horizontal(1))
+ .bg(cfg.colors.bar_bg_color);
let search_string = Paragraph::new(Line::from(vec![
Span::styled(
search_title,
if let Some(FormerArea::EntryArea) = app.bibiman.former_area {
Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::BOLD)
} else if let Some(FormerArea::TagArea) = app.bibiman.former_area {
Style::new()
- .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap())
+ .fg(cfg.colors.keyword_color)
.add_modifier(Modifier::BOLD)
} else {
Style::new()
- .fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap())
+ .fg(cfg.colors.highlight_text_color)
.add_modifier(Modifier::BOLD)
},
),
- Span::raw(app.bibiman.search_struct.search_string.clone()).fg(cfg
- .colors
- .as_ref()
- .unwrap()
- .highlight_text_color
- .unwrap()),
+ Span::raw(app.bibiman.search_struct.search_string.clone())
+ .fg(cfg.colors.highlight_text_color),
]))
.block(block);
@@ -400,10 +382,10 @@ pub fn render_file_info(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect
symbols::border::PLAIN
})
.border_style(if let CurrentArea::EntryArea = app.bibiman.current_area {
- Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap())
+ Style::new().fg(cfg.colors.highlight_text_color)
} else {
Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::BOLD)
});
@@ -421,42 +403,33 @@ pub fn render_file_info(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect
&& app.bibiman.main_bibfiles.first().unwrap().is_file()
{
Line::from(vec![
- Span::raw("File: ")
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bold(),
+ Span::raw("File: ").fg(cfg.colors.main_text_color).bold(),
Span::raw(
app.bibiman.main_bibfiles[0]
.file_name()
.unwrap()
.to_string_lossy(),
)
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
+ .fg(cfg.colors.main_text_color)
.bold(),
])
- .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap())
+ .bg(cfg.colors.bar_bg_color)
} else {
Line::from(vec![
Span::raw("Multiple files (")
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
+ .fg(cfg.colors.main_text_color)
.bold(),
Span::raw(count_files(&app.bibiman.main_bibfiles).to_string())
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bold(),
- Span::raw(")")
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
+ .fg(cfg.colors.main_text_color)
.bold(),
+ Span::raw(")").fg(cfg.colors.main_text_color).bold(),
])
- .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap())
+ .bg(cfg.colors.bar_bg_color)
};
let cur_keywords = Line::from(if !app.bibiman.tag_list.selected_keywords.is_empty() {
vec![
- Span::raw("Selected keywords: ").fg(cfg
- .colors
- .as_ref()
- .unwrap()
- .main_text_color
- .unwrap()),
+ Span::raw("Selected keywords: ").fg(cfg.colors.main_text_color),
// Show all keywords in correct order if list is filtered
// successively by multiple keywords
Span::raw(app.bibiman.tag_list.selected_keywords.join(" → "))
@@ -466,7 +439,7 @@ pub fn render_file_info(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect
} else {
vec![Span::raw(" ")]
})
- .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap());
+ .bg(cfg.colors.bar_bg_color);
// .render(keyword_area, buf);
let item_count = Line::from(
@@ -502,42 +475,36 @@ pub fn render_file_info(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect
.to_string()
},
)
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
+ .fg(cfg.colors.main_text_color)
.bold(),
- Span::raw("/").fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()),
- Span::raw(app.bibiman.entry_table.entry_table_items.len().to_string()).fg(cfg
- .colors
- .as_ref()
- .unwrap()
- .main_text_color
- .unwrap()),
+ Span::raw("/").fg(cfg.colors.main_text_color),
+ Span::raw(app.bibiman.entry_table.entry_table_items.len().to_string())
+ .fg(cfg.colors.main_text_color),
]
} else {
vec![Span::raw("No entries")]
},
)
.right_aligned()
- .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap());
+ .bg(cfg.colors.bar_bg_color);
frame.render_widget(file_info, file_area);
frame.render_widget(cur_keywords, keyword_area);
frame.render_widget(item_count, count_area);
}
pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) {
- let entry_box_selected_border_style: Style =
- Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap());
+ let entry_box_selected_border_style: Style = Style::new().fg(cfg.colors.highlight_text_color);
let entry_box_selected_title_style: Style = Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::BOLD);
- let entry_box_unselected_border_style: Style =
- Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap());
+ let entry_box_unselected_border_style: Style = Style::new().fg(cfg.colors.main_text_color);
let entry_box_unselected_title_style: Style = Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::BOLD);
let selected_table_col_style: Style = Style::new().add_modifier(Modifier::BOLD);
let selectec_table_cell_style: Style = Style::new().add_modifier(Modifier::REVERSED);
let entry_selected_row_style: Style = Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::BOLD)
.add_modifier(Modifier::REVERSED);
@@ -567,8 +534,8 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
let header_style = Style::default()
.bold()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap());
+ .fg(cfg.colors.main_text_color)
+ .bg(cfg.colors.bar_bg_color);
let header = Row::new(vec![
Cell::from(
@@ -592,9 +559,9 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
if let EntryTableColumn::Authors =
app.bibiman.entry_table.entry_table_selected_column
{
- cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap()
+ cfg.colors.selected_row_bg_color
} else {
- cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()
+ cfg.colors.bar_bg_color
},
),
),
@@ -618,9 +585,9 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
.bg(
if let EntryTableColumn::Title = app.bibiman.entry_table.entry_table_selected_column
{
- cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap()
+ cfg.colors.selected_row_bg_color
} else {
- cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()
+ cfg.colors.bar_bg_color
},
),
),
@@ -644,9 +611,9 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
.bg(
if let EntryTableColumn::Year = app.bibiman.entry_table.entry_table_selected_column
{
- cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap()
+ cfg.colors.selected_row_bg_color
} else {
- cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()
+ cfg.colors.bar_bg_color
},
),
),
@@ -671,9 +638,9 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
if let EntryTableColumn::Pubtype =
app.bibiman.entry_table.entry_table_selected_column
{
- cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap()
+ cfg.colors.selected_row_bg_color
} else {
- cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()
+ cfg.colors.bar_bg_color
},
),
),
@@ -705,7 +672,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
// args.colors.highlight_text_color,
// 20,
// )),
- Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()),
+ Style::new().fg(cfg.colors.highlight_text_color),
)
.height(1)
});
@@ -760,9 +727,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec
pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) {
// We get the info depending on the item's state.
- let style_value = Style::new()
- .bold()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap());
+ let style_value = Style::new().bold().fg(cfg.colors.main_text_color);
let lines = {
if app
.bibiman
@@ -782,10 +747,7 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
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().fg(cfg.colors.as_ref().unwrap().info_color.unwrap()),
- ),
+ Span::styled(cur_entry.authors(), Style::new().fg(cfg.colors.info_color)),
]));
if cur_entry.subtitle.is_some() {
lines.push(Line::from(vec![
@@ -793,19 +755,19 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
Span::styled(
cur_entry.title(),
Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::ITALIC),
),
Span::styled(
": ",
Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::ITALIC),
),
Span::styled(
cur_entry.subtitle(),
Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::ITALIC),
),
]));
@@ -815,17 +777,14 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
Span::styled(
cur_entry.title(),
Style::new()
- .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())
+ .fg(cfg.colors.entry_color)
.add_modifier(Modifier::ITALIC),
),
]));
}
lines.push(Line::from(vec![
Span::styled("Year: ", style_value),
- Span::styled(
- cur_entry.year(),
- Style::new().fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()),
- ),
+ Span::styled(cur_entry.year(), Style::new().fg(cfg.colors.keyword_color)),
]));
// Render keywords in info box in Markdown code style
if !cur_entry.keywords.is_empty() {
@@ -838,31 +797,25 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
let mut content = vec![Span::styled("Keywords: ", style_value)];
for k in kw {
// Add half block highlighted in bg color to enlarge block
- content.push(
- Span::raw("▐").fg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()),
- );
+ content.push(Span::raw("▐").fg(cfg.colors.bar_bg_color));
content.push(Span::styled(
k,
- Style::default()
- .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap())
- .fg(
- // Highlight selected keyword green
- if app
- .bibiman
- .tag_list
- .selected_keywords
- .iter()
- .any(|e| e == k)
- {
- Color::Green
- } else {
- cfg.colors.as_ref().unwrap().main_text_color.unwrap()
- },
- ),
+ Style::default().bg(cfg.colors.bar_bg_color).fg(
+ // Highlight selected keyword green
+ if app
+ .bibiman
+ .tag_list
+ .selected_keywords
+ .iter()
+ .any(|e| e == k)
+ {
+ Color::Green
+ } else {
+ cfg.colors.main_text_color
+ },
+ ),
));
- content.push(
- Span::raw("▌").fg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()),
- );
+ content.push(Span::raw("▌").fg(cfg.colors.bar_bg_color));
}
lines.push(Line::from(content))
}
@@ -874,9 +827,7 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
Span::styled("DOI/URL: ", style_value),
Span::styled(
cur_entry.doi_url(),
- Style::new()
- .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())
- .underlined(),
+ Style::new().fg(cfg.colors.main_text_color).underlined(),
),
]));
}
@@ -885,14 +836,14 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
Span::styled("File: ", style_value),
Span::styled(
cur_entry.filepath().to_string_lossy(),
- Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()),
+ Style::new().fg(cfg.colors.main_text_color),
),
]));
}
lines.push(Line::from(""));
lines.push(Line::from(vec![Span::styled(
cur_entry.abstract_text.clone(),
- Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()),
+ Style::new().fg(cfg.colors.main_text_color),
)]));
lines
} else {
@@ -909,7 +860,7 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
let block = Block::bordered()
.title(Line::raw(" Entry Information ").centered().bold())
.border_set(symbols::border::PLAIN)
- .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()))
+ .border_style(Style::new().fg(cfg.colors.main_text_color))
.padding(Padding::horizontal(1));
// INFO: '.line_count' method only possible with unstable-rendered-line-info feature -> API might change: https://github.com/ratatui/ratatui/issues/293#ref-pullrequest-2027056434
@@ -963,18 +914,16 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
}
pub fn render_taglist(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) {
- let keyword_box_selected_border_style: Style =
- Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap());
+ let keyword_box_selected_border_style: Style = Style::new().fg(cfg.colors.highlight_text_color);
let keyword_box_selected_title_style: Style = Style::new()
- .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap())
+ .fg(cfg.colors.keyword_color)
.add_modifier(Modifier::BOLD);
- let keyword_box_unselected_border_style: Style =
- Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap());
+ let keyword_box_unselected_border_style: Style = Style::new().fg(cfg.colors.main_text_color);
let keyword_box_unselected_title_style: Style = Style::new()
- .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap())
+ .fg(cfg.colors.keyword_color)
.add_modifier(Modifier::BOLD);
let keyword_selected_row_style: Style = Style::new()
- .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap())
+ .fg(cfg.colors.keyword_color)
.add_modifier(Modifier::BOLD)
.add_modifier(Modifier::REVERSED);
@@ -1018,9 +967,9 @@ pub fn render_taglist(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect:
// args.colors.highlight_text_color,
// 20,
// )
- cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()
+ cfg.colors.highlight_text_color
} else {
- cfg.colors.as_ref().unwrap().main_text_color.unwrap()
+ cfg.colors.main_text_color
},
)) //.bg(color)
})