aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2013-01-01 16:56:22 +0100
committerHans Bolinder <[email protected]>2013-01-02 10:15:18 +0100
commitc44bc4f840f85c677eb86f00dc42c1648aaec0a6 (patch)
treef3e4bb6337559d73af91cfd75f647f23a778b3c0 /lib/stdlib/src
parent6f86a3a6ba3b975016aab80b3f5b3f2807304b24 (diff)
downloadotp-c44bc4f840f85c677eb86f00dc42c1648aaec0a6.tar.gz
otp-c44bc4f840f85c677eb86f00dc42c1648aaec0a6.tar.bz2
otp-c44bc4f840f85c677eb86f00dc42c1648aaec0a6.zip
Make sure the Erlang shell prompt can handle Unicode
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/io.erl4
-rw-r--r--lib/stdlib/src/io_lib.erl31
2 files changed, 21 insertions, 14 deletions
diff --git a/lib/stdlib/src/io.erl b/lib/stdlib/src/io.erl
index bc1727c027..ecf2aeb375 100644
--- a/lib/stdlib/src/io.erl
+++ b/lib/stdlib/src/io.erl
@@ -73,9 +73,9 @@ o_request(Io, Request, Func) ->
put_chars(Chars) ->
put_chars(default_output(), Chars).
--spec put_chars(IoDevice, IoData) -> 'ok' when
+-spec put_chars(IoDevice, CharData) -> 'ok' when
IoDevice :: device(),
- IoData :: unicode:chardata().
+ CharData :: unicode:chardata().
put_chars(Io, Chars) ->
o_request(Io, {put_chars,unicode,Chars}, put_chars).
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl
index 461da422ef..44c1d2132a 100644
--- a/lib/stdlib/src/io_lib.erl
+++ b/lib/stdlib/src/io_lib.erl
@@ -62,7 +62,7 @@
-export([fwrite/2,fread/2,fread/3,format/2]).
-export([print/1,print/4,indentation/2]).
--export([write/1,write/2,write/3,nl/0,format_prompt/1]).
+-export([write/1,write/2,write/3,nl/0,format_prompt/1,format_prompt/2]).
-export([write_atom/1,write_string/1,write_string/2,write_unicode_string/1,
write_unicode_string/2, write_char/1, write_unicode_char/1]).
@@ -178,27 +178,34 @@ indentation(Chars, Current) ->
%% Format an IO-request prompt (handles formatting errors safely).
-%% Atoms, binaries, and iolists can be used as-is, and will be
-%% printed without any additional quotes.
-%% Note that the output is a deep string, and not an iolist (i.e.,
-%% it may be deep, but never contains binaries, due to the "~s").
+%% Atoms, binaries, and iolists (or unicode:charlist()) can be used
+%% as-is, and will be printed without any additional quotes.
-spec format_prompt(term()) -> chars().
-format_prompt({format,Format,Args}) ->
- format_prompt(Format,Args);
-format_prompt(Prompt)
- when is_list(Prompt); is_atom(Prompt); is_binary(Prompt) ->
- format_prompt("~ts", [Prompt]);
format_prompt(Prompt) ->
- format_prompt("~tp", [Prompt]).
+ format_prompt(Prompt, latin1).
+
+-spec format_prompt(term(), atom()) -> chars().
+
+format_prompt({format,Format,Args}, _Encoding) ->
+ do_format_prompt(Format, Args);
+format_prompt(Prompt, Encoding)
+ when is_list(Prompt); is_atom(Prompt); is_binary(Prompt) ->
+ do_format_prompt(add_modifier(Encoding, "s"), [Prompt]);
+format_prompt(Prompt, Encoding) ->
+ do_format_prompt(add_modifier(Encoding, "p"), [Prompt]).
-format_prompt(Format, Args) ->
+do_format_prompt(Format, Args) ->
case catch io_lib:format(Format, Args) of
{'EXIT',_} -> "???";
List -> List
end.
+add_modifier(latin1, C) ->
+ "~"++C;
+add_modifier(_, C) ->
+ "~t"++C.
%% write(Term)
%% write(Term, Depth)