use std::collections::{HashMap, HashSet};
use std::ffi::OsString;
use std::path::{Path, PathBuf};
use bat::assets::HighlightingAssets;
use clap::{ColorChoice, CommandFactory, FromArgMatches, Parser};
use lazy_static::lazy_static;
use syntect::highlighting::Theme as SyntaxTheme;
use syntect::parsing::SyntaxSet;
use crate::config::delta_unreachable;
use crate::env::DeltaEnv;
use crate::git_config::GitConfig;
use crate::options;
use crate::utils;
use crate::utils::bat::output::PagingMode;
#[derive(Parser)]
#[command(
name = "delta",
about = "A viewer for git and diff output",
version,
color = ColorChoice::Always,
term_width(0),
after_long_help = "\
GIT CONFIG
----------
By default, delta takes settings from a section named \"delta\" in git config files, if one is present. The git config file to use for delta options will usually be ~/.gitconfig, but delta follows the rules given in https://git-scm.com/docs/git-config#FILES. Most delta options can be given in a git config file, using the usual option names but without the initial '--'. An example is
[delta]
line-numbers = true
zero-style = dim syntax
FEATURES
--------
A feature is a named collection of delta options in git config. An example is:
[delta \"my-delta-feature\"]
syntax-theme = Dracula
plus-style = bold syntax \"#002800\"
To activate those options, you would use:
delta --features my-delta-feature
A feature name may not contain whitespace. You can activate multiple features:
[delta]
features = my-highlight-styles-colors-feature my-line-number-styles-feature
If more than one feature sets the same option, the last one wins.
If an option is present in the [delta] section, then features are not considered at all.
If you want an option to be fully overridable by a feature and also have a non default value when no features are used, then you need to define a \"default\" feature and include it in the main delta configuration.
For instance:
[delta]
feature = default-feature
[delta \"default-feature\"]
width = 123
At this point, you can override features set in the command line or in the environment variables and the \"last one wins\" rules will apply as expected.
STYLES
------
All options that have a name like --*-style work the same way. It is very similar to how colors/styles are specified in a gitconfig file: https://git-scm.com/docs/git-config#Documentation/git-config.txt-color
Here is an example:
--minus-style 'red bold ul \"#ffeeee\"'
That means: For removed lines, set the foreground (text) color to 'red', make it bold and underlined, and set the background color to '#ffeeee'.
See the COLORS section below for how to specify a color. In addition to real colors, there are 4 special color names: 'auto', 'normal', 'raw', and 'syntax'.
Here is an example of using special color names together with a single attribute:
--minus-style 'syntax bold auto'
That means: For removed lines, syntax-highlight the text, and make it bold, and do whatever delta normally does for the background.
The available attributes are: 'blink', 'bold', 'dim', 'hidden', 'italic', 'reverse', 'strike', and 'ul' (or 'underline').
The attribute 'omit' is supported by commit-style, file-style, and hunk-header-style, meaning to remove the element entirely from the output.
A complete description of the style string syntax follows:
- If the input that delta is receiving already has colors, and you want delta to output those colors unchanged, then use the special style string 'raw'. Other