Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set stdio encoding to utf-8 on windows #108

Closed
cnd opened this issue May 27, 2016 · 15 comments
Closed

set stdio encoding to utf-8 on windows #108

cnd opened this issue May 27, 2016 · 15 comments

Comments

@cnd
Copy link

cnd commented May 27, 2016

related issue: atom-haskell/ide-haskell-cabal#11 (comment)

when I run chcp 65001 it helps but it seems like it could break integration with other things

is it possible to set stdio encoding to utf-8 on windows?

@jaspervdj
Copy link
Member

Yeah, I agree that this is a good idea, since it seems UTF-8 is at least how GHC reads files (source). We can do this on all platforms and allow users to disable it with a command-line option.

@cnd
Copy link
Author

cnd commented May 31, 2016

but just adding

        hSetEncoding stdout utf8
        readUTF8File fileName >>= putStr

doesn't help with atom, cc @lierdakil

@lierdakil
Copy link

That's probably because ide-haskell uses stylish-haskell as filter, i.e. source is passed on stdin instead of file. Try to hSetEncoding stdin utf8.

@cnd
Copy link
Author

cnd commented May 31, 2016

@lierdakil no effect and no error messages

@jaspervdj
Copy link
Member

Another approach could be using the bytestring library, reading stdin as raw ByteString and using T.unpack . Data.Text.Encoding.decodeUtf8 to convert it into a String. It's a bit more hassle but it would do the job, I think.

@lierdakil
Copy link

@Heather, I think you might be hacking on the wrong part of stylish-haskell there... lines 52-55 of src/Main.hs have to do with dumping default config, not actual "stylishing".

You might want to do this in main before call to stylishHaskell (should work) or in file (might work)

Minimal example:

main :: IO ()
main = do
    mapM_ (`hSetEncoding` utf8) [stdin, stdout]
    cmdArgs stylishArgs >>= stylishHaskell

@cnd
Copy link
Author

cnd commented May 31, 2016

@jaspervdj seems like helped #109

@cnd
Copy link
Author

cnd commented May 31, 2016

@jaspervdj btw, it doesn't work with CPP things alike #if MIN_VERSION_Win32(2,3,1) - is it known issue?

@jaspervdj
Copy link
Member

Yes @Heather, CPP is impossible to parse in some cases, so stylish-haskell doesn't try.

@jaspervdj
Copy link
Member

@Heather I've added an --utf8 flag which should do the job in 90f18cb, which is on the master branch. Could you try that out on Windows? I hope there's some way to tell atom that it should use the --utf8 flag.

@lierdakil
Copy link

That would be my job... Sigh. I'll have to check version of stylish-haskell
now as well.
1 июня 2016 г. 9:41 PM пользователь "Jasper Van der Jeugt" <
[email protected]> написал:

@Heather https://github.com/Heather I've added an --utf8 flag which
should do the job in 90f18cb
90f18cb,
which is on the master branch. Could you try that out on Windows? I hope
there's some way to tell atom that it should use the --utf8 flag.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#108 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AG8EZn3_kWc5sbXgd-NtvcUK_OS6IFdOks5qHdJAgaJpZM4IoO1q
.

@cnd
Copy link
Author

cnd commented Jun 1, 2016

@jaspervdj sure I can test it some later, it doesn't use change I used to add so result could be different

+readUTF8File :: FilePath -> IO String
 +readUTF8File fp = do
 +    content <- B.readFile fp
 +    let utf = decodeUtf8 content
 +    return (T.unpack utf)

@jaspervdj-luminal
Copy link

@lierdakil oh, in that case I can make it the default. It shouldn't hurt.

@Heather That code is not used if you're just using stylish-haskell as a unix filter (which I believe Atom is doing), so it should not matter.

@lierdakil
Copy link

If you could make it default, that would be great. Thanks.
1 июня 2016 г. 11:02 PM пользователь "Jasper Van der Jeugt" <
[email protected]> написал:

@lierdakil https://github.com/lierdakil oh, in that case I can make it
the default. It shouldn't hurt.

@Heather https://github.com/heather That code is not used if you're
just using stylish-haskell as a unix filter (which I believe Atom is
doing), so it should not matter.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#108 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AG8EZtFQLeOrPhgi66qKiYmJpiJLveBaks5qHeVBgaJpZM4IoO1q
.

@jaspervdj
Copy link
Member

I've uploaded stylish-haskell-0.5.17.0, which sets stdin/stdout encoding to UTF-8 by default. That should fix this issue. Feel free to re-open if it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants