Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get GHC error messages properly formatted on powershell terminal when built with stack?

Building with ghc prints beautifully formatted error messages on powershell (as in other terminals):

PS > ghc .\src\XXX.hs -package ghc -package ghc-paths -package filepath

[1 of 1] Compiling XXX           ( src\XXX.hs, src\XXX.o )

src\XXX.hs:340:9: error:
    parse error on input `<-'
    Perhaps this statement should be within a 'do' block?
    |
340 |   blah  <- blah blah blah
    |         ^^

But when building through stack, something goes wrong:

PS > stack build
XXX-0.1.0.0: build (lib + exe)
Preprocessing library for XXX-0.1.0.0..
Building library for XXX-0.1.0.0..
[2 of 3] Compiling XXX ( src\XXX.hs, .stack-work\dist\5c8418a7\build\XXX.o )

←[;1msrc\XXX.hs:340:9: ←[;1m←[31merror:←[0m←[0m←[;1m←[0m←[0m←[;1m
    parse error on input `<-'
    Perhaps this statement should be within a 'do' block?←[0m←[0m
←[;1m←[34m    |←[0m←[0m
←[;1m←[34m340 |←[0m←[0m   blah ←[;1m←[31m<-←[0m←[0m blah blah blah
←[;1m←[34m    |←[0m←[0m←[;1m←[31m         ^^←[0m←[0m
←[0m←[0m←[0m

Is this a bug in stack, or is there a setting to fix it?

Thanks!

like image 280
user3048859 Avatar asked Apr 28 '18 11:04

user3048859


People also ask

What is the difference between GHC and ghci?

Introduction. GHCi is GHC's interactive environment, in which Haskell expressions can be interactively evaluated and programs can be interpreted.

Where does stack install GHC?

You can find these sandboxed GHC installations in the ghc-* directories in the stack path --programs directory. If you would like Stack to use your system GHC installation, use the --system-ghc flag or run stack config set system-ghc --global true to make Stack check your PATH for a suitable GHC by default.

How do I run ghci in terminal?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.

What is stack ghci?

stack ghci allows you to load components and files of your project into ghci . It uses the same TARGET syntax as stack build , and can also take options like --test , --bench , and --flag . Similarly to stack build , the default is to load up ghci with all libraries and executables in the project.


1 Answers

Turning off "use legacy console" in the cmd options does the trick!

Seems to be due to ansi color escape sequences - thanks @LotPings

Also: stack build --color never

gives monochrome but otherwise correctly formatted error messages.

like image 188
user3048859 Avatar answered Oct 22 '22 14:10

user3048859