<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Fantastic, thank you José!<div><br></div><div><br><div><div>On 26 Jun 2014, at 11:51, José Valim <<a href="mailto:jose.valim@plataformatec.com.br">jose.valim@plataformatec.com.br</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Camille,<div><br></div><div>I have reported two bugs related to this area as I was expecting this behaviour to change on 17.0:</div><div><br></div><div><a href="http://erlang.org/pipermail/erlang-bugs/2014-April/004309.html">http://erlang.org/pipermail/erlang-bugs/2014-April/004309.html</a><br>

</div><div><a href="http://erlang.org/pipermail/erlang-bugs/2014-April/004310.html">http://erlang.org/pipermail/erlang-bugs/2014-April/004310.html</a><br></div><div><br></div><div>Only the erlang shell, the one started via the erl command, respects LC_CTYPE and the +fnu flags. If you pass -noshell, use the "dumb terminal" (triggered when you set TERM to something else), use stderr, or an escript, the encoding will remain as latin1.</div>

<div><br></div><div>You can change the encoding in those situations by calling:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>io:setopts(standard_io, [{encoding,utf8}]);</div>

</blockquote><div><br></div><div>I hope this helps,</div><div><br></div><div>PS: In case you want to call the line above in your application callback, you may notice a slow down when starting the application along side the shell with something like: erl -s my_app start. That's because the group_leader sends a message to the shell to change the encoding but the shell is not yet ready. I was able to work around this particular scenario by using:</div>

<div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>case init:get_argument(noshell) of</div><div>  {ok, _} -> io:setopts(standard_io, [{encoding,utf8}]);</div>
<div>
<div>  error   -> ok</div></div><div>end</div></blockquote><div><br></div><div>A patch was sent to OTP to fix this particular issue: <a href="https://github.com/erlang/otp/pull/351">https://github.com/erlang/otp/pull/351</a></div>

<div><br></div></div><div class="gmail_extra"><br clear="all"><div><div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div>

<div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></div>

</div>
<br><br><div class="gmail_quote">On Thu, Jun 26, 2014 at 11:28 AM, Camille Troillard <span dir="ltr"><<a href="mailto:lists@tuli.pe" target="_blank">lists@tuli.pe</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hello,<br>
<br>
<br>
On Mac OS X, when I start an Erlang shell from the command-line the io module encoding is set to unicode:<br>
<br>
<br>
> Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]<br>
><br>
> Eshell V5.10.4  (abort with ^G)<br>
> 1> os:getenv("LC_CTYPE").<br>
> "UTF-8"<br>
> 2> lists:keyfind(encoding, 1, io:getopts()).<br>
> {encoding,unicode}<br>
<br>
<br>
<br>
So that’s great.<br>
<br>
Now, I have a GUI application that launches the Erlang shell. At first I thought the LC_CTYPE environment variable was not set (which was the case), but even when set to UTF-8, this does not work as expected:<br>
<br>
Here's the output of the shell launched by the GUI application:<br>
<br>
> 1> os:getenv("LC_CTYPE").<br>
> "UTF-8"<br>
> 2> lists:keyfind(encoding, 1, io:getopts()).<br>
> {encoding,latin1}<br>
<br>
<br>
I want {encoding, unicode}, and don’t understand why it defaults to latin1.<br>
How can it be?<br>
<br>
<br>
The documentation of io says:<br>
<br>
(<a href="http://erlang.org/doc/man/io.html" target="_blank">http://erlang.org/doc/man/io.html</a>)<br>
> The standard shell will be set for either Unicode or latin1 encoding when the system is started. The actual encoding is set with the help of the LANG or LC_CTYPE environment variables on Unix-like system or by other means on other systems.<br>


<br>
Does Mac OS X applies to “other systems”? If so, what are the “other means”?<br>
<br>
Thanks!<br>
<br>
<br>
Best,<br>
Cam<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>
</blockquote></div><br></div></body></html>