From 0920d108012c4bdf84558be6a0273bbd80d08638 Mon Sep 17 00:00:00 2001 From: Iftakhar Husan Date: Fri, 1 Mar 2024 00:43:22 +0200 Subject: [PATCH] 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 0ad8986..b3ae1c2 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