Current section

Files

Jump to
gu src gu.erl
Raw

src/gu.erl

-module(gu).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([help_all/1, about/1, version/1, set_modal/1, new_list/1, add_row/2, new_forms/1, set_show_header/1, add_value/2, add_value_if/3, add_opt/3, set_text/2, set_title/2, set_width/2, set_height/2, set_timeout/2, set_ok_label/2, set_cancel_label/2, add_extra_button/2, add_column/2, add_entry/2, add_password/2, add_calendar/2, add_combo_and_values/3, set_separator/2, set_forms_date_format/2, add_opt_if/4, add_opt_int/3, new_calendar/6, add_opt_list/3, add_list_and_values/4, add_bool/3, new_message_opts/6, new_entry/4, new_file_selection/7, new_list_opts/10, new_notification/4, new_progress/8, new_question_opts/3, new_scale/8, new_text_info/6, new_color_selection/3, new_password/2, parse/1, parse_list/2, run/2, show_in/3, show/2, exit/1, new_error/1, new_info/1, new_question/1, new_warning/1]).
-spec help_all(list(binary())) -> list(binary()).
help_all(Command) ->
[<<"--help-all"/utf8>> | Command].
-spec about(list(binary())) -> list(binary()).
about(Command) ->
[<<"--about"/utf8>> | Command].
-spec version(list(binary())) -> list(binary()).
version(Command) ->
[<<"--version"/utf8>> | Command].
-spec set_modal(list(binary())) -> list(binary()).
set_modal(Command) ->
[<<"--modal"/utf8>> | Command].
-spec new_list(list(binary())) -> list(binary()).
new_list(Command) ->
[<<"--list"/utf8>> | Command].
-spec add_row(list(binary()), list(binary())) -> list(binary()).
add_row(Command, Row) ->
_pipe = Row,
_pipe@1 = lists:reverse(_pipe),
lists:append(_pipe@1, Command).
-spec new_forms(list(binary())) -> list(binary()).
new_forms(Command) ->
[<<"--forms"/utf8>> | Command].
-spec set_show_header(list(binary())) -> list(binary()).
set_show_header(Command) ->
[<<"--show-header"/utf8>> | Command].
-spec add_value(list(binary()), binary()) -> list(binary()).
add_value(Command, Value) ->
[Value | Command].
-spec add_value_if(list(binary()), boolean(), binary()) -> list(binary()).
add_value_if(Command, Condition, Value) ->
case Condition of
true ->
add_value(Command, Value);
false ->
Command
end.
-spec add_opt(list(binary()), gleam@option:option(binary()), binary()) -> list(binary()).
add_opt(Command, Opt, Str) ->
case Opt of
{some, Val} ->
[<<<<<<"--"/utf8, Str/binary>>/binary, "="/utf8>>/binary,
Val/binary>> |
Command];
none ->
Command
end.
-spec set_text(list(binary()), binary()) -> list(binary()).
set_text(Command, Text) ->
add_opt(Command, {some, Text}, <<"text"/utf8>>).
-spec set_title(list(binary()), binary()) -> list(binary()).
set_title(Command, Title) ->
add_opt(Command, {some, Title}, <<"title"/utf8>>).
-spec set_width(list(binary()), integer()) -> list(binary()).
set_width(Command, Width) ->
add_opt(Command, {some, gleam@int:to_string(Width)}, <<"width"/utf8>>).
-spec set_height(list(binary()), integer()) -> list(binary()).
set_height(Command, Height) ->
add_opt(Command, {some, gleam@int:to_string(Height)}, <<"height"/utf8>>).
-spec set_timeout(list(binary()), integer()) -> list(binary()).
set_timeout(Command, Timeout) ->
add_opt(Command, {some, gleam@int:to_string(Timeout)}, <<"timeout"/utf8>>).
-spec set_ok_label(list(binary()), binary()) -> list(binary()).
set_ok_label(Command, Ok_label) ->
add_opt(Command, {some, Ok_label}, <<"ok-label"/utf8>>).
-spec set_cancel_label(list(binary()), binary()) -> list(binary()).
set_cancel_label(Command, Cancel_label) ->
add_opt(Command, {some, Cancel_label}, <<"cancel-label"/utf8>>).
-spec add_extra_button(list(binary()), binary()) -> list(binary()).
add_extra_button(Command, Extra_button) ->
add_opt(Command, {some, Extra_button}, <<"extra-button"/utf8>>).
-spec add_column(list(binary()), binary()) -> list(binary()).
add_column(Command, Column) ->
add_opt(Command, {some, Column}, <<"column"/utf8>>).
-spec add_entry(list(binary()), binary()) -> list(binary()).
add_entry(Command, Entry) ->
add_opt(Command, {some, Entry}, <<"add-entry"/utf8>>).
-spec add_password(list(binary()), binary()) -> list(binary()).
add_password(Command, Password) ->
add_opt(Command, {some, Password}, <<"add-password"/utf8>>).
-spec add_calendar(list(binary()), binary()) -> list(binary()).
add_calendar(Command, Calendar) ->
add_opt(Command, {some, Calendar}, <<"add-calendar"/utf8>>).
-spec add_combo_and_values(list(binary()), binary(), list(binary())) -> list(binary()).
add_combo_and_values(Command, Combo, Values) ->
_pipe = Command,
_pipe@1 = add_opt(_pipe, {some, Combo}, <<"add-combo"/utf8>>),
add_opt(
_pipe@1,
{some, gleam@string:join(Values, <<"|"/utf8>>)},
<<"combo-values"/utf8>>
).
-spec set_separator(list(binary()), binary()) -> list(binary()).
set_separator(Command, Separator) ->
add_opt(Command, {some, Separator}, <<"separator"/utf8>>).
-spec set_forms_date_format(list(binary()), binary()) -> list(binary()).
set_forms_date_format(Command, Format) ->
add_opt(Command, {some, Format}, <<"forms-date-format"/utf8>>).
-spec add_opt_if(list(binary()), boolean(), binary(), binary()) -> list(binary()).
add_opt_if(Command, Condition, Opt, Str) ->
case Condition of
true ->
add_opt(Command, {some, Opt}, Str);
false ->
Command
end.
-spec add_opt_int(list(binary()), gleam@option:option(integer()), binary()) -> list(binary()).
add_opt_int(Command, Opt, Str) ->
case Opt of
{some, Val} ->
[<<<<<<"--"/utf8, Str/binary>>/binary, "="/utf8>>/binary,
(gleam@int:to_string(Val))/binary>> |
Command];
none ->
Command
end.
-spec new_calendar(
list(binary()),
gleam@option:option(binary()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(binary())
) -> list(binary()).
new_calendar(Command, Text, Day, Month, Year, Date_format) ->
_pipe = [<<"--calendar"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Text, <<"text"/utf8>>),
_pipe@2 = add_opt_int(_pipe@1, Day, <<"day"/utf8>>),
_pipe@3 = add_opt_int(_pipe@2, Month, <<"month"/utf8>>),
_pipe@4 = add_opt_int(_pipe@3, Year, <<"year"/utf8>>),
add_opt(_pipe@4, Date_format, <<"date-format"/utf8>>).
-spec add_opt_list(
list(binary()),
gleam@option:option(list(binary())),
binary()
) -> list(binary()).
add_opt_list(Command, Opt_list, Str) ->
case Opt_list of
{some, Val} ->
[<<<<<<"--"/utf8, Str/binary>>/binary, "="/utf8>>/binary,
(gleam@string:join(Val, <<"|"/utf8>>))/binary>> |
Command];
none ->
Command
end.
-spec add_list_and_values(
list(binary()),
binary(),
list(binary()),
gleam@option:option(list(binary()))
) -> list(binary()).
add_list_and_values(Command, List_name, Values, Column_values) ->
_pipe = Command,
_pipe@1 = add_opt(_pipe, {some, List_name}, <<"add-list"/utf8>>),
_pipe@2 = add_opt(
_pipe@1,
{some, gleam@string:join(Values, <<"|"/utf8>>)},
<<"list-values"/utf8>>
),
add_opt_list(_pipe@2, Column_values, <<"column-values"/utf8>>).
-spec add_bool(list(binary()), boolean(), binary()) -> list(binary()).
add_bool(Command, Condition, Str) ->
case Condition of
true ->
[<<"--"/utf8, Str/binary>> | Command];
false ->
Command
end.
-spec new_message_opts(
list(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
boolean(),
boolean(),
boolean()
) -> list(binary()).
new_message_opts(Command, Text, Icon, No_wrap, No_markup, Ellipsize) ->
_pipe = Command,
_pipe@1 = add_opt(_pipe, Text, <<"text"/utf8>>),
_pipe@2 = add_opt(_pipe@1, Icon, <<"icon"/utf8>>),
_pipe@3 = add_bool(_pipe@2, No_wrap, <<"no-wrap"/utf8>>),
_pipe@4 = add_bool(_pipe@3, No_markup, <<"no-markup"/utf8>>),
add_bool(_pipe@4, Ellipsize, <<"ellipsize"/utf8>>).
-spec new_entry(
list(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
boolean()
) -> list(binary()).
new_entry(Command, Text, Entry_text, Hide_text) ->
_pipe = [<<"--entry"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Text, <<"text"/utf8>>),
_pipe@2 = add_opt(_pipe@1, Entry_text, <<"entry-text"/utf8>>),
add_bool(_pipe@2, Hide_text, <<"hide-text"/utf8>>).
-spec new_file_selection(
list(binary()),
gleam@option:option(binary()),
boolean(),
boolean(),
boolean(),
gleam@option:option(binary()),
gleam@option:option(list(binary()))
) -> list(binary()).
new_file_selection(
Command,
Filename,
Multiple,
Directory,
Save,
Separator,
File_filter
) ->
_pipe = [<<"--file-selection"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Filename, <<"filename"/utf8>>),
_pipe@2 = add_bool(_pipe@1, Multiple, <<"multiple"/utf8>>),
_pipe@3 = add_bool(_pipe@2, Directory, <<"directory"/utf8>>),
_pipe@4 = add_bool(_pipe@3, Save, <<"save"/utf8>>),
_pipe@5 = add_opt(_pipe@4, Separator, <<"separator"/utf8>>),
add_opt_list(_pipe@5, File_filter, <<"file-filter"/utf8>>).
-spec new_list_opts(
list(binary()),
boolean(),
boolean(),
boolean(),
gleam@option:option(binary()),
boolean(),
boolean(),
gleam@option:option(binary()),
gleam@option:option(integer()),
boolean()
) -> list(binary()).
new_list_opts(
Command,
Checklist,
Radiolist,
Imagelist,
Separator,
Multiple,
Editable,
Print_column,
Hide_column,
Hide_header
) ->
_pipe = Command,
_pipe@1 = add_bool(_pipe, Checklist, <<"checklist"/utf8>>),
_pipe@2 = add_bool(_pipe@1, Radiolist, <<"radiolist"/utf8>>),
_pipe@3 = add_bool(_pipe@2, Imagelist, <<"imagelist"/utf8>>),
_pipe@4 = add_opt(_pipe@3, Separator, <<"separator"/utf8>>),
_pipe@5 = add_bool(_pipe@4, Multiple, <<"multiple"/utf8>>),
_pipe@6 = add_bool(_pipe@5, Editable, <<"editable"/utf8>>),
_pipe@7 = add_opt(_pipe@6, Print_column, <<"print-column"/utf8>>),
_pipe@8 = add_opt_int(_pipe@7, Hide_column, <<"hide-column"/utf8>>),
add_bool(_pipe@8, Hide_header, <<"hide-header"/utf8>>).
-spec new_notification(
list(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
boolean()
) -> list(binary()).
new_notification(Command, Text, Icon, Listen) ->
_pipe = [<<"--notification"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Text, <<"text"/utf8>>),
_pipe@2 = add_opt(_pipe@1, Icon, <<"icon"/utf8>>),
add_bool(_pipe@2, Listen, <<"listen"/utf8>>).
-spec new_progress(
list(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
boolean(),
boolean(),
boolean(),
boolean(),
boolean()
) -> list(binary()).
new_progress(
Command,
Text,
Percentage,
Pulsate,
Auto_close,
Auto_kill,
No_cancel,
Time_remaining
) ->
_pipe = [<<"--progress"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Text, <<"text"/utf8>>),
_pipe@2 = add_opt(_pipe@1, Percentage, <<"percentage"/utf8>>),
_pipe@3 = add_bool(_pipe@2, Pulsate, <<"pulsate"/utf8>>),
_pipe@4 = add_bool(_pipe@3, Auto_close, <<"auto-close"/utf8>>),
_pipe@5 = add_bool(_pipe@4, Auto_kill, <<"auto-kill"/utf8>>),
_pipe@6 = add_bool(_pipe@5, No_cancel, <<"no-cancel"/utf8>>),
add_bool(_pipe@6, Time_remaining, <<"time-remaining"/utf8>>).
-spec new_question_opts(list(binary()), boolean(), boolean()) -> list(binary()).
new_question_opts(Command, Default_cancel, Switch) ->
_pipe = Command,
_pipe@1 = add_bool(_pipe, Default_cancel, <<"default-cancel"/utf8>>),
add_bool(_pipe@1, Switch, <<"switch"/utf8>>).
-spec new_scale(
list(binary()),
gleam@option:option(binary()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(integer()),
boolean(),
boolean()
) -> list(binary()).
new_scale(
Command,
Text,
Value,
Min_value,
Max_value,
Step,
Print_partial,
Hide_value
) ->
_pipe = [<<"--scale"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Text, <<"text"/utf8>>),
_pipe@2 = add_opt_int(_pipe@1, Value, <<"value"/utf8>>),
_pipe@3 = add_opt_int(_pipe@2, Min_value, <<"min-value"/utf8>>),
_pipe@4 = add_opt_int(_pipe@3, Max_value, <<"max-value"/utf8>>),
_pipe@5 = add_opt_int(_pipe@4, Step, <<"step"/utf8>>),
_pipe@6 = add_bool(_pipe@5, Print_partial, <<"print-partial"/utf8>>),
add_bool(_pipe@6, Hide_value, <<"hide-value"/utf8>>).
-spec new_text_info(
list(binary()),
gleam@option:option(binary()),
boolean(),
gleam@option:option(binary()),
gleam@option:option(binary()),
boolean()
) -> list(binary()).
new_text_info(Command, Filename, Editable, Font, Checkbox, Auto_scroll) ->
_pipe = [<<"--text-info"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Filename, <<"filename"/utf8>>),
_pipe@2 = add_bool(_pipe@1, Editable, <<"editable"/utf8>>),
_pipe@3 = add_opt(_pipe@2, Font, <<"font"/utf8>>),
_pipe@4 = add_opt(_pipe@3, Checkbox, <<"checkbox"/utf8>>),
add_bool(_pipe@4, Auto_scroll, <<"auto-scroll"/utf8>>).
-spec new_color_selection(
list(binary()),
gleam@option:option(binary()),
boolean()
) -> list(binary()).
new_color_selection(Command, Color, Show_palette) ->
_pipe = [<<"--color-selection"/utf8>> | Command],
_pipe@1 = add_opt(_pipe, Color, <<"color"/utf8>>),
add_bool(_pipe@1, Show_palette, <<"show-palette"/utf8>>).
-spec new_password(list(binary()), boolean()) -> list(binary()).
new_password(Command, Username) ->
_pipe = [<<"--password"/utf8>> | Command],
add_bool(_pipe, Username, <<"username"/utf8>>).
-spec parse(binary()) -> binary().
parse(Str) ->
_pipe = Str,
gleam@string:trim_right(_pipe).
-spec parse_list(binary(), binary()) -> list(binary()).
parse_list(Str, Separator) ->
_pipe = Str,
_pipe@1 = gleam@string:trim_right(_pipe),
gleam@string:split(_pipe@1, Separator).
-spec run(list(binary()), boolean()) -> gleam@option:option({integer(),
binary()}).
run(Command, Errors) ->
Opts = case Errors of
true ->
[];
false ->
[let_be_stderr]
end,
case lists:reverse(Command) of
[Run | With] ->
case shellout:command(Run, With, <<"."/utf8>>, Opts) of
{ok, Val} ->
{some, {0, Val}};
{error, Err} ->
case Errors of
true ->
{some, Err};
false ->
none
end
end;
_ ->
none
end.
-spec show_in(list(binary()), binary(), boolean()) -> {ok, binary()} |
{error, {integer(), binary()}}.
show_in(Command, In_dir, Capture_errors) ->
Opts = case Capture_errors of
true ->
[];
false ->
[let_be_stderr]
end,
case lists:reverse(Command) of
[Run | With] ->
shellout:command(Run, With, In_dir, Opts);
_ ->
erlang:error(#{gleam_error => panic,
message => <<"panic expression evaluated"/utf8>>,
module => <<"gu"/utf8>>,
function => <<"show_in"/utf8>>,
line => 459})
end.
-spec show(list(binary()), boolean()) -> {ok, binary()} |
{error, {integer(), binary()}}.
show(Command, Capture_errors) ->
show_in(Command, <<"."/utf8>>, Capture_errors).
-spec exit(integer()) -> nil.
exit(Status) ->
shellout_ffi:os_exit(Status).
-spec new_error(list(binary())) -> list(binary()).
new_error(Command) ->
[<<"--error"/utf8>> | Command].
-spec new_info(list(binary())) -> list(binary()).
new_info(Command) ->
[<<"--info"/utf8>> | Command].
-spec new_question(list(binary())) -> list(binary()).
new_question(Command) ->
[<<"--question"/utf8>> | Command].
-spec new_warning(list(binary())) -> list(binary()).
new_warning(Command) ->
[<<"--warning"/utf8>> | Command].