Skip to content

Commit

Permalink
Merge pull request #135 from solidiquis/feature/force-color
Browse files Browse the repository at this point in the history
Feature/force color
  • Loading branch information
solidiquis authored Apr 19, 2023
2 parents e0b64aa + 0ea8467 commit 14fd53e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/render/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub struct Context {
/// Directory to traverse; defaults to current working directory
dir: Option<PathBuf>,

/// 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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 14fd53e

Please sign in to comment.