Current section
Files
Jump to
Current section
Files
src/examples@styles.erl
-module(examples@styles).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/examples/styles.gleam").
-export([main/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.
?MODULEDOC(false).
-file("src/examples/styles.gleam", 86).
?DOC(false).
-spec make_rainbow(binary()) -> binary().
make_rainbow(S) ->
_pipe = S,
_pipe@1 = gleam@string:to_graphemes(_pipe),
_pipe@2 = gleam@list:index_map(_pipe@1, fun(S@1, I) -> case I rem 7 of
0 ->
etch@style:with(S@1, {rgb, 233, 51, 35});
1 ->
etch@style:with(S@1, {rgb, 241, 161, 57});
2 ->
etch@style:with(S@1, {ansi_value, 220});
3 ->
etch@style:with(S@1, {ansi_value, 40});
4 ->
etch@style:with(S@1, {rgb, 74, 163, 228});
5 ->
etch@style:with(S@1, blue);
6 ->
etch@style:with(S@1, magenta);
_ ->
erlang:error(#{gleam_error => panic,
message => <<"Unreachable"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"examples/styles"/utf8>>,
function => <<"make_rainbow"/utf8>>,
line => 98})
end end),
gleam@string:join(_pipe@2, <<""/utf8>>).
-file("src/examples/styles.gleam", 14).
?DOC(false).
-spec main() -> nil.
main() ->
Q = {queue, []},
Q@1 = begin
_pipe = Q,
etch@stdout:queue(
_pipe,
[{clear, all}, {move_to, 0, 0}, enable_line_wrap]
)
end,
X = begin
_pipe@1 = <<"Hi! This one is dim, italic, blinking, underlined with inversed colors! (your terminal may not support some attributes)."/utf8>>,
_pipe@2 = etch@style:dim(_pipe@1),
_pipe@3 = etch@style:italic(_pipe@2),
_pipe@4 = etch@style:blinking(_pipe@3),
_pipe@5 = etch@style:inverse(_pipe@4),
etch@style:underline(_pipe@5)
end,
Y = <<<<(begin
_pipe@6 = <<"`command.PrintlnReset()` resets our color. Now we can use different styles. This one is magenta "/utf8>>,
_pipe@7 = etch@style:bold(_pipe@6),
_pipe@8 = etch@style:italic(_pipe@7),
etch@style:with(_pipe@8, magenta)
end)/binary,
(begin
_pipe@9 = <<"and this is on dark turquoise. "/utf8>>,
_pipe@10 = etch@style:bold(_pipe@9),
_pipe@11 = etch@style:italic(_pipe@10),
etch@style:on(_pipe@11, {ansi_value, 44})
end)/binary>>/binary,
(begin
_pipe@12 = <<"As you can see, we can easily apply different styles."/utf8>>,
_pipe@13 = etch@style:dim(_pipe@12),
_pipe@14 = etch@style:inverse(_pipe@13),
etch@style:underline(_pipe@14)
end)/binary>>,
Z = <<<<<<<<(begin
_pipe@15 = <<"Hi from ETCH! YAAAAAY! "/utf8>>,
_pipe@16 = make_rainbow(_pipe@15),
etch@style:reset_color(_pipe@16)
end)/binary,
"We defined "/utf8>>/binary,
(begin
_pipe@17 = <<"`make_rainbow`"/utf8>>,
_pipe@18 = etch@style:attributes(
_pipe@17,
[italic, bold, underline]
),
etch@style:reset_attributes(_pipe@18)
end)/binary>>/binary,
" function and made this text "/utf8>>/binary,
(begin
_pipe@19 = <<"RAINBOW!"/utf8>>,
make_rainbow(_pipe@19)
end)/binary>>,
A = <<"And now the colors are reset after we call `command.ResetColors`. Try commenting it and this text will turn red, because we never reset the color after using `make_rainbow`."/utf8>>,
Q@2 = begin
_pipe@20 = Q@1,
etch@stdout:queue(
_pipe@20,
[{println_reset, X},
{print_reset, Y},
{move_to_next_line, 1},
{println, Z},
reset_style,
{print, A},
{move_to_next_line, 2}]
)
end,
etch@stdout:flush(Q@2),
etch@stdout:execute(
[{println,
begin
_pipe@21 = <<"We can use ANSI color values. This one is DarkSlateGray3 with HotPink3 background."/utf8>>,
etch@style:with_on(
_pipe@21,
{ansi_value, 116},
{ansi_value, 168}
)
end},
{move_to_next_line, 1},
{println,
<<"The colors are not reset again, because `with_on` does not reset them after applying."/utf8>>}]
).