From 6a5753f4bc9845b5482256b6904bb43554ac10ea Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 27 Sep 2023 14:44:20 +0200 Subject: [PATCH] cli: Add `--color` option to `rad diff` Forces color output for eg. when piping into a pager. --- radicle-cli/src/commands/diff.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/radicle-cli/src/commands/diff.rs b/radicle-cli/src/commands/diff.rs index 8261d6a4..aaaed6ea 100644 --- a/radicle-cli/src/commands/diff.rs +++ b/radicle-cli/src/commands/diff.rs @@ -29,6 +29,7 @@ Usage Options --staged View staged changes + --color Force color output --help Print help "#, }; @@ -37,6 +38,7 @@ pub struct Options { pub commits: Vec, pub staged: bool, pub unified: usize, + pub color: bool, } impl Args for Options { @@ -47,6 +49,7 @@ impl Args for Options { let mut commits = Vec::new(); let mut staged = false; let mut unified = 5; + let mut color = false; while let Some(arg) = parser.next()? { match arg { @@ -55,6 +58,7 @@ impl Args for Options { unified = term::args::number(&val)?; } Long("staged") | Long("cached") => staged = true, + Long("color") => color = true, Long("help") | Short('h') => return Err(Error::Help.into()), Value(val) => { let rev = term::args::rev(&val)?; @@ -70,6 +74,7 @@ impl Args for Options { commits, staged, unified, + color, }, vec![], )) @@ -135,6 +140,8 @@ pub fn run(options: Options, _ctx: impl term::Context) -> anyhow::Result<()> { }?; diff.find_similar(Some(&mut find_opts))?; + term::Paint::force(options.color); + let diff = surf::diff::Diff::try_from(diff)?; let mut hi = Highlighter::default(); let pretty = diff.pretty(&mut hi, &(), &repo);