git-delta-lib 0.0.1

Not ready for use: use crate git-delta for the application
Documentation
use std::io::{self, ErrorKind, Read};

use crate::cli;
use crate::config;
use crate::delta;
use crate::git_config;
use crate::options::get::get_themes;
use crate::utils::bat::output::{OutputType, PagingMode};

pub fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> std::io::Result<()> {
    use std::io::BufReader;

    use bytelines::ByteLines;

    use super::sample_diff::DIFF;

    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 git_config = git_config::GitConfig::try_create();
    let opt =
        cli::Opt::from_iter_and_git_config(&["", "", "--navigate", "--show-themes"], git_config);
    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 &get_themes(git_config::GitConfig::try_create()) {
        let git_config = git_config::GitConfig::try_create();
        let opt = cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], git_config);
        let is_dark_theme = opt.dark;
        let is_light_theme = opt.light;
        let config = config::Config::from(opt);

        if (!computed_theme_is_light && is_dark_theme)
            || (computed_theme_is_light && is_light_theme)
            || (dark && light)
        {
            writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?;

            if let Err(error) =
                delta::delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config)
            {
                match error.kind() {
                    ErrorKind::BrokenPipe => std::process::exit(0),
                    _ => eprintln!("{}", error),
                }
            }
        }
    }

    Ok(())
}