From 0ea8467dc0e690306a9b39fbecb6461b2a69386e Mon Sep 17 00:00:00 2001 From: Benjamin Nguyen Date: Wed, 19 Apr 2023 16:32:52 -0700 Subject: [PATCH] add option to force colors no matter what --- src/render/context/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/render/context/mod.rs b/src/render/context/mod.rs index 15f6ed42..c589ec67 100644 --- a/src/render/context/mod.rs +++ b/src/render/context/mod.rs @@ -41,6 +41,10 @@ pub struct Context { /// Directory to traverse; defaults to current working directory dir: Option, + /// Turn on colorization always + #[arg(short = 'C', long)] + pub force_color: bool, + /// Print physical or logical file size #[arg(short, long, value_enum, default_value_t = DiskUsage::default())] pub disk_usage: DiskUsage, @@ -248,9 +252,15 @@ impl Context { Self::from_arg_matches(&user_args).map_err(Error::ArgParse) } - /// Determines whether or not it's appropriate to display color in output based on `--no-color` - /// and whether or not stdout is connected to a tty. + /// Determines whether or not it's appropriate to display color in output based on + /// `--no-color`, `--force-color`, and whether or not stdout is connected to a tty. + /// + /// If `--force-color` is true then this will always evaluate to `false`. pub const fn no_color(&self) -> bool { + if self.force_color { + return false + } + self.no_color || !self.stdout_is_tty }