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.
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 ...
)?
(This is just a guess; if that doesn't work then others will know more; if it does perhaps we could make it automatic...)
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.
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.
One wild guess is that the standard library's IsTerminal
API isn't implemented for wasi just yet
this seems to indicate that my wild guess is wrong
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.
oh I couldn't get clap to generate colors with --help
either
that was just colorization working at all in wasi
looks like --env CLICOLOR=1
may do the trick
although --env TERM=xxx
also works for me
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.
oh locally with wasm-tools that got me bold stuff which I assument meant colorization was enabled
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
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.
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.
Frank Rehwinkel has marked this topic as resolved.
Last updated: Dec 23 2024 at 14:03 UTC