From a1e42432f4413b54249700e59494e261f5718f3a Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 27 Mar 2021 19:46:08 -0400 Subject: Reorganize and add test for get_themes --- src/main.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a90d4871..fb4628ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,6 @@ mod style; mod syntect_color; mod tests; -use lazy_static::lazy_static; -use regex::Regex; use std::io::{self, ErrorKind, Read, Write}; use std::path::PathBuf; use std::process; @@ -41,6 +39,7 @@ use crate::bat_utils::assets::{list_languages, HighlightingAssets}; use crate::bat_utils::output::{OutputType, PagingMode}; use crate::config::delta_unreachable; use crate::delta::delta; +use crate::options::get::get_themes; use crate::options::theme::is_light_syntax_theme; pub mod errors { @@ -313,30 +312,6 @@ where } } -lazy_static! { - static ref GIT_CONFIG_THEME_REGEX: Regex = Regex::new(r"^delta\.(.+)\.is-theme$").unwrap(); -} - -fn get_themes() -> Vec { - let _git_config = git_config::GitConfig::try_create(); - let mut themes: Vec = Vec::new(); - for e in &_git_config.unwrap().config.entries(None).unwrap() { - let entry = e.unwrap(); - let entry_name = entry.name().unwrap(); - let entry_value = entry.value().unwrap(); - dbg!(entry_name, entry_value); - if entry_value == "true" { - let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); - if let Some(caps) = caps { - // need to check value i.e. whether is_theme = false - let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); - themes.push(name) - } - } - } - themes -} - fn show_themes() -> std::io::Result<()> { use bytelines::ByteLines; use sample_diff::DIFF; @@ -361,7 +336,7 @@ fn show_themes() -> std::io::Result<()> { let title_style = ansi_term::Style::new().bold(); let writer = output_type.handle().unwrap(); - for theme in &get_themes() { + for theme in &get_themes(git_config::GitConfig::try_create()) { writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?; let opt = cli::Opt::from_iter_and_git_config(&["", "", "--features", &theme], &mut git_config); -- cgit v1.2.3