Packages

A small Gleam package that provides input functions (stdin reading) missing from gleam/io.

Current section

Files

Jump to
in src in.erl
Raw

src/in.erl

-module(in).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/in.gleam").
-export([read_line/0, read_chars/1]).
-export_type([io_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type io_error() :: eof.
-file("src/in.gleam", 17).
?DOC(
" Reads a line from stdin.\n"
" Returns an `Eof` error if you try to read beyond the end of the file.\n"
).
-spec read_line() -> {ok, binary()} | {error, io_error()}.
read_line() ->
_pipe = io:get_line(<<""/utf8>>),
_pipe@1 = gleam@dynamic@decode:run(
_pipe,
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
gleam@result:replace_error(_pipe@1, eof).
-file("src/in.gleam", 31).
?DOC(
" Reads up to `count` characters from stdin.\n"
" If `count` is greater than the stdin length\n"
" the function will return everything up to the end of the input.\n"
" Returns an `Eof` error if you try to read beyond the end of the file.\n"
).
-spec read_chars(integer()) -> {ok, binary()} | {error, io_error()}.
read_chars(Count) ->
_pipe = io:get_chars(<<""/utf8>>, Count),
_pipe@1 = gleam@dynamic@decode:run(
_pipe,
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
gleam@result:replace_error(_pipe@1, eof).