Packages

A command line tool for generating a commands history report.

Current section

Files

Jump to
chr lib chr print.ex
Raw

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