quchen / prettyprinter

A modern, extensible and well-documented prettyprinter.
BSD 2-Clause "Simplified" License
293 stars 34 forks source link

BUG pretty not working on Windows: "invalid character" #242

Open turbotimon opened 1 year ago

turbotimon commented 1 year ago

Prettyprinter does not work on Windows when printing a special character

ghci> import Prettyprinter
ghci> pretty "hello"
hello
ghci> pretty "hello λ"
hello *** Exception: <stdout>: hPutChar: invalid argument (invalid character)
sjakobi commented 1 year ago

What happens if you just input "hello λ"?

Did you configure your terminal to use UTF-8?

turbotimon commented 1 year ago

I looks like UTF-8 generally work in PS and CMD. In GHCI it get's escaped (but no error):

PS C:\Users\user> "hello ?"
hello λ
PS C:\Users\user> ghci
GHCi, version 9.2.5: https://www.haskell.org/ghc/  :? for help
ghci> "hello λ"
"hello \955"

I know other people having this issue on windows, it therefore seems not to be a isolated problem with my system.

turbotimon commented 1 year ago

I found a workaround by changing the codepage of the PowerShell or cmd.exe: chcp 65001

(this link may be also useful)

das-g commented 1 year ago

Here seems to be workaround that can probably be implemented in programs and libraries (rather than by the end user).