clif-util wasm: don't panic when terminal colors are unsupported

This breaks inside of Emacs' `M-x shell` and `compilation-mode`.
This commit is contained in:
Nick Fitzgerald
2018-09-06 16:44:58 -07:00
committed by Dan Gohman
parent da0243b0ab
commit 8fb681b86d

View File

@@ -72,13 +72,13 @@ fn handle_module(
fisa: FlagsOrIsa, fisa: FlagsOrIsa,
) -> Result<(), String> { ) -> Result<(), String> {
let mut terminal = term::stdout().unwrap(); let mut terminal = term::stdout().unwrap();
terminal.fg(term::color::YELLOW).unwrap(); let _ = terminal.fg(term::color::YELLOW);
vprint!(flag_verbose, "Handling: "); vprint!(flag_verbose, "Handling: ");
terminal.reset().unwrap(); let _ = terminal.reset();
vprintln!(flag_verbose, "\"{}\"", name); vprintln!(flag_verbose, "\"{}\"", name);
terminal.fg(term::color::MAGENTA).unwrap(); let _ = terminal.fg(term::color::MAGENTA);
vprint!(flag_verbose, "Translating... "); vprint!(flag_verbose, "Translating... ");
terminal.reset().unwrap(); let _ = terminal.reset();
let mut module_binary = let mut module_binary =
read_to_end(path.clone()).map_err(|err| String::from(err.description()))?; read_to_end(path.clone()).map_err(|err| String::from(err.description()))?;
@@ -103,9 +103,9 @@ fn handle_module(
DummyEnvironment::with_triple_flags(isa.triple().clone(), fisa.flags.clone()); DummyEnvironment::with_triple_flags(isa.triple().clone(), fisa.flags.clone());
translate_module(&module_binary, &mut dummy_environ).map_err(|e| e.to_string())?; translate_module(&module_binary, &mut dummy_environ).map_err(|e| e.to_string())?;
terminal.fg(term::color::GREEN).unwrap(); let _ = terminal.fg(term::color::GREEN);
vprintln!(flag_verbose, "ok"); vprintln!(flag_verbose, "ok");
terminal.reset().unwrap(); let _ = terminal.reset();
if flag_just_decode { if flag_just_decode {
if !flag_print { if !flag_print {
@@ -131,17 +131,17 @@ fn handle_module(
println!("{}", context.func.display(None)); println!("{}", context.func.display(None));
vprintln!(flag_verbose, ""); vprintln!(flag_verbose, "");
} }
terminal.reset().unwrap(); let _ = terminal.reset();
return Ok(()); return Ok(());
} }
terminal.fg(term::color::MAGENTA).unwrap(); let _ = terminal.fg(term::color::MAGENTA);
if flag_check_translation { if flag_check_translation {
vprint!(flag_verbose, "Checking... "); vprint!(flag_verbose, "Checking... ");
} else { } else {
vprint!(flag_verbose, "Compiling... "); vprint!(flag_verbose, "Compiling... ");
} }
terminal.reset().unwrap(); let _ = terminal.reset();
if flag_print_size { if flag_print_size {
vprintln!(flag_verbose, ""); vprintln!(flag_verbose, "");
@@ -201,8 +201,8 @@ fn handle_module(
println!("Total module bytecode size: {} bytes", total_bytecode_size); println!("Total module bytecode size: {} bytes", total_bytecode_size);
} }
terminal.fg(term::color::GREEN).unwrap(); let _ = terminal.fg(term::color::GREEN);
vprintln!(flag_verbose, "ok"); vprintln!(flag_verbose, "ok");
terminal.reset().unwrap(); let _ = terminal.reset();
Ok(()) Ok(())
} }