diff --git a/lib/ring_logger.ex b/lib/ring_logger.ex index 7c8a148..772eae0 100644 --- a/lib/ring_logger.ex +++ b/lib/ring_logger.ex @@ -57,6 +57,7 @@ defmodule RingLogger do alias RingLogger.Autoclient alias RingLogger.Server + alias RingLogger.Viewer @typedoc "Option values used by the ring logger" @type server_option() :: @@ -193,11 +194,17 @@ defmodule RingLogger do @spec tail(non_neg_integer(), client_options()) :: :ok def tail(n, opts), do: Autoclient.tail(n, opts) + @doc """ + Starts the Ring Logger Viewer TUI app on the current prompt with intial arguments + """ + @spec viewer(String.t()) :: :ok + defdelegate viewer(cmd_string), to: Viewer, as: :view + @doc """ Starts the Ring Logger Viewer TUI app on the current prompt """ @spec viewer() :: :ok - def viewer(), do: RingLogger.Viewer.view() + defdelegate viewer(), to: Viewer, as: :view @doc """ Reset the index into the log for `next/1` to the oldest entry. diff --git a/lib/ring_logger/viewer.ex b/lib/ring_logger/viewer.ex index 8cf3225..8683afa 100644 --- a/lib/ring_logger/viewer.ex +++ b/lib/ring_logger/viewer.ex @@ -42,7 +42,6 @@ defmodule RingLogger.Viewer do @level_strings ["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"] @microsecond_factor 1_000_000 - @seconds_in_year 365 * 24 * 60 * 60 @seconds_in_month 30 * 24 * 60 * 60 @seconds_in_week 7 * 24 * 60 * 60 @@ -50,8 +49,8 @@ defmodule RingLogger.Viewer do @seconds_in_hour 60 * 60 @seconds_in_minute 60 - @spec view() :: :ok - def view() do + @spec view(String.t()) :: :ok + def view(cmd_string \\ "") do screen_dims = get_screen_dims() if screen_dims.w <= @min_width do @@ -62,9 +61,7 @@ defmodule RingLogger.Viewer do raise "Sorry, your terminal needs to be at least #{@min_height} rows high to use this tool!" end - IO.puts("Starting RingLogger Viewer...") - - @init_state |> get_log_snapshot() |> loop() + parse_launch_cmd(cmd_string, @init_state) |> get_log_snapshot() |> loop() end @doc """ @@ -88,6 +85,11 @@ defmodule RingLogger.Viewer do # apply_command_parser/3 returns state by applying single filter defp apply_command_parser(cmd_char, cmd, state) do case {cmd_char, cmd, state} do + {"l", cmd, state} -> set_log_level(cmd, state) + {"a", cmd, state} -> add_remove_app(cmd, state) + {"r", _cmd, _state} -> %{@init_state | current_page: 0} + {"g", cmd, state} -> add_remove_grep(cmd, state) + {"q", _cmd, state} -> %{state | running: false} {"d", cmd, state} -> add_time_log(cmd, state) _ -> state end