IHaskell/ihaskell-notebook

Stack output can produce raw ANSI codes

Closed this issue · 7 comments

First of all, thanks for this project, it's amazing!

Steps to reproduce

:!stack install friday

Expected

Just nice output logging, maybe even in colour!

Actual

Raw ANSI codes

WARNING: Ignoring friday's bounds on containers (>=0.4 && <0.6); using containers-0.6.0.1. Reason: allow-newer enabled. �[91mError:�[0m While constructing the build plan, the following exceptions were encountered: In the dependencies for �[33mfriday-0.2.3.1�[0m: �[91mratio-int�[0m must match �[92m>=0.1.2 && <0.2�[0m, but the stack configuration has no specified version (latest matching version is �[92m0.1.2�[0m) needed since �[33mfriday�[0m is a build target. Some different approaches to resolving this: * �[1;92mRecommended action:�[0m try adding the following to your extra-deps in �[36m/opt/stack/global-project/stack.yaml�[0m: - ratio-int-0.1.2@sha256:304c6558e75eff2c7799558651091811d1d92e611594af8ac51edd10dd6c5cd8,858 Plan construction failed. 

Workaround

:!stack --color=never install $PACKAGE etc seems fine

Thanks for the bug report @declension !

Yeah, I see what's going on there. That's a shame. I've configured Stack to always use color output:

https://github.com/jamesdbrock/ihaskell-notebook/blob/290122cc67bb36b58eeb75000c5006a162b089ea/stack.config.yaml#L14

We could globally configure Stack to never output in color? That's stupid though, JupyterLab should definitely be able to handle ANSI color codes correctly. Here is some discussion: jupyterlab/jupyterlab#3773

Maybe we should just delete the color: always Stack configuration and let Stack auto-detect its terminal environment.

Thanks @jamesdbrock, the plot thickens. I've definitely noticed even GHC producing colour / bold things, so it's weird. Maybe it's only partial support for ANSI (I skimmed through that discussion but hard to say).

Either way I think autodetection will probably be better than forcing it here (then unforcing in notebooks) 👍

So, I removed the Stack color: always config and pushed that to master (along with assorted other upgrades) and tagged a new Docker lastest. And now the stack error messages print without ANSI color codes.

But those error messages should be able to display formatting and ANSI color without any problem. That's how the IPython kernel works. I've described this in IHaskell/IHaskell#1196 ... and now it looks like Vaibhav has already fixed it? I will take a look.

Vaibhav totally fixed the ANSI color problem, so I added his fix to the Dockerfile and built it on the Dockerhub latest. Now :! stack install friday will show properly a formatted and colored Stack error message.

(There are also a bunch of other upgrades in the latest image).

Amazing, thanks for all the investigation @jamesdbrock ! 💯