<div class="gmail_quote">On Thu, Nov 4, 2010 at 6:09 AM, Simon Marlow <span dir="ltr">&lt;<a href="mailto:marlowsd@gmail.com">marlowsd@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On 04/11/2010 02:35, David Sankel wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Wed, Nov 3, 2010 at 9:00 AM, Simon Marlow &lt;<a href="mailto:marlowsd@gmail.com" target="_blank">marlowsd@gmail.com</a><br></div><div><div></div><div class="h5">
&lt;mailto:<a href="mailto:marlowsd@gmail.com" target="_blank">marlowsd@gmail.com</a>&gt;&gt; wrote:<br>
<br>
    On 03/11/2010 10:36, Bulat Ziganshin wrote:<br>
<br>
        Hello Max,<br>
<br>
        Wednesday, November 3, 2010, 1:26:50 PM, you wrote:<br>
<br>
            1. You need to use &quot;chcp 65001&quot; to set the console code page<br>
            to UTF8<br>
            2. It is very likely that your Windows console won&#39;t have<br>
            the fonts<br>
            required to actually make sense of the output. Pipe the<br>
            output to<br>
            foo.txt. If you open this file in notepad you will see the<br>
            correct<br>
            characters show up.<br>
<br>
<br>
        it will work even without chcp. afaik nor ghc nor windows<br>
        adjusts text<br>
        being output to current console codepage<br>
<br>
<br>
    GHC certainly does.  We use GetConsoleCP() when deciding what code<br>
    page to use by default - see libraries/base/GHC/IO/Encoding/CodePage.hs.<br>
<br>
<br>
<br>
This can actually be quite helpful. I&#39;ve discovered that if you have a<br>
console set to code page 65001 (UTF-8) and use WriteConsoleA (the<br>
non-wide version) with UTF-8 encoded strings, the console displays the<br>
text properly!<br>
<br>
So the solution seems to be, when outputting to a utf8 console use<br>
WriteConsoleA.<br>
</div></div></blockquote>
<br>
We need someone to rewrite the IO library backend for Win32.  Currently it is going via the msvcrt POSIX emulation layer, i.e. using write() and pseudo-file-descriptors.  More than a few problems have been caused by this, and it&#39;s totally unnecessary except that we get to share some code between the POSIX and Windows backends.  We ought to be using the native Win32 APIs and HANDLE directly, then we could use WriteConsoleA.<br>

</blockquote><div><br></div><div>It looks like replacing the POSIX layer isn&#39;t necessary to fix the Unicode console output bug. I&#39;ve made a ticket and in a comment I illustrate the _setmode call that magically makes everything work:</div>

<div><br></div><div><a href="http://hackage.haskell.org/trac/ghc/ticket/4471">http://hackage.haskell.org/trac/ghc/ticket/4471</a></div><div><br></div><div>I could attempt a ghc patch for this, but I don&#39;t have any experience with the ghc code. Perhaps someone could add this _setmode call with relative ease?</div>

<div><br></div><div>David</div></div><br>-- <br>David Sankel<br>Sankel Software<br><a href="http://www.sankelsoftware.com">www.sankelsoftware.com</a><br>585 617 4748 (Office)<br>