Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm terminal color always detected as unsupported #154

Open
tqwewe opened this issue Jan 16, 2023 · 3 comments
Open

Wasm terminal color always detected as unsupported #154

tqwewe opened this issue Jan 16, 2023 · 3 comments

Comments

@tqwewe
Copy link

tqwewe commented Jan 16, 2023

console/src/wasm_term.rs

Lines 16 to 19 in 02fa5c0

#[inline]
pub fn is_a_color_terminal(_out: &Term) -> bool {
false
}

In the wasm terminal module, it sets is_a_color_terminal to always return false. But this should use detection similar to native terminals.

In my case, I'm trying to implement console with a wasm runner called lunatic, though coloring doesn't work unless I force it to be enabled, since the compiled module is a wasm module ran by lunatic.

@mitsuhiko
Copy link
Collaborator

mitsuhiko commented Jan 16, 2023

I would need to look into what WASI wants to do there. There is some discussion about how this is supposed to work over there: WebAssembly/WASI#162

It looks like even if console were to report a color terminal, wasmtime would filter out ANSI codes. I'm unfamiliar with lunatic, not sure how that works. If you have a reference about how lunatic supports ANSI codes I would be interested.

@tqwewe
Copy link
Author

tqwewe commented Jan 16, 2023

Lunatic uses wasmtime under the hood for running the wasm, and just manages multiple "processes". But the main support would be a matter of wasmtime really.

If I force it to be enabled, it prints the colors just fine. I guess wasi just lacks a spec/support for ansi stuff, and sadly that github issue isn't very active.

I guess my best case going forward could be to just copying these lines

console/src/unix_term.rs

Lines 26 to 33 in 02fa5c0

if env::var("NO_COLOR").is_ok() {
return false;
}
match env::var("TERM") {
Ok(term) => term != "dumb",
Err(_) => false,
}
and setting the color to be enabled based on this

@mitsuhiko
Copy link
Collaborator

mitsuhiko commented Jan 16, 2023

That is interesting. Because this commit here indicates that ANSI sequences should be filtered by wasmtime: bytecodealliance/wasmtime#684 — it's also documented here as explicitly filtered: https://github.com/bytecodealliance/wasmtime/blob/e4dc9c79443259e40f3e93b9c7815b0645ebd5c4/docs/security.md?plain=1#L98

I would love to get some guidance on what to do with ANSI codes before committing to something. Right now you can already manually force colors on globally by calling console::set_colors_enabled overriding what happens normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants