aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2022-01-14 22:22:28 +0000
committerLouis Pilfold <louis@lpil.uk>2022-01-14 22:22:28 +0000
commitdf8278a33cd9114da3f42bac25bd992f5bd2120c (patch)
tree3aeb5aa22ae6475222298642d39c6a8eb79c115e
parent6498513ed9b17ee0e50ea566db6984c81866aa75 (diff)
downloadgleam_stdlib-df8278a33cd9114da3f42bac25bd992f5bd2120c.tar.gz
gleam_stdlib-df8278a33cd9114da3f42bac25bd992f5bd2120c.zip
Fix unicode printing
-rw-r--r--src/gleam/io.gleam16
-rw-r--r--src/gleam_stdlib.erl21
2 files changed, 15 insertions, 22 deletions
diff --git a/src/gleam/io.gleam b/src/gleam/io.gleam
index 4b3e998..df96128 100644
--- a/src/gleam/io.gleam
+++ b/src/gleam/io.gleam
@@ -15,10 +15,8 @@ pub fn print(string: String) -> Nil {
}
if erlang {
- fn do_print(string: String) -> Nil {
- erl_print("~s", [string])
- Nil
- }
+ external fn do_print(string: String) -> Nil =
+ "gleam_stdlib" "print"
}
if javascript {
@@ -39,10 +37,8 @@ pub fn println(string: String) -> Nil {
}
if erlang {
- fn do_println(string: String) -> Nil {
- erl_print("~ts\n", [string])
- Nil
- }
+ external fn do_println(string: String) -> Nil =
+ "gleam_stdlib" "println"
}
if javascript {
@@ -79,7 +75,7 @@ pub fn debug(term: anything) -> anything {
if erlang {
fn debug_print(term: anything) -> DoNotLeak {
- erl_print("~tp\n", [term])
+ erlang_fwrite("~tp\n", [term])
}
}
@@ -91,6 +87,6 @@ if javascript {
if erlang {
external type DoNotLeak
- external fn erl_print(String, List(a)) -> DoNotLeak =
+ external fn erlang_fwrite(String, List(a)) -> DoNotLeak =
"io" "fwrite"
}
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index 3228b18..c757857 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -11,7 +11,7 @@
bit_string_slice/3, decode_bit_string/1, compile_regex/2, regex_scan/2,
percent_encode/1, percent_decode/1, regex_check/2, regex_split/2,
base_decode64/1, parse_query/1, bit_string_concat/1, size_of_tuple/1,
- decode_tuple/1, tuple_get/2, classify_dynamic/1]).
+ decode_tuple/1, tuple_get/2, classify_dynamic/1, print/1, println/1]).
%% Taken from OTP's uri_string module
-define(DEC2HEX(X),
@@ -303,17 +303,6 @@ uri_parse(String) ->
case uri_string:parse(String) of
{error, _, _} -> {error, nil};
Uri ->
- % #{
- % host := Host, path := Path, port := Port, query := Query,
- % scheme := Scheme, userinfo := Userinfo
- % } ->
- % scheme: Option(String),
- % userinfo: Option(String),
- % host: Option(String),
- % port: Option(Int),
- % path: String,
- % query: Option(String),
- % fragment: Option(String),
{ok, {uri,
maps_get_optional(Uri, scheme),
maps_get_optional(Uri, userinfo),
@@ -334,3 +323,11 @@ maps_get_or(Map, Key, Default) ->
try maps:get(Key, Map)
catch _:_ -> Default
end.
+
+print(String) ->
+ io:put_chars(String),
+ nil.
+
+println(String) ->
+ io:put_chars([String, $\n]),
+ nil.