From d72e2cda09df280e1e690d9233790ebbb9e58812 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 14 Sep 2013 13:15:47 -0500 Subject: improved user output look --- src/rlx_app_discovery.erl | 4 ++-- src/rlx_log.erl | 34 +++++++++++++++++++++++++++------- src/rlx_prv_assembler.erl | 10 +++++----- src/rlx_prv_overlay.erl | 2 +- src/rlx_prv_release.erl | 2 +- src/rlx_rel_discovery.erl | 4 ++-- src/rlx_release.erl | 10 +++++----- src/rlx_state.erl | 22 +++++++++++----------- src/rlx_topo.erl | 4 ++-- src/rlx_util.erl | 2 +- 10 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/rlx_app_discovery.erl b/src/rlx_app_discovery.erl index e6b6e2c..6407124 100644 --- a/src/rlx_app_discovery.erl +++ b/src/rlx_app_discovery.erl @@ -40,7 +40,7 @@ do(State, LibDirs) -> rlx_log:info(rlx_state:log(State), fun() -> ["Resolving OTP Applications from directories:\n", - [[rlx_util:indent(1), LibDir, "\n"] || LibDir <- LibDirs]] + [[rlx_util:indent(2), LibDir, "\n"] || LibDir <- LibDirs]] end), resolve_app_metadata(State, LibDirs). @@ -72,7 +72,7 @@ resolve_app_metadata(State, LibDirs) -> rlx_log:debug(rlx_state:log(State), fun() -> ["Resolved the following OTP Applications from the system: \n", - [[rlx_app_info:format(1, App), "\n"] || App <- AppMeta1]] + [[rlx_app_info:format(2, App), "\n"] || App <- AppMeta1]] end), {ok, AppMeta1}; Errors -> diff --git a/src/rlx_log.erl b/src/rlx_log.erl index 901ae7c..6122e9b 100644 --- a/src/rlx_log.erl +++ b/src/rlx_log.erl @@ -59,6 +59,17 @@ -type log_fun() :: fun(() -> iolist()). +-type color() :: 31..36. + +-define(RED, 31). +-define(GREEN, 32). +-define(YELLOW, 33). +-define(BLUE, 34). +-define(MAGENTA, 35). +-define(CYAN, 36). + +-define(PREFIX, "===> "). + %%============================================================================ %% API %%============================================================================ @@ -83,7 +94,7 @@ new(AtomLogLevel) -spec debug(t(), string() | log_fun()) -> ok. debug(LogState, Fun) when erlang:is_function(Fun) -> - log(LogState, ?RLX_DEBUG, Fun); + log(LogState, ?RLX_DEBUG, fun() -> colorize(?CYAN, false, Fun()) end); debug(LogState, String) -> debug(LogState, "~s~n", [String]). @@ -91,14 +102,14 @@ debug(LogState, String) -> %% and argements @see io:format/2 -spec debug(t(), string(), [any()]) -> ok. debug(LogState, FormatString, Args) -> - log(LogState, ?RLX_DEBUG, FormatString, Args). + log(LogState, ?RLX_DEBUG, colorize(?CYAN, false, FormatString), Args). %% @doc log at the info level given the current log state with a string or %% function that returns a string -spec info(t(), string() | log_fun()) -> ok. info(LogState, Fun) when erlang:is_function(Fun) -> - log(LogState, ?RLX_INFO, Fun); + log(LogState, ?RLX_INFO, fun() -> colorize(?GREEN, false, Fun()) end); info(LogState, String) -> info(LogState, "~s~n", [String]). @@ -106,14 +117,14 @@ info(LogState, String) -> %% and argements @see io:format/2 -spec info(t(), string(), [any()]) -> ok. info(LogState, FormatString, Args) -> - log(LogState, ?RLX_INFO, FormatString, Args). + log(LogState, ?RLX_INFO, colorize(?GREEN, false, FormatString), Args). %% @doc log at the error level given the current log state with a string or %% format string that returns a function -spec error(t(), string() | log_fun()) -> ok. error(LogState, Fun) when erlang:is_function(Fun) -> - log(LogState, ?RLX_ERROR, Fun); + log(LogState, ?RLX_ERROR, fun() -> colorize(?RED, false, Fun()) end); error(LogState, String) -> error(LogState, "~s~n", [String]). @@ -121,7 +132,7 @@ error(LogState, String) -> %% and argements @see io:format/2 -spec error(t(), string(), [any()]) -> ok. error(LogState, FormatString, Args) -> - log(LogState, ?RLX_ERROR, FormatString, Args). + log(LogState, ?RLX_ERROR, colorize(?GREEN, false, FormatString), Args). %% @doc Execute the fun passed in if log level is as expected. -spec log(t(), int_log_level(), log_fun()) -> ok. @@ -131,7 +142,6 @@ log({?MODULE, DetailLogLevel}, LogLevel, Fun) log(_, _, _) -> ok. - %% @doc when the module log level is less then or equal to the log level for the %% call then write the log info out. When its not then ignore the call. -spec log(t(), int_log_level(), string(), [any()]) -> ok. @@ -172,6 +182,16 @@ format(Log) -> erlang:atom_to_list(atom_log_level(Log)), <<")">>]. +-spec colorize(color(), boolean(), string()) -> string(). +colorize(Color, false, Msg) when is_integer(Color) -> + colorize_(Color, 0, Msg); +colorize(Color, true, Msg) when is_integer(Color) -> + colorize_(Color, 1, Msg). + +-spec colorize_(color(), integer(), string()) -> string(). +colorize_(Color, Bold, Msg) when is_integer(Color), is_integer(Bold)-> + lists:flatten(io_lib:format("\033[~B;~Bm~s~s\033[0m", [Bold, Color, ?PREFIX, Msg])). + %%%=================================================================== %%% Test Functions %%%=================================================================== diff --git a/src/rlx_prv_assembler.erl b/src/rlx_prv_assembler.erl index 70c38ec..d47a850 100644 --- a/src/rlx_prv_assembler.erl +++ b/src/rlx_prv_assembler.erl @@ -101,19 +101,19 @@ format_error({release_script_generation_error, RelFile}) -> [RelFile]); format_error({release_script_generation_warning, Module, Warnings}) -> ["Warnings generating release \s", - rlx_util:indent(1), Module:format_warning(Warnings)]; + rlx_util:indent(2), Module:format_warning(Warnings)]; format_error({unable_to_create_output_dir, OutputDir}) -> io_lib:format("Unable to create output directory (possible permissions issue): ~s", [OutputDir]); format_error({release_script_generation_error, Module, Errors}) -> ["Errors generating release \n", - rlx_util:indent(1), Module:format_error(Errors)]; + rlx_util:indent(2), Module:format_error(Errors)]; format_error({relup_generation_error, CurrentName, UpFromName}) -> io_lib:format("Unknown internal release error generating the relup from ~s to ~s", [UpFromName, CurrentName]); format_error({relup_generation_warning, Module, Warnings}) -> ["Warnings generating relup \s", - rlx_util:indent(1), Module:format_warning(Warnings)]; + rlx_util:indent(2), Module:format_warning(Warnings)]; format_error({relup_script_generation_error, {relup_script_generation_error, systools_relup, {missing_sasl, _}}}) -> @@ -121,10 +121,10 @@ format_error({relup_script_generation_error, "in both the current release and the release to upgrade from."; format_error({relup_script_generation_error, Module, Errors}) -> ["Errors generating relup \n", - rlx_util:indent(1), Module:format_error(Errors)]; + rlx_util:indent(2), Module:format_error(Errors)]; format_error({unable_to_make_symlink, AppDir, TargetDir, Reason}) -> io_lib:format("Unable to symlink directory ~s to ~s because \n~s~s", - [AppDir, TargetDir, rlx_util:indent(1), + [AppDir, TargetDir, rlx_util:indent(2), file:format_error(Reason)]); format_error({tar_unknown_generation_error, Module, Vsn}) -> io_lib:format("Tarball generation error of ~s ~s", diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl index f242d21..e1edb6c 100644 --- a/src/rlx_prv_overlay.erl +++ b/src/rlx_prv_overlay.erl @@ -68,7 +68,7 @@ format_error({dir_render_failed, Dir, Error}) -> [Dir, Error]); format_error({unable_to_make_symlink, AppDir, TargetDir, Reason}) -> io_lib:format("Unable to symlink directory ~s to ~s because \n~s~s", - [AppDir, TargetDir, rlx_util:indent(1), + [AppDir, TargetDir, rlx_util:indent(2), file:format_error(Reason)]); format_error({copy_failed, FromFile, ToFile, Err}) -> io_lib:format("Unable to copy from ~s to ~s because of ~p", diff --git a/src/rlx_prv_release.erl b/src/rlx_prv_release.erl index cf13953..908573b 100644 --- a/src/rlx_prv_release.erl +++ b/src/rlx_prv_release.erl @@ -175,7 +175,7 @@ set_resolved(State, Release0, Pkgs) -> rlx_release:vsn(Release1)]), rlx_log:debug(rlx_state:log(State), fun() -> - rlx_release:format(1, Release1) + rlx_release:format(0, Release1) end), {ok, rlx_state:add_realized_release(State, Release1)}; {error, E} -> diff --git a/src/rlx_rel_discovery.erl b/src/rlx_rel_discovery.erl index 3cdca3e..6f23ad0 100644 --- a/src/rlx_rel_discovery.erl +++ b/src/rlx_rel_discovery.erl @@ -40,8 +40,8 @@ do(State, LibDirs, AppMeta) -> rlx_log:info(rlx_state:log(State), fun() -> - ["Resolving available releases from directories:\n", - [[rlx_util:indent(1), LibDir, "\n"] || LibDir <- LibDirs]] + ["Resolving available OTP Releases from directories:\n", + [[rlx_util:indent(2), LibDir, "\n"] || LibDir <- LibDirs]] end), resolve_rel_metadata(State, LibDirs, AppMeta). diff --git a/src/rlx_release.erl b/src/rlx_release.erl index 68193fa..471a6f7 100644 --- a/src/rlx_release.erl +++ b/src/rlx_release.erl @@ -196,14 +196,14 @@ format(Indent, #release_t{name=Name, vsn=Vsn, erts=ErtsVsn, realized=Realized, goals = Goals, applications=Apps}) -> BaseIndent = rlx_util:indent(Indent), [BaseIndent, "release: ", rlx_util:to_string(Name), "-", Vsn, "\n", - rlx_util:indent(Indent + 1), " erts-", ErtsVsn, + rlx_util:indent(Indent + 2), " erts-", ErtsVsn, ", realized = ", erlang:atom_to_list(Realized), "\n", - BaseIndent, "goals: \n", - [[rlx_util:indent(Indent + 1), format_goal(Goal), ",\n"] || Goal <- Goals], + rlx_util:indent(Indent + 1), "goals: \n", + [[rlx_util:indent(Indent + 2), format_goal(Goal), ",\n"] || Goal <- Goals], case Realized of true -> - [BaseIndent, "applications: \n", - [[rlx_util:indent(Indent + 1), io_lib:format("~p", [App]), ",\n"] || + [rlx_util:indent(Indent + 1), "applications: \n", + [[rlx_util:indent(Indent + 2), io_lib:format("~p", [App]), ",\n"] || App <- Apps]]; false -> [] diff --git a/src/rlx_state.erl b/src/rlx_state.erl index 65b0565..81f6bef 100644 --- a/src/rlx_state.erl +++ b/src/rlx_state.erl @@ -319,17 +319,17 @@ format(#state_t{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, Values1 = ec_dictionary:to_list(Values0), [rlx_util:indent(Indent), <<"state(">>, erlang:atom_to_list(Caller), <<"):\n">>, - rlx_util:indent(Indent + 1), <<"log: ">>, rlx_log:format(LogState), <<",\n">>, - rlx_util:indent(Indent + 1), "config file: ", rlx_util:optional_to_string(ConfigFile), "\n", - rlx_util:indent(Indent + 1), "goals: \n", - [[rlx_util:indent(Indent + 2), rlx_depsolver:format_constraint(Goal), ",\n"] || Goal <- Goals], - rlx_util:indent(Indent + 1), "output_dir: ", OutDir, "\n", - rlx_util:indent(Indent + 1), "lib_dirs: \n", - [[rlx_util:indent(Indent + 2), LibDir, ",\n"] || LibDir <- LibDirs], - rlx_util:indent(Indent + 1), "providers: \n", - [[rlx_util:indent(Indent + 2), rlx_provider:format(Provider), ",\n"] || Provider <- Providers], - rlx_util:indent(Indent + 1), "provider config values: \n", - [[rlx_util:indent(Indent + 2), io_lib:format("~p", [Value]), ",\n"] || Value <- Values1]]. + rlx_util:indent(Indent + 2), <<"log: ">>, rlx_log:format(LogState), <<",\n">>, + rlx_util:indent(Indent + 2), "config file: ", rlx_util:optional_to_string(ConfigFile), "\n", + rlx_util:indent(Indent + 2), "goals: \n", + [[rlx_util:indent(Indent + 3), rlx_depsolver:format_constraint(Goal), ",\n"] || Goal <- Goals], + rlx_util:indent(Indent + 2), "output_dir: ", OutDir, "\n", + rlx_util:indent(Indent + 2), "lib_dirs: \n", + [[rlx_util:indent(Indent + 3), LibDir, ",\n"] || LibDir <- LibDirs], + rlx_util:indent(Indent + 2), "providers: \n", + [[rlx_util:indent(Indent + 3), rlx_provider:format(Provider), ",\n"] || Provider <- Providers], + rlx_util:indent(Indent + 2), "provider config values: \n", + [[rlx_util:indent(Indent + 3), io_lib:format("~p", [Value]), ",\n"] || Value <- Values1]]. %%%=================================================================== %%% Internal Functions diff --git a/src/rlx_topo.erl b/src/rlx_topo.erl index 11928c1..1b3593b 100644 --- a/src/rlx_topo.erl +++ b/src/rlx_topo.erl @@ -71,9 +71,9 @@ format_error({cycle, Pairs}) -> "before we can continue:\n", case Pairs of [{P1, P2}] -> - [rlx_util:indent(1), erlang:atom_to_list(P2), "->", erlang:atom_to_list(P1)]; + [rlx_util:indent(2), erlang:atom_to_list(P2), "->", erlang:atom_to_list(P1)]; [{P1, P2} | Rest] -> - [rlx_util:indent(1), erlang:atom_to_list(P2), "->", erlang:atom_to_list(P1), + [rlx_util:indent(2), erlang:atom_to_list(P2), "->", erlang:atom_to_list(P1), [["-> ", erlang:atom_to_list(PP2), " -> ", erlang:atom_to_list(PP1)] || {PP1, PP2} <- Rest]]; [] -> [] diff --git a/src/rlx_util.erl b/src/rlx_util.erl index ac6af5c..53e9122 100644 --- a/src/rlx_util.erl +++ b/src/rlx_util.erl @@ -30,7 +30,7 @@ indent/1, optional_to_string/1]). --define(ONE_LEVEL_INDENT, " "). +-define(ONE_LEVEL_INDENT, " "). %%============================================================================ %% types %%============================================================================ -- cgit v1.2.3