Current section

Files

Jump to
islands_text_client lib islands text_client prompter.ex
Raw

lib/islands/text_client/prompter.ex

defmodule Islands.TextClient.Prompter do
@moduledoc """
Prompts a _Game of Islands_ player.
"""
alias IO.ANSI.Plus, as: ANSI
alias Islands.TextClient.{Input, State, Summary}
@spec accept_move(State.t(), ANSI.ansilist()) :: State.t() | no_return
def accept_move(state, message \\ [])
def accept_move(state, []), do: do_accept_move(state)
def accept_move(state, message),
do: state |> Summary.display(message) |> do_accept_move()
# Private functions
@spec do_accept_move(State.t()) :: State.t() | no_return
defp do_accept_move(%State{player_name: player_name} = state) do
[:light_white, "#{player_name}, your move (or help):", :reset, " "]
|> ANSI.format()
|> IO.gets()
|> Input.check(state)
end
end