Skip to main content

src/spruce@symbol.erl

-module(spruce@symbol).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/spruce/symbol.gleam").
-export([resolve/3, status/2]).
-export_type([mode/0, status/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(
    " Named terminal glyphs and ASCII fallbacks.\n"
    "\n"
    " Use the Unicode constants for rich terminal output, and the `_ascii`\n"
    " constants when output must stay plain ASCII.\n"
).

-type mode() :: unicode | ascii.

-type status() :: info |
    warn |
    error |
    success |
    start |
    trace |
    debug |
    notice |
    alert |
    bullet |
    arrow.

-file("src/spruce/symbol.gleam", 82).
?DOC(" Resolve a glyph pair according to the requested mode.\n").
-spec resolve(mode(), binary(), binary()) -> binary().
resolve(Mode, Unicode, Ascii) ->
    case Mode of
        unicode ->
            Unicode;

        ascii ->
            Ascii
    end.

-file("src/spruce/symbol.gleam", 94).
?DOC(" Resolve a named status glyph according to the requested mode.\n").
-spec status(mode(), status()) -> binary().
status(Mode, Status) ->
    case {Status, Mode} of
        {info, unicode} ->
            <<"ℹ"/utf8>>;

        {info, ascii} ->
            <<"i"/utf8>>;

        {warn, unicode} ->
            <<"⚠"/utf8>>;

        {warn, ascii} ->
            <<"!"/utf8>>;

        {error, unicode} ->
            <<"✖"/utf8>>;

        {error, ascii} ->
            <<"x"/utf8>>;

        {success, unicode} ->
            <<"✔"/utf8>>;

        {success, ascii} ->
            <<"+"/utf8>>;

        {start, unicode} ->
            <<"◐"/utf8>>;

        {start, ascii} ->
            <<"*"/utf8>>;

        {trace, unicode} ->
            <<"→"/utf8>>;

        {trace, ascii} ->
            <<">"/utf8>>;

        {debug, unicode} ->
            <<"⚙"/utf8>>;

        {debug, ascii} ->
            <<"*"/utf8>>;

        {notice, unicode} ->
            <<"◉"/utf8>>;

        {notice, ascii} ->
            <<"o"/utf8>>;

        {alert, unicode} ->
            <<"‼"/utf8>>;

        {alert, ascii} ->
            <<"!!"/utf8>>;

        {bullet, unicode} ->
            <<"•"/utf8>>;

        {bullet, ascii} ->
            <<"-"/utf8>>;

        {arrow, unicode} ->
            <<"▸"/utf8>>;

        {arrow, ascii} ->
            <<">"/utf8>>
    end.