Current section
Files
Jump to
Current section
Files
lib/chr/print.ex
defmodule Chr.Print do
@moduledoc """
Print module
"""
defp print_count_number(counts, title, color, min_height \\ 5) do
counts
|> Owl.Box.new(
title: title,
padding_x: 2,
padding_y: 1,
border_tag: color,
min_height: min_height
)
end
defp print_count_bar(percents, title, color, min_height \\ 5) do
percents
|> Owl.Box.new(
title: title,
padding_x: 2,
padding_y: 1,
border_tag: color,
min_height: min_height
)
end
defp count_stringify(span, first, second) do
first
|> String.pad_leading(span, " ")
"#{first} #{second} "
end
defp percent_stringify(title, count) when is_atom(title) do
label =
title
|> Atom.to_string()
|> String.slice(0, 3)
|> String.capitalize()
value = String.duplicate("β", count)
"#{label} #{value}"
end
defp percent_stringify(title, count) do
label = title
value = String.duplicate("β", count)
"#{label} #{value}"
end
@doc """
print top commands
"""
def print_top_commands(histories) do
histories
|> Chr.top_commands()
|> Enum.map(fn {command, count} ->
count_stringify(5, count |> Integer.to_string(), command)
end)
|> Enum.join("\n")
# FIXME: Owl's bug: right border malposition when title has emoji
|> print_count_number("π Top Commands", :red)
end
@doc """
print top directories
"""
def print_top_directories(histories) do
histories
|> Chr.top_directories()
|> Enum.map(fn {directory, count} ->
count_stringify(5, count |> Integer.to_string(), directory)
end)
|> Enum.join("\n")
|> print_count_number("π Top Directories", :red, 5)
end
defp busiest_day_stringify({day, count}) do
"#{count} commands on #{day}"
end
@doc """
print busiest day
"""
def print_busiest_day(histories) do
histories
|> Chr.busiest_day()
|> busiest_day_stringify()
|> print_count_number("π¦ Busiest Day", :green)
end
@doc """
print weekly activity
"""
def print_weekly_activity(histories) do
histories
|> Chr.weekly_activity()
|> Enum.map(fn {day, count} ->
percent_stringify(day, count)
end)
|> Enum.join("\n")
|> print_count_bar("π
Weekly Activity", :yellow)
end
@doc """
print daily activity
"""
def print_daily_activity(histories) do
histories
|> Chr.daily_activity()
|> Enum.map(fn {hour, count} ->
percent_stringify(hour, count)
end)
|> Enum.join("\n")
|> print_count_bar("π Daily Activity", :magenta)
end
@doc """
print copy right
"""
def print_copy_right() do
"""
ββββββββββ ββββββββββ
βββββββββββ βββββββββββ
βββ ββββββββββββββββ
βββ ββββββββββββββββ 2024
βββββββββββ ββββββ βββ Commands History Report
ββββββββββ ββββββ βββ
generated by chr, made with β€οΈ by @ThaddeusJiang
"""
|> Owl.Box.new(padding_x: 1, padding_y: 1, border_tag: :cyan)
end
end