mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
use 'atty' to detect when colors can be used
This commit is contained in:
parent
7d17740ca8
commit
8ba6277cce
3 changed files with 12 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2264,6 +2264,7 @@ name = "taskchampion-cli"
|
|||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"assert_cmd",
|
||||
"atty",
|
||||
"config",
|
||||
"dirs 3.0.1",
|
||||
"env_logger",
|
||||
|
|
|
@ -13,6 +13,7 @@ nom = "*"
|
|||
prettytable-rs = "^0.8.0"
|
||||
textwrap = "0.12.1"
|
||||
termcolor = "1.1.2"
|
||||
atty = "0.2.14"
|
||||
|
||||
[dependencies.config]
|
||||
default-features = false
|
||||
|
|
|
@ -18,7 +18,7 @@ pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> {
|
|||
log::debug!("command: {:?}", command);
|
||||
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
|
||||
// `execute` functions in a submodule of `cmd`.
|
||||
|
@ -110,3 +110,12 @@ fn get_server(settings: &Config) -> Fallible<Box<dyn server::Server>> {
|
|||
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
|
||||
}))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue