Stream: wasmtime

Topic: ✔ colorized output from wasmtime


view this post on Zulip Frank Rehwinkel (May 08 2024 at 15:16):

Should a Wasm Component built with clap be able to produce colored output to the terminal? For example, I see wasmtime itself is built with clap and the --help it provides is colorized. But so far, if I build a Wasm Component with the same clap features and then run that component with wasmtime and ask for its --help, I see the component's help text but it is not colorized.

I wonder if I'm building the component wrong, running wasmtime with the wrong arguments, or if somehow this is related to the WASI standards?

And it's not super important for the component-docs to talk about colorization but I will note that it doesn't. It could say what's required, or it could say that it's not supported at this time.

view this post on Zulip Chris Fallin (May 08 2024 at 15:20):

At least in the native-unix world this is supported via TERM, terminfo, and ANSI escape sequences... I don't know whether the latter bits are specially excluded from WASI builds or not but you could try passing TERM=vt100 as an explicit environment variable (wasmtime run --env TERM=vt100 ...)?

view this post on Zulip Chris Fallin (May 08 2024 at 15:21):

(This is just a guess; if that doesn't work then others will know more; if it does perhaps we could make it automatic...)

view this post on Zulip Frank Rehwinkel (May 08 2024 at 15:23):

That was a good idea but sorry to say it didn't help. The -env parameter was accepted without an error but the resulting output still wasn't colorized.

view this post on Zulip Alex Crichton (May 08 2024 at 15:25):

I think that there's probably some auto-detection which needs updating. If I do wasmtime run --dir . ./target/wasm32-wasi/debug/wasm-tools.wasm dump --color always foo.wat I see colors, but by default colors aren't printed.

view this post on Zulip Alex Crichton (May 08 2024 at 15:26):

One wild guess is that the standard library's IsTerminal API isn't implemented for wasi just yet

view this post on Zulip Alex Crichton (May 08 2024 at 15:27):

this seems to indicate that my wild guess is wrong

Empowering everyone to build reliable and efficient software. - rust-lang/rust

view this post on Zulip Frank Rehwinkel (May 08 2024 at 15:29):

How is your command wasmdump run command showing color but mine doesn't. Let me see if I can update my clap to take a color argument.

view this post on Zulip Alex Crichton (May 08 2024 at 15:30):

oh I couldn't get clap to generate colors with --help either

view this post on Zulip Alex Crichton (May 08 2024 at 15:30):

that was just colorization working at all in wasi

view this post on Zulip Alex Crichton (May 08 2024 at 15:38):

looks like --env CLICOLOR=1 may do the trick

view this post on Zulip Alex Crichton (May 08 2024 at 15:39):

although --env TERM=xxx also works for me

view this post on Zulip Frank Rehwinkel (May 08 2024 at 15:43):

Okay, I guess I'm using clap differently. I see there was a time during v3 that color was removed but then I guess it might have been added back (and I'm using the latest published version, v4.5.4). Thanks for confirming it should work. Just to be clear, I'm calling wasmtime run --env CLICOLOR=1 target/command.wasm --help and seeing the expected help, just not colorized. If this doesn't spark any other quick ideas, don't let me use anyone's time further.

view this post on Zulip Alex Crichton (May 08 2024 at 15:45):

oh locally with wasm-tools that got me bold stuff which I assument meant colorization was enabled

view this post on Zulip Alex Crichton (May 08 2024 at 15:45):

clap may have other stuff for putting colors everywhere other than just bolding some things but that's probably a clap config thing rather than a wasi thing

view this post on Zulip Frank Rehwinkel (May 08 2024 at 15:49):

yea, it might be that clap v4 keeps color off by default, but I thought I looked at wasmtime's src and didn't see where it would have been overriding the default. Anyway, I don't mean to conflate wasmtime's use of clap itself with its ability to run components built with clap, I know they are completely different. I'll start from scratch with a normal cargo/clap bin build and see where things start to go unexpected.

view this post on Zulip Frank Rehwinkel (May 08 2024 at 15:53):

Success. I found there is a "color" feature I needed to add. :man_facepalming: and I needed to pass an --env argument.


Either TERM=vt100 or CLICOLOR=1 worked.


Thank you both.

view this post on Zulip Notification Bot (May 08 2024 at 15:53):

Frank Rehwinkel has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC