Colors are appropriate if "our" pager is running (we start it in such a way that it handles colors) or stdout is a tty.
2YEVYKBBYRSNBNDIUGQRFP7EYI5O4XTVFS63SJDSIK4EPHQRBHCAC
H62VFFJEBL2I3O4D3BAJZ57ROPWUISC7JCDIWFBC5DAYJRHMMDXAC
KVBLRDOUFRYB6BPOQJDD7OVBYMTTPDAUX7CJ5DC3U7WFRI5OLWRAC
GRSSOI6NZNHBNF43NXZSNMVGIWI3OTEMLQGOKUSB5S7BYJGYPPHAC
UQ4M4BRBN42USIWC2S57GLXWDKOTIOPIUCGTKWGPYRTX7CBUEZJQC
SXEYMYF7P4RZMZ46WPL4IZUTSQ2ATBWYZX7QNVMS3SGOYXYOHAGQC
L4JXJHWXYNCL4QGJXNKKTOKKTAXKKXBJUUY7HFZGEUZ5A2V5H34QC
VIHXB7SGRETFPHPYZFSRGOFRXEO4RZY57WDZSU6IAUEJRU3HPKQAC
G734WNM64AR5BLAZMN5MDPKSFTYXTUQR6MAGB32NRBC5FXFRWSJAC
I52XSRUH5RVHQBFWVMAQPTUSPAJ4KNVID2RMI3UGCVKFLYUO6WZAC
OUWD436ATBTZJR53B6XDSI5SXRRNZV7YGRUEA5ACHZC2RUDP7G5QC
/// Determine whether we should emit colored output. True if
/// we started the pager (so we know it can read color codes)
/// or stdout is a tty, otherwise false.
fn use_colors(pager: &pager::Pager) -> bool {
pager.is_on() || atty::is(atty::Stream::Stdout)
}
let mut pager = initialize_pager();
Pager::with_pager("less -F -r").setup();
change.write(&changes, Some(hash), file_name, true, &mut o)?;
let pager = initialize_pager();
change.write(
&changes,
Some(hash),
file_name,
true,
&mut o,
use_colors(&pager),
)?;
atty = "0.2"
print_change_contents(&mut w, changes, change, change_contents)?;
print_change_contents(&mut w, changes, replacement, change_contents)?;
print_change_contents(&mut w, changes, change, change_contents, use_colors)?;
print_change_contents(&mut w, changes, replacement, change_contents, use_colors)?;
/// The style in which to print insertion changes.
/// Green if we can use colors, plain otherwise.
fn insertion_style(use_colors: bool) -> Style {
if use_colors {
Style::from(Green)
} else {
Style::default()
}
}
/// The style in which to print deletion changes.
/// Red if we can use colors, plain otherwise.
fn deletion_style(use_colors: bool) -> Style {
if use_colors {
Style::from(Red)
} else {
Style::default()
}
}
"console_error_panic_hook" = rec {
crateName = "console_error_panic_hook";
version = "0.1.6";
edition = "2015";
sha256 = "04d2narcrzk9bnddz17rr2l819l82pr0h6d98s2w9q236n87dndq";
authors = [
"Nick Fitzgerald <fitzgen@gmail.com>"
];
dependencies = [
{
name = "cfg-if";
packageId = "cfg-if 0.1.10";
}
{
name = "wasm-bindgen";
packageId = "wasm-bindgen";
}
];
};
"const_fn" = rec {
crateName = "const_fn";
version = "0.4.3";
edition = "2018";
sha256 = "1axgb6p2b0mdazi000vf0hd7hky690s052bwnizz3klx09p86y64";
procMacro = true;
authors = [
"Taiki Endo <te316e89@gmail.com>"
];
};
authors = [
"The Crossbeam Project Developers"
];
dependencies = [
{
name = "cfg-if";
packageId = "cfg-if 1.0.0";
}
{
name = "lazy_static";
packageId = "lazy_static";
optional = true;
}
];
buildDependencies = [
{
name = "autocfg";
packageId = "autocfg";
}
];
features = {
"default" = [ "std" ];
"std" = [ "lazy_static" ];
};
resolvedDefaultFeatures = [ "default" "lazy_static" "std" ];
};
"crossbeam-utils 0.8.0" = rec {
crateName = "crossbeam-utils";
version = "0.8.0";
edition = "2018";
sha256 = "199ywwmkg60kqavhw8rhy9wybsfjr9p5czinhq56jprmk06m94gc";
"errno" = rec {
crateName = "errno";
version = "0.2.7";
edition = "2015";
sha256 = "1zj6rra8n7d7gagppvvs5pvrfblad6x4ln5knb4kg7dfkkxz4s7s";
authors = [
"Chris Wong <lambda.fairy@gmail.com>"
];
dependencies = [
{
name = "errno-dragonfly";
packageId = "errno-dragonfly";
target = { target, features }: (target."os" == "dragonfly");
}
{
name = "libc";
packageId = "libc";
target = { target, features }: (target."os" == "hermit");
}
{
name = "libc";
packageId = "libc";
target = { target, features }: (target."os" == "wasi");
}
{
name = "libc";
packageId = "libc";
target = { target, features }: target."unix";
}
{
name = "winapi";
packageId = "winapi 0.3.9";
target = { target, features }: target."windows";
features = [ "errhandlingapi" "minwindef" "ntdef" "winbase" ];
}
];
};
"errno-dragonfly" = rec {
crateName = "errno-dragonfly";
version = "0.1.1";
edition = "2015";
sha256 = "0rshlc00nv45f14v2l1w0ma2nf1jg5j7q9pvw7hh018r6r73bjhl";
authors = [
"Michael Neumann <mneumann@ntecs.de>"
];
dependencies = [
{
name = "libc";
packageId = "libc";
}
];
buildDependencies = [
{
name = "gcc";
packageId = "gcc";
}
];
};
};
"pager" = rec {
crateName = "pager";
version = "0.16.0";
edition = "2018";
sha256 = "0s0r95q3jfbh2c3paab2bpl158lyaq35xnzy1x7mrdfhy26d1iq5";
authors = [
"Cyril Plisko <cyril.plisko@mountall.com>"
];
dependencies = [
{
name = "errno";
packageId = "errno";
}
{
name = "libc";
packageId = "libc";
}
];
features = {
};
"wasm-bindgen-test" = rec {
crateName = "wasm-bindgen-test";
version = "0.3.18";
edition = "2018";
sha256 = "0r3z37d48i91bg2akjzfcpj3a1jbkhcs2l1xfcj7ymcap74cvl9l";
authors = [
"The wasm-bindgen Developers"
];
dependencies = [
{
name = "console_error_panic_hook";
packageId = "console_error_panic_hook";
}
{
name = "js-sys";
packageId = "js-sys";
}
{
name = "scoped-tls";
packageId = "scoped-tls";
}
{
name = "wasm-bindgen";
packageId = "wasm-bindgen";
}
{
name = "wasm-bindgen-futures";
packageId = "wasm-bindgen-futures";
}
{
name = "wasm-bindgen-test-macro";
packageId = "wasm-bindgen-test-macro";
}
];
};
"wasm-bindgen-test-macro" = rec {
crateName = "wasm-bindgen-test-macro";
version = "0.3.18";
edition = "2018";
sha256 = "11d5w6wdjd2if1n7jrjvhgi52pn094m51nxpn65fwfblprkrryz8";
procMacro = true;
authors = [
"The wasm-bindgen Developers"
];
dependencies = [
{
name = "proc-macro2";
packageId = "proc-macro2";
}
{
name = "quote";
packageId = "quote";
}
];
};
"crossbeam-utils 0.7.2" = rec {
"base64 0.12.3" = rec {
authors = [
"Alice Maz <alice@alicemaz.com>"
"Marshall Pierce <marshall@mpierce.org>"
];
features = {
"default" = [ "std" ];
};
resolvedDefaultFeatures = [ "default" "std" ];
};
"base64 0.13.0" = rec {
crateName = "base64";
version = "0.13.0";
edition = "2018";
sha256 = "1z82g23mbzjgijkpcrilc7nljpxpvpf7zxf6iyiapkgka2ngwkch";