From 0920d108012c4bdf84558be6a0273bbd80d08638 Mon Sep 17 00:00:00 2001 From: Iftakhar Husan Date: Fri, 1 Mar 2024 00:43:22 +0200 Subject: [PATCH 1/4] Fix in consistent printing of meditation This fixes the issues I observed while solving the koans. Some of the issues I noticed are: - Random vertical position of printing koans - Sometimes koan intro printed before clear screen - Next koan does not appear when all koan passes for a module --- lib/display.ex | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/display.ex b/lib/display.ex index 0ad89863..b3ae1c2e 100644 --- a/lib/display.ex +++ b/lib/display.ex @@ -21,15 +21,14 @@ defmodule Display do {:noreply, %{state | clear_screen: false}} end - def handle_cast(:clear_screen, %{clear_screen: true} = state) do - IO.puts(ANSI.clear()) - IO.puts(ANSI.home()) + def handle_call(:clear_screen, _from, %{clear_screen: true} = state) do + ANSI.clear <> ANSI.home |> IO.puts() - {:noreply, state} + {:reply, :ok, state} end - def handle_cast(:clear_screen, state) do - {:noreply, state} + def handle_call(:clear_screen, _from, state) do + {:reply, :ok, state} end def invalid_koan(koan, modules) do @@ -53,7 +52,7 @@ defmodule Display do end def clear_screen do - GenServer.cast(__MODULE__, :clear_screen) + GenServer.call(__MODULE__, :clear_screen) end defp format(failure, module, name) do From 70c76693a6126f457fa82155dd23def4a15480f2 Mon Sep 17 00:00:00 2001 From: Iftakhar Husan Date: Fri, 1 Mar 2024 01:01:14 +0200 Subject: [PATCH 2/4] Improve progress bar This improves progress bar by: - Adding progress percentage - Calculating progress bar underline based on the text length of progress bar --- lib/display.ex | 6 ++++-- lib/display/progress_bar.ex | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/display.ex b/lib/display.ex index b3ae1c2e..1f57c16f 100644 --- a/lib/display.ex +++ b/lib/display.ex @@ -56,11 +56,13 @@ defmodule Display do end 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())} Now meditate upon #{format_module(module)} - #{ProgressBar.progress_bar(Tracker.summarize())} - ---------------------------------------- + #{progress_bar} + #{progress_bar_underline} #{name} #{Failure.format_failure(failure)} """ diff --git a/lib/display/progress_bar.ex b/lib/display/progress_bar.ex index 1c029ba4..71c1cdc0 100644 --- a/lib/display/progress_bar.ex +++ b/lib/display/progress_bar.ex @@ -4,14 +4,19 @@ defmodule Display.ProgressBar do def progress_bar(%{current: current, total: total}) do 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 defp calculate_progress(current, total) do round(current / total * @progress_bar_length) end + defp calculate_percentage(current, total) do + Float.round(current / total * 100, 1) + end + defp build_arrow(0), do: "" defp build_arrow(length) do From 2353ad0d0f54cb7382932b7d519571b16c9d6112 Mon Sep 17 00:00:00 2001 From: Iftakhar Husan Date: Fri, 1 Mar 2024 01:06:30 +0200 Subject: [PATCH 3/4] Fix failing tests for progress_bar changes --- test/display/progress_bar_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/display/progress_bar_test.exs b/test/display/progress_bar_test.exs index e080ae1a..f32229d8 100644 --- a/test/display/progress_bar_test.exs +++ b/test/display/progress_bar_test.exs @@ -5,16 +5,16 @@ defmodule ProgressBarTest do test "empty bar" do bar = ProgressBar.progress_bar(%{total: 12, current: 0}) - assert bar == "| | 0 of 12" + assert bar == "| | 0 of 12 -> 0.0% complete" end test "puts counter on the right until half the koans are complete" do bar = ProgressBar.progress_bar(%{total: 12, current: 3}) - assert bar == "|=======> | 3 of 12" + assert bar == "|=======> | 3 of 12 -> 25.0% complete" end test "full bar" do bar = ProgressBar.progress_bar(%{total: 12, current: 12}) - assert bar == "|=============================>| 12 of 12" + assert bar == "|=============================>| 12 of 12 -> 100.0% complete" end end From be4b4fd5a07d4b4db262716ce72d582b8ddcf5f1 Mon Sep 17 00:00:00 2001 From: Iftakhar Husan <37600593+Iftakharpy@users.noreply.github.com> Date: Fri, 1 Mar 2024 01:26:28 +0200 Subject: [PATCH 4/4] Add capability to run workflow manually --- .github/workflows/elixir.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index d8bc4d02..08ca75da 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -1,6 +1,7 @@ name: Elixir CI on: + workflow_dispatch: push: branches: [ master ] pull_request: