-module(terminal_link). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([terminal_link_to_string/1, terminal_supports_links/0]). -export_type([terminal_link/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. -type terminal_link() :: {terminal_link, binary(), binary(), gleam@option:option(binary())}. -file("src/terminal_link.gleam", 11). -spec terminal_link_to_string(terminal_link()) -> binary(). terminal_link_to_string(L) -> case erlang:element(4, L) of {some, Id} -> gleam@string:concat( [<<"\x{1b}]8;id="/utf8>>, Id, <<";"/utf8>>, erlang:element(2, L), <<"\x{1b}\\"/utf8>>, erlang:element(3, L), <<"\x{1b}]8;;\x{1b}\\"/utf8>>] ); none -> gleam@string:concat( [<<"\x{1b}]8;;"/utf8>>, erlang:element(2, L), <<"\x{1b}\\"/utf8>>, erlang:element(3, L), <<"\x{1b}]8;;\x{1b}\\"/utf8>>] ) end. -file("src/terminal_link.gleam", 36). -spec force_hyperlink_enabled() -> gleam@option:option(boolean()). force_hyperlink_enabled() -> case envoy_ffi:get(<<"FORCE_HYPERLINK"/utf8>>) of {ok, <<"0"/utf8>>} -> {some, false}; {ok, _} -> {some, true}; {error, _} -> none end. -file("src/terminal_link.gleam", 44). -spec is_domterm() -> boolean(). is_domterm() -> _pipe = envoy_ffi:get(<<"DOMTERM"/utf8>>), gleam@result:is_ok(_pipe). -file("src/terminal_link.gleam", 49). -spec is_windows_terminal() -> boolean(). is_windows_terminal() -> _pipe = envoy_ffi:get(<<"WT_SESSION"/utf8>>), gleam@result:is_ok(_pipe). -file("src/terminal_link.gleam", 54). -spec check_vte_version() -> boolean(). check_vte_version() -> case envoy_ffi:get(<<"VTE_VERSION"/utf8>>) of {ok, Value} -> _pipe = gleam_stdlib:parse_int(Value), _pipe@1 = gleam@result:map( _pipe, fun(Version) -> Version >= 5000 end ), gleam@result:unwrap(_pipe@1, false); {error, _} -> false end. -file("src/terminal_link.gleam", 65). -spec check_term_program_env() -> boolean(). check_term_program_env() -> case envoy_ffi:get(<<"TERM_PROGRAM"/utf8>>) of {ok, <<"Hyper"/utf8>>} -> true; {ok, <<"iTerm.app"/utf8>>} -> true; {ok, <<"terminology"/utf8>>} -> true; {ok, <<"WezTerm"/utf8>>} -> true; {ok, <<"vscode"/utf8>>} -> true; {ok, <<"ghostty"/utf8>>} -> true; {ok, _} -> false; {error, _} -> false end. -file("src/terminal_link.gleam", 78). -spec check_term_env() -> boolean(). check_term_env() -> case envoy_ffi:get(<<"TERM"/utf8>>) of {ok, <<"xterm-kitty"/utf8>>} -> true; {ok, <<"alacritty"/utf8>>} -> true; {ok, <<"alacritty-direct"/utf8>>} -> true; {ok, _} -> false; {error, _} -> false end. -file("src/terminal_link.gleam", 88). -spec check_colorterm_env() -> boolean(). check_colorterm_env() -> case envoy_ffi:get(<<"COLORTERM"/utf8>>) of {ok, <<"xfce4-terminal"/utf8>>} -> true; {ok, _} -> false; {error, _} -> false end. -file("src/terminal_link.gleam", 96). -spec konsole_version_is_set() -> boolean(). konsole_version_is_set() -> _pipe = envoy_ffi:get(<<"KONSOLE_VERSION"/utf8>>), gleam@result:is_ok(_pipe). -file("src/terminal_link.gleam", 102). ?DOC(" Check if the terminal emulator supports clickable hyperlinks\n"). -spec terminal_supports_links() -> boolean(). terminal_supports_links() -> case force_hyperlink_enabled() of {some, Value} -> Value; none -> (((((is_domterm() orelse check_vte_version()) orelse check_term_program_env( )) orelse check_term_env()) orelse check_colorterm_env()) orelse is_windows_terminal()) orelse konsole_version_is_set() end.