diff options
author | Catherine Noll <noll.catherine@gmail.com> | 2021-03-20 23:08:27 -0500 |
---|---|---|
committer | Catherine Noll <noll.catherine@gmail.com> | 2021-03-21 11:38:31 -0500 |
commit | 43f971512594d931b97a61313612601ea5af6d0c (patch) | |
tree | 9340bea550805781e2b0df5fd4337fa1af7ce674 /src | |
parent | cc1bf64939f3ae6af21dc258e4a5aeb78d202ecb (diff) |
Add functionality to cycle through themes using a diff from stdin
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs index b03b95a3..d48a2961 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,31 +315,30 @@ const THEMES: [&'static str; 4] = [ fn show_themes() -> std::io::Result<()> { use bytelines::ByteLines; - use std::io::BufReader; use sample_diff::DIFF; - let input = &DIFF.to_vec(); + use std::io::BufReader; + let mut input = DIFF.to_vec(); + + if !atty::is(atty::Stream::Stdin) { + let mut buf = Vec::new(); + io::stdin().lock().read_to_end(&mut buf)?; + if !buf.is_empty() { + input = buf; + } + }; let mut git_config = git_config::GitConfig::try_create(); - let opt = cli::Opt::from_iter_and_git_config( - &["", "", "--navigate"], - &mut git_config, - ); + let opt = cli::Opt::from_iter_and_git_config(&["", "", "--navigate"], &mut git_config); - let mut output_type = OutputType::from_mode( - PagingMode::Always, - None, - &config::Config::from(opt), - ) - .unwrap(); + let mut output_type = + OutputType::from_mode(PagingMode::Always, None, &config::Config::from(opt)).unwrap(); let title_style = ansi_term::Style::new().bold(); let writer = output_type.handle().unwrap(); 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, - ); + let opt = + cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], &mut git_config); let config = config::Config::from(opt); if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { match error.kind() { |