Current section
Files
Jump to
Current section
Files
src/gleamy_lights.erl
-module(gleamy_lights).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([by_rgb/4, by_rgb_bg/4, by_hexcolour/2, by_colour/2, by_hexcolour_bg/2, by_colour_bg/2]).
-spec by_rgb(binary(), integer(), integer(), integer()) -> binary().
by_rgb(Msg, R, G, B) ->
F = fun() ->
<<<<<<<<<<<<<<<<"\x{001b}[38;2;"/utf8, (gleam@int:to_string(R))/binary>>/binary,
";"/utf8>>/binary,
(gleam@int:to_string(G))/binary>>/binary,
";"/utf8>>/binary,
(gleam@int:to_string(B))/binary>>/binary,
"m"/utf8>>/binary,
Msg/binary>>/binary,
"\x{001b}[0m"/utf8>>
end,
case envoy_ffi:get(<<"NO_COLOR"/utf8>>) of
{ok, <<""/utf8>>} ->
F();
{ok, _} ->
Msg;
_ ->
F()
end.
-spec by_rgb_bg(binary(), integer(), integer(), integer()) -> binary().
by_rgb_bg(Msg, R, G, B) ->
<<<<<<<<<<<<<<<<"\x{001b}[48;2;"/utf8, (gleam@int:to_string(R))/binary>>/binary,
";"/utf8>>/binary,
(gleam@int:to_string(G))/binary>>/binary,
";"/utf8>>/binary,
(gleam@int:to_string(B))/binary>>/binary,
"m"/utf8>>/binary,
Msg/binary>>/binary,
"\x{001b}[0m"/utf8>>.
-spec hexcolour_to_rgb(binary()) -> list(integer()).
hexcolour_to_rgb(Hex) ->
Hexcolour = gleam@string:replace(Hex, <<"#"/utf8>>, <<""/utf8>>),
R@1 = case gleam@int:base_parse(gleam@string:slice(Hexcolour, 0, 2), 16) of
{ok, R} ->
R;
{error, _} ->
0
end,
G@1 = case gleam@int:base_parse(gleam@string:slice(Hexcolour, 2, 2), 16) of
{ok, G} ->
G;
{error, _} ->
0
end,
B@1 = case gleam@int:base_parse(gleam@string:slice(Hexcolour, 4, 2), 16) of
{ok, B} ->
B;
{error, _} ->
0
end,
[R@1, G@1, B@1].
-spec by_hexcolour(binary(), binary()) -> binary().
by_hexcolour(Msg, Hexcolour) ->
Rgb = hexcolour_to_rgb(Hexcolour),
_assert_subject = begin
_pipe = Rgb,
gleam@list:first(_pipe)
end,
{ok, R} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour"/utf8>>,
line => 143})
end,
_assert_subject@1 = begin
_pipe@1 = Rgb,
gleam@list:rest(_pipe@1)
end,
{ok, Rest} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour"/utf8>>,
line => 146})
end,
_assert_subject@2 = begin
_pipe@2 = Rest,
gleam@list:first(_pipe@2)
end,
{ok, G} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@2,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour"/utf8>>,
line => 149})
end,
_assert_subject@3 = begin
_pipe@3 = Rest,
gleam@list:rest(_pipe@3)
end,
{ok, Rest@1} = case _assert_subject@3 of
{ok, _} -> _assert_subject@3;
_assert_fail@3 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@3,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour"/utf8>>,
line => 152})
end,
_assert_subject@4 = begin
_pipe@4 = Rest@1,
gleam@list:first(_pipe@4)
end,
{ok, B} = case _assert_subject@4 of
{ok, _} -> _assert_subject@4;
_assert_fail@4 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@4,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour"/utf8>>,
line => 155})
end,
_pipe@5 = Msg,
by_rgb(_pipe@5, R, G, B).
-spec by_colour(binary(), gleam_community@colour:colour()) -> binary().
by_colour(Msg, Clr) ->
by_hexcolour(Msg, gleam_community@colour:to_rgb_hex_string(Clr)).
-spec by_hexcolour_bg(binary(), binary()) -> binary().
by_hexcolour_bg(Msg, Hexcolour) ->
Rgb = hexcolour_to_rgb(Hexcolour),
_assert_subject = begin
_pipe = Rgb,
gleam@list:first(_pipe)
end,
{ok, R} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour_bg"/utf8>>,
line => 169})
end,
_assert_subject@1 = begin
_pipe@1 = Rgb,
gleam@list:rest(_pipe@1)
end,
{ok, Rest} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour_bg"/utf8>>,
line => 172})
end,
_assert_subject@2 = begin
_pipe@2 = Rest,
gleam@list:first(_pipe@2)
end,
{ok, G} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@2,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour_bg"/utf8>>,
line => 175})
end,
_assert_subject@3 = begin
_pipe@3 = Rest,
gleam@list:rest(_pipe@3)
end,
{ok, Rest@1} = case _assert_subject@3 of
{ok, _} -> _assert_subject@3;
_assert_fail@3 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@3,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour_bg"/utf8>>,
line => 178})
end,
_assert_subject@4 = begin
_pipe@4 = Rest@1,
gleam@list:first(_pipe@4)
end,
{ok, B} = case _assert_subject@4 of
{ok, _} -> _assert_subject@4;
_assert_fail@4 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@4,
module => <<"gleamy_lights"/utf8>>,
function => <<"by_hexcolour_bg"/utf8>>,
line => 181})
end,
_pipe@5 = Msg,
by_rgb_bg(_pipe@5, R, G, B).
-spec by_colour_bg(binary(), gleam_community@colour:colour()) -> binary().
by_colour_bg(Msg, Clr) ->
by_hexcolour_bg(Msg, gleam_community@colour:to_rgb_hex_string(Clr)).