Skip to content

Commit

Permalink
Always return binary strings from get_line
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Sep 9, 2021
1 parent 42c7063 commit dbea224
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/gleam_erlang_ffi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ atom_from_dynamic(Data) when is_atom(Data) ->
atom_from_dynamic(_) ->
{error, list_to_binary("expected an atom, got some other type")}.

-spec get_line(io:prompt()) -> {ok, string() | unicode:unicode_binary()} | {error, eof} | {error, no_data}.
-spec get_line(io:prompt()) -> {ok, unicode:unicode_binary()} | {error, eof | no_data}.
get_line(Prompt) ->
case io:get_line(Prompt) of
eof -> {error, eof};
{error, _} -> {error, no_data};
Data -> {ok, Data}
Data when is_binary(Data) -> {ok, Data};
Data when is_list(Data) -> {ok, unicode:characters_to_binary(Data)}
end.

0 comments on commit dbea224

Please sign in to comment.