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'. Otherwise, delta will strip any colors from its input.
- A style string consists of 0, 1, or 2 colors, together with an arbitrary number of style attributes, all separated by spaces.
- The first color is the foreground (text) color. The second color is the background color. Attributes can go in any position.
- This means that in order to specify a background color you must also specify a foreground (text) color.
- If you want delta to choose one of the colors automatically, then use the special color 'auto'. This can be used for both foreground and background.
- If you want the foreground/background color to be your terminal's foreground/background color, then use the special color 'normal'.
- If you want the foreground text to be syntax-highlighted according to its language, then use the special foreground color 'syntax'. This can only be used for the foreground (text).
- The minimal style specification is the empty string ''. This means: do not apply any colors or styling to the element in question.
COLORS