Current section

Files

Jump to
shiny src ui@prompt.erl
Raw

src/ui@prompt.erl

-module(ui@prompt).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/ui/prompt.gleam").
-export([prompt/1, confirm/1, select_option/2]).
-file("src/ui/prompt.gleam", 7).
-spec prompt(binary()) -> binary().
prompt(Question) ->
gleam_stdlib:print(<<Question/binary, ": "/utf8>>),
_pipe = io:get_line(<<""/utf8>>),
gleam@string:trim(_pipe).
-file("src/ui/prompt.gleam", 12).
-spec confirm(binary()) -> boolean().
confirm(Question) ->
Answer = prompt(<<Question/binary, " (y/n)"/utf8>>),
case string:lowercase(Answer) of
<<"y"/utf8>> ->
true;
<<"yes"/utf8>> ->
true;
_ ->
false
end.
-file("src/ui/prompt.gleam", 20).
-spec select_option(binary(), list(binary())) -> binary().
select_option(Question, Options) ->
gleam_stdlib:println(Question),
gleam@list:index_map(
Options,
fun(Option, Index) ->
gleam_stdlib:println(
<<<<(erlang:integer_to_binary(Index + 1))/binary, ". "/utf8>>/binary,
Option/binary>>
)
end
),
Choice = prompt(<<"Select option"/utf8>>),
Options_length = erlang:length(Options),
case gleam_stdlib:parse_int(Choice) of
{ok, Num} when (Num > 0) andalso (Num =< Options_length) ->
case begin
_pipe = gleam@list:drop(Options, Num - 1),
gleam@list:first(_pipe)
end of
{ok, Option@1} ->
Option@1;
{error, _} ->
<<""/utf8>>
end;
_ ->
<<""/utf8>>
end.