Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ring_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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() ::
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 8 additions & 6 deletions lib/ring_logger/viewer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ 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
@seconds_in_day 24 * 60 * 60
@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
Expand All @@ -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 """
Expand All @@ -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
Expand Down