-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new variants of spawnPipe functions with encoding support
The current handle returned by `spawnPipe` doesn't have any encoding and it uses the function fdToHandle which returns a Binary Handle. When spawnPipe is used with a program like xmobar, this can easily lead to errors: λ> h <- spawnPipe "xmobar" λ> hPutStrLn h "\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723" <stdin>: hGetLine: invalid argument (invalid byte sequence) One workaround, to avoid this is to use `hSetEncoding`. But from reading GHC's source code - the entire Handle and write operations seems stateful. So doing something like hPutStr and hSetEncoding can theoretically lead to an undefined state as the first write will use latin encoding and the second write will use the new encoding. More details about it are present here: * http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.IO.Handle.Internals.html#writeCharBuffer * http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.IO.Buffer.html#CharBuffer So having these new functions will ensure that we get the handles in the proper encoding in the first place.
- Loading branch information
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters