summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorCatherine Noll <noll.catherine@gmail.com>2021-03-27 19:46:08 -0400
committerCatherine Noll <noll.catherine@gmail.com>2021-03-27 19:46:08 -0400
commita1e42432f4413b54249700e59494e261f5718f3a (patch)
tree26afe4c4095ac28afe82f9fd1f34d1703ca1ff80 /src/main.rs
parentcbbc1aab01db4caa24872fd402567d1fc8ee49c3 (diff)
Reorganize and add test for get_themes
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs29
1 files changed, 2 insertions, 27 deletions
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<String> {
- let _git_config = git_config::GitConfig::try_create();
- let mut themes: Vec<String> = 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);