cli: Add `--color` option to `rad diff`
Forces color output for eg. when piping into a pager.
This commit is contained in:
parent
dc7e126c85
commit
6a5753f4bc
|
|
@ -29,6 +29,7 @@ Usage
|
||||||
Options
|
Options
|
||||||
|
|
||||||
--staged View staged changes
|
--staged View staged changes
|
||||||
|
--color Force color output
|
||||||
--help Print help
|
--help Print help
|
||||||
"#,
|
"#,
|
||||||
};
|
};
|
||||||
|
|
@ -37,6 +38,7 @@ pub struct Options {
|
||||||
pub commits: Vec<Rev>,
|
pub commits: Vec<Rev>,
|
||||||
pub staged: bool,
|
pub staged: bool,
|
||||||
pub unified: usize,
|
pub unified: usize,
|
||||||
|
pub color: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args for Options {
|
impl Args for Options {
|
||||||
|
|
@ -47,6 +49,7 @@ impl Args for Options {
|
||||||
let mut commits = Vec::new();
|
let mut commits = Vec::new();
|
||||||
let mut staged = false;
|
let mut staged = false;
|
||||||
let mut unified = 5;
|
let mut unified = 5;
|
||||||
|
let mut color = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
|
|
@ -55,6 +58,7 @@ impl Args for Options {
|
||||||
unified = term::args::number(&val)?;
|
unified = term::args::number(&val)?;
|
||||||
}
|
}
|
||||||
Long("staged") | Long("cached") => staged = true,
|
Long("staged") | Long("cached") => staged = true,
|
||||||
|
Long("color") => color = true,
|
||||||
Long("help") | Short('h') => return Err(Error::Help.into()),
|
Long("help") | Short('h') => return Err(Error::Help.into()),
|
||||||
Value(val) => {
|
Value(val) => {
|
||||||
let rev = term::args::rev(&val)?;
|
let rev = term::args::rev(&val)?;
|
||||||
|
|
@ -70,6 +74,7 @@ impl Args for Options {
|
||||||
commits,
|
commits,
|
||||||
staged,
|
staged,
|
||||||
unified,
|
unified,
|
||||||
|
color,
|
||||||
},
|
},
|
||||||
vec![],
|
vec![],
|
||||||
))
|
))
|
||||||
|
|
@ -135,6 +140,8 @@ pub fn run(options: Options, _ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}?;
|
}?;
|
||||||
diff.find_similar(Some(&mut find_opts))?;
|
diff.find_similar(Some(&mut find_opts))?;
|
||||||
|
|
||||||
|
term::Paint::force(options.color);
|
||||||
|
|
||||||
let diff = surf::diff::Diff::try_from(diff)?;
|
let diff = surf::diff::Diff::try_from(diff)?;
|
||||||
let mut hi = Highlighter::default();
|
let mut hi = Highlighter::default();
|
||||||
let pretty = diff.pretty(&mut hi, &(), &repo);
|
let pretty = diff.pretty(&mut hi, &(), &repo);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue