Add option to highlight echoed recipe lines (#190)

Using bold and cyan, for visibility.
This commit is contained in:
Casey Rodarmor 2017-04-25 23:39:34 -07:00 committed by GitHub
parent 9fce455851
commit 1990c58a21
2 changed files with 17 additions and 1 deletions

View File

@ -115,6 +115,9 @@ pub fn app() {
.arg(Arg::with_name("EVALUATE") .arg(Arg::with_name("EVALUATE")
.long("evaluate") .long("evaluate")
.help("Prints evaluated variables")) .help("Prints evaluated variables"))
.arg(Arg::with_name("HIGHLIGHT")
.long("highlight")
.help("Highlight echoed recipe lines in bold"))
.arg(Arg::with_name("JUSTFILE") .arg(Arg::with_name("JUSTFILE")
.long("justfile") .long("justfile")
.takes_value(true) .takes_value(true)
@ -338,6 +341,7 @@ pub fn app() {
let options = RunOptions { let options = RunOptions {
dry_run: matches.is_present("DRY-RUN"), dry_run: matches.is_present("DRY-RUN"),
evaluate: matches.is_present("EVALUATE"), evaluate: matches.is_present("EVALUATE"),
highlight: matches.is_present("HIGHLIGHT"),
overrides: overrides, overrides: overrides,
quiet: matches.is_present("QUIET"), quiet: matches.is_present("QUIET"),
shell: matches.value_of("SHELL"), shell: matches.value_of("SHELL"),

View File

@ -424,8 +424,11 @@ impl<'a> Recipe<'a> {
if options.dry_run if options.dry_run
|| options.verbose || options.verbose
|| !((quiet_command ^ self.quiet) || options.quiet) { || !((quiet_command ^ self.quiet) || options.quiet) {
warn!("{}", command); let highlight = maybe_highlight(options.highlight
&& options.use_color.should_color_stderr());
warn!("{}", highlight.paint(command));
} }
if options.dry_run { if options.dry_run {
continue; continue;
} }
@ -1031,6 +1034,14 @@ fn maybe_bold(colors: bool) -> ansi_term::Style {
} }
} }
fn maybe_highlight(colors: bool) -> ansi_term::Style {
if colors {
ansi_term::Style::new().fg(ansi_term::Color::Cyan).bold()
} else {
ansi_term::Style::default()
}
}
impl<'a> Display for CompileError<'a> { impl<'a> Display for CompileError<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use ErrorKind::*; use ErrorKind::*;
@ -1143,6 +1154,7 @@ struct Justfile<'a> {
struct RunOptions<'a> { struct RunOptions<'a> {
dry_run: bool, dry_run: bool,
evaluate: bool, evaluate: bool,
highlight: bool,
overrides: Map<&'a str, &'a str>, overrides: Map<&'a str, &'a str>,
quiet: bool, quiet: bool,
shell: Option<&'a str>, shell: Option<&'a str>,