From e561a51371365da845e13b91617cc0aaa2d92ef1 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 20 Mar 2021 20:39:01 -0500 Subject: Apply themes to a hardcoded diff --- src/cli.rs | 2 -- src/main.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index 78c3e179..781fd644 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,4 @@ use std::collections::{HashMap, HashSet}; -#[cfg(test)] use std::ffi::OsString; use std::path::PathBuf; @@ -641,7 +640,6 @@ impl Opt { Self::from_clap_and_git_config(Self::clap().get_matches(), git_config, assets) } - #[cfg(test)] pub fn from_iter_and_git_config(iter: I, git_config: &mut Option) -> Self where I: IntoIterator, diff --git a/src/main.rs b/src/main.rs index 8fd8dd10..82e41536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -313,6 +313,25 @@ const THEMES: [&'static str; 4] = [ ]; fn show_themes() -> std::io::Result<()> { + use bytelines::ByteLines; + use std::io::BufReader; + let input = b"\ +diff --git a/example.rs b/example.rs +index f38589a..0f1bb83 100644 +--- a/example.rs ++++ b/example.rs +@@ -1,5 +1,5 @@ +-// Output the square of a number. +-fn print_square(num: f64) { +- let result = f64::powf(num, 2.0); +- println!(\"The square of {:.2} is {:.2}.\", num, result); ++// Output the cube of a number. ++fn print_cube(num: f64) { ++ let result = f64::powf(num, 3.0); ++ println!(\"The cube of {:.2} is {:.2}.\", num, result); +" + .to_vec(); + let mut output_type = OutputType::from_mode( PagingMode::QuitIfOneScreen, None, @@ -324,6 +343,17 @@ fn show_themes() -> std::io::Result<()> { for theme in &THEMES { writeln!(writer, "\n\nTheme: {}\n", title_style.paint(*theme))?; + let opt = cli::Opt::from_iter_and_git_config( + &["", "", "--features", theme], + &mut git_config::GitConfig::try_create(), + ); + let config = config::Config::from(opt); + if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { + match error.kind() { + ErrorKind::BrokenPipe => process::exit(0), + _ => eprintln!("{}", error), + } + }; } Ok(()) -- cgit v1.2.3