Remove colored CLI output from runtime-core lib.

When the colored output was originally added in https://github.com/wasmerio/wasmer/pull/489 and there was a discussion then about that it should ideally be in a higher-level crate rather than in the runtime-core library crate.

I agree with that, users of the library shouldn't be required to bring in the colored crate dependency and ideally also not have stdout/stderr output either, that should be controlled by the application that uses wasmer-runtime-core, not the library.

Disabling stdout/stderr output would be more intrusive but I wanted to at least not have colored output and another crate dependency so this change removes the colored output and the "colored" crate.
This commit is contained in:
Johan Andersson
2019-09-15 03:21:04 +02:00
parent 9068777aaf
commit ad70caff83
6 changed files with 10 additions and 88 deletions

View File

@ -283,13 +283,10 @@ extern "C" fn signal_trap_handler(
let image = build_instance_image(ctx, es_image);
unwind_result = Box::new(image);
} else {
use colored::*;
if es_image.frames.len() > 0 {
eprintln!(
"\n{}",
"Wasmer encountered an error while running your WebAssembly program."
.bold()
.red()
);
es_image.print_backtrace_if_needed();
}

View File

@ -303,7 +303,7 @@ impl ExecutionStateImage {
if let Ok(x) = env::var("WASMER_BACKTRACE") {
if x == "1" {
eprintln!("{}", self.colored_output());
eprintln!("{}", self.output());
return;
}
}
@ -311,9 +311,7 @@ impl ExecutionStateImage {
eprintln!("Run with `WASMER_BACKTRACE=1` environment variable to display a backtrace.");
}
pub fn colored_output(&self) -> String {
use colored::*;
pub fn output(&self) -> String {
fn join_strings(x: impl Iterator<Item = String>, sep: &str) -> String {
let mut ret = String::new();
let mut first = true;
@ -341,8 +339,6 @@ impl ExecutionStateImage {
i,
x.map(|x| format!("{}", x))
.unwrap_or_else(|| "?".to_string())
.bold()
.cyan()
)
}),
", ",
@ -353,27 +349,27 @@ impl ExecutionStateImage {
let mut ret = String::new();
if self.frames.len() == 0 {
ret += &"Unknown fault address, cannot read stack.".yellow();
ret += &"Unknown fault address, cannot read stack.";
ret += "\n";
} else {
ret += &"Backtrace:".bold();
ret += &"Backtrace:";
ret += "\n";
for (i, f) in self.frames.iter().enumerate() {
ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id).bold();
ret += &format!("* Frame {} @ Local function {}", i, f.local_function_id);
ret += "\n";
ret += &format!(
" {} {}\n",
"Offset:".bold().yellow(),
format!("{}", f.wasm_inst_offset).bold().cyan(),
"Offset:",
format!("{}", f.wasm_inst_offset),
);
ret += &format!(
" {} {}\n",
"Locals:".bold().yellow(),
"Locals:",
format_optional_u64_sequence(&f.locals)
);
ret += &format!(
" {} {}\n\n",
"Stack:".bold().yellow(),
"Stack:",
format_optional_u64_sequence(&f.stack)
);
}