-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", 55). ?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 => <>, module => <<"examples/styles"/utf8>>, function => <<"make_rainbow"/utf8>>, line => 67}) end end), _pipe@3 = gleam@string:join(_pipe@2, <<""/utf8>>), etch@style:reset_color(_pipe@3). -file("src/examples/styles.gleam", 10). ?DOC(false). -spec main() -> nil. main() -> etch@stdout:execute([{clear, all}, {move_to, 0, 0}]), Line1 = <<"This example shows how to apply some style to a text."/utf8>>, Line2 = <<<<<<<<<<"We can use"/utf8, (begin _pipe = <<"`with`"/utf8>>, etch@style:with(_pipe, bright_red) end)/binary>>/binary, ","/utf8>>/binary, (begin _pipe@1 = <<"`on`"/utf8>>, etch@style:on(_pipe@1, bright_green) end)/binary>>/binary, "and "/utf8>>/binary, (begin _pipe@2 = <<"`with_on`."/utf8>>, etch@style:with_on(_pipe@2, magenta, bright_yellow) end)/binary>>, Line3 = <<"(Note that if you want to set both foreground and background, `with_on` is slightly faster than `with` and `on`)."/utf8>>, Line4 = begin _pipe@3 = <<"And we can also apply attributes using `attributes`. This line is bold, italic and with inversed colors."/utf8>>, etch@style:attributes(_pipe@3, [bold, italic, inverse]) end, etch@stdout:execute( [{println, Line1}, {println, Line2}, {println, Line3}, {println_reset, Line4}] ), Line5 = <<"As you can see, none of these functions reset colors or attributes. To reset it, we called PrintlnReset command at the previous line."/utf8>>, etch@stdout:execute([{println, Line5}]), Line6 = <<<<<<<<<<<<"If we call commands like "/utf8, (begin _pipe@4 = <<"`red`"/utf8>>, etch@style:red(_pipe@4) end)/binary>>/binary, ", "/utf8>>/binary, (begin _pipe@5 = <<"`on_green`"/utf8>>, etch@style:on_green(_pipe@5) end)/binary>>/binary, ", "/utf8>>/binary, (begin _pipe@6 = <<"`underline`"/utf8>>, etch@style:underline(_pipe@6) end)/binary>>/binary, ", they reset their color/attribute after calling them."/utf8>>, etch@stdout:execute([{println, Line6}]), Line7 = <<<<<<"Commands that do not reset applied style are still useful."/utf8, "We can define some function that utilizes this feature. Like "/utf8>>/binary, (begin _pipe@7 = <<"`make_rainbow`"/utf8>>, make_rainbow(_pipe@7) end)/binary>>/binary, " It's a neat function!"/utf8>>, Line8 = begin _pipe@8 = <<"HI FROM ETCH! YAAAAAAAAAAAAAY!"/utf8>>, make_rainbow(_pipe@8) end, etch@stdout:execute([{println, Line7}, {println, Line8}]).