clif-util: add option for controlling terminal colors
On @fitzgen's suggestion, this change adds a `--color` option for controlling whether the `clif-util` output prints with ANSI color escape sequences. Only `clif-util wasm ...` currently uses this new option. The option has three variants: - `--color auto`, the default, prints colors if the terminal supports them - `--color always` prints colors always - `--color never` never prints colors
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
)
|
||||
)]
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use clap::{arg_enum, App, Arg, SubCommand};
|
||||
use cranelift_codegen::dbg::LOG_FILENAME_PREFIX;
|
||||
use cranelift_codegen::VERSION;
|
||||
use std::io::{self, Write};
|
||||
@@ -62,6 +62,26 @@ fn add_verbose_flag<'a>() -> clap::Arg<'a, 'a> {
|
||||
Arg::with_name("verbose").short("v").help("Be more verbose")
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum UseTerminalColor {
|
||||
Auto,
|
||||
Never,
|
||||
Always
|
||||
}
|
||||
}
|
||||
|
||||
fn add_color<'a>() -> clap::Arg<'a, 'a> {
|
||||
Arg::with_name("color")
|
||||
.long("color")
|
||||
.possible_values(&UseTerminalColor::variants())
|
||||
.takes_value(true)
|
||||
.multiple(false)
|
||||
.default_value("auto")
|
||||
.case_insensitive(true)
|
||||
.help("Use colors in output")
|
||||
}
|
||||
|
||||
fn add_time_flag<'a>() -> clap::Arg<'a, 'a> {
|
||||
Arg::with_name("time-passes")
|
||||
.short("T")
|
||||
@@ -120,6 +140,12 @@ fn add_check_translation_flag<'a>() -> clap::Arg<'a, 'a> {
|
||||
.help("Just checks the correctness of Cranelift IR translated from WebAssembly")
|
||||
}
|
||||
|
||||
fn add_value_ranges<'a>() -> clap::Arg<'a, 'a> {
|
||||
Arg::with_name("value-ranges")
|
||||
.long("value-ranges")
|
||||
.help("Display values ranges and their locations")
|
||||
}
|
||||
|
||||
/// Returns a vector of clap value options and changes these options into a vector of strings
|
||||
fn get_vec(argument_vec: Option<clap::Values>) -> Vec<String> {
|
||||
let mut ret_vec: Vec<String> = Vec::new();
|
||||
@@ -201,11 +227,9 @@ fn main() {
|
||||
)
|
||||
.subcommand(add_wasm_or_compile("compile"))
|
||||
.subcommand(
|
||||
add_wasm_or_compile("wasm").arg(
|
||||
Arg::with_name("value-ranges")
|
||||
.long("value-ranges")
|
||||
.help("Display values ranges and their locations"),
|
||||
),
|
||||
add_wasm_or_compile("wasm")
|
||||
.arg(add_value_ranges())
|
||||
.arg(add_color()),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("pass")
|
||||
@@ -306,6 +330,7 @@ fn main() {
|
||||
|
||||
wasm::run(
|
||||
get_vec(rest_cmd.values_of("file")),
|
||||
rest_cmd.value_of("color").unwrap().parse().unwrap(),
|
||||
rest_cmd.is_present("verbose"),
|
||||
rest_cmd.is_present("just-decode"),
|
||||
rest_cmd.is_present("check-translation"),
|
||||
|
||||
Reference in New Issue
Block a user