Support colour when using git with a pager

Closes #29
ida_star
Wilfred Hughes 2021-08-24 00:20:34 +07:00
parent f55ca3bbcf
commit f17e0a5e0a
3 changed files with 17 additions and 2 deletions

@ -7,6 +7,8 @@ didn't display anything.
Fixed a crash on renaming a file.
Colour is now enabled when using git with a pager.
### Display
Side-by-side display now uses "..." for column numbers when aligning

@ -127,8 +127,8 @@ Alternatively, to run difftastic as the default diff engine for a git
command:
```
$ CLICOLOR_FORCE=1 GIT_EXTERNAL_DIFF=difftastic git diff
$ CLICOLOR_FORCE=1 GIT_EXTERNAL_DIFF=difftastic git log -p --ext-diff
$ GIT_EXTERNAL_DIFF=difftastic git diff
$ GIT_EXTERNAL_DIFF=difftastic git log -p --ext-diff
```
## License

@ -9,6 +9,7 @@ mod side_by_side;
mod style;
mod syntax;
mod tree_sitter_parser;
use atty::Stream;
use clap::{App, AppSettings, Arg};
use std::ffi::OsStr;
use std::path::Path;
@ -55,7 +56,19 @@ fn is_probably_binary(bytes: &[u8]) -> bool {
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn configure_color() {
if atty::is(Stream::Stdout) || env::var("GIT_PAGER_IN_USE").is_ok() {
// Always enable colour if stdout is a TTY or if the git pager is active.
// TODO: provide a way to disable this.
// TODO: consider following the env parsing logic in git_config_bool
// in config.c.
colored::control::set_override(true);
}
}
fn main() {
configure_color();
let matches = App::new("Difftastic")
.version(VERSION)
.about("A syntax aware diff.")