use 'atty' to detect when colors can be used
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2264,6 +2264,7 @@ name = "taskchampion-cli"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
|
"atty",
|
||||||
"config",
|
"config",
|
||||||
"dirs 3.0.1",
|
"dirs 3.0.1",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ nom = "*"
|
|||||||
prettytable-rs = "^0.8.0"
|
prettytable-rs = "^0.8.0"
|
||||||
textwrap = "0.12.1"
|
textwrap = "0.12.1"
|
||||||
termcolor = "1.1.2"
|
termcolor = "1.1.2"
|
||||||
|
atty = "0.2.14"
|
||||||
|
|
||||||
[dependencies.config]
|
[dependencies.config]
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> {
|
|||||||
log::debug!("command: {:?}", command);
|
log::debug!("command: {:?}", command);
|
||||||
log::debug!("settings: {:?}", settings);
|
log::debug!("settings: {:?}", settings);
|
||||||
|
|
||||||
let mut w = StandardStream::stdout(ColorChoice::Auto);
|
let mut w = get_writer()?;
|
||||||
|
|
||||||
// This function examines the command and breaks out the necessary bits to call one of the
|
// This function examines the command and breaks out the necessary bits to call one of the
|
||||||
// `execute` functions in a submodule of `cmd`.
|
// `execute` functions in a submodule of `cmd`.
|
||||||
@@ -110,3 +110,12 @@ fn get_server(settings: &Config) -> Fallible<Box<dyn server::Server>> {
|
|||||||
client_id,
|
client_id,
|
||||||
})?)
|
})?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a WriteColor implementation based on whether the output is a tty.
|
||||||
|
fn get_writer() -> Fallible<StandardStream> {
|
||||||
|
Ok(StandardStream::stdout(if atty::is(atty::Stream::Stdout) {
|
||||||
|
ColorChoice::Auto
|
||||||
|
} else {
|
||||||
|
ColorChoice::Never
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user