Improve progress bar
This improves progress bar by: - Adding progress percentage - Calculating progress bar underline based on the text length of progress bar
This commit is contained in:
@@ -56,11 +56,13 @@ defmodule Display do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp format(failure, module, name) do
|
defp format(failure, module, name) do
|
||||||
|
progress_bar = ProgressBar.progress_bar(Tracker.summarize())
|
||||||
|
progress_bar_underline = String.duplicate("-", String.length(progress_bar))
|
||||||
"""
|
"""
|
||||||
#{Intro.intro(module, Tracker.visited())}
|
#{Intro.intro(module, Tracker.visited())}
|
||||||
Now meditate upon #{format_module(module)}
|
Now meditate upon #{format_module(module)}
|
||||||
#{ProgressBar.progress_bar(Tracker.summarize())}
|
#{progress_bar}
|
||||||
----------------------------------------
|
#{progress_bar_underline}
|
||||||
#{name}
|
#{name}
|
||||||
#{Failure.format_failure(failure)}
|
#{Failure.format_failure(failure)}
|
||||||
"""
|
"""
|
||||||
|
@@ -4,14 +4,19 @@ defmodule Display.ProgressBar do
|
|||||||
|
|
||||||
def progress_bar(%{current: current, total: total}) do
|
def progress_bar(%{current: current, total: total}) do
|
||||||
arrow = calculate_progress(current, total) |> build_arrow
|
arrow = calculate_progress(current, total) |> build_arrow
|
||||||
|
progress_percentage = calculate_percentage(current, total)
|
||||||
|
|
||||||
"|" <> String.pad_trailing(arrow, @progress_bar_length) <> "| #{current} of #{total}"
|
"|" <> String.pad_trailing(arrow, @progress_bar_length) <> "| #{current} of #{total} -> #{progress_percentage}% complete"
|
||||||
end
|
end
|
||||||
|
|
||||||
defp calculate_progress(current, total) do
|
defp calculate_progress(current, total) do
|
||||||
round(current / total * @progress_bar_length)
|
round(current / total * @progress_bar_length)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp calculate_percentage(current, total) do
|
||||||
|
Float.round(current / total * 100, 1)
|
||||||
|
end
|
||||||
|
|
||||||
defp build_arrow(0), do: ""
|
defp build_arrow(0), do: ""
|
||||||
|
|
||||||
defp build_arrow(length) do
|
defp build_arrow(length) do
|
||||||
|
Reference in New Issue
Block a user