diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2023-01-13 17:02:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 17:02:31 -0700 |
commit | b1b62f154ab5f74a9217dbf5a6422640ac929df3 (patch) | |
tree | 6fa3b6e8d7e9219decda28948bf3f02c3cf2dab2 /lib/chessh/utils.ex | |
parent | fdc22875284b78f9fb98993cbe44ce893c0de413 (diff) | |
parent | 3a6c603b0b12964d8a04ae4f78fb61bc094adf12 (diff) | |
download | chessh-b1b62f154ab5f74a9217dbf5a6422640ac929df3.tar.gz chessh-b1b62f154ab5f74a9217dbf5a6422640ac929df3.zip |
Merge pull request #3 from Simponic/draw_board
Draw board
Diffstat (limited to 'lib/chessh/utils.ex')
-rw-r--r-- | lib/chessh/utils.ex | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/chessh/utils.ex b/lib/chessh/utils.ex index 3e83d5e..20a8b96 100644 --- a/lib/chessh/utils.ex +++ b/lib/chessh/utils.ex @@ -1,4 +1,23 @@ defmodule Chessh.Utils do + @ascii_chars Application.compile_env!(:chessh, :ascii_chars_json_file) + |> File.read!() + |> Jason.decode!() + + @clear_codes [ + IO.ANSI.clear(), + IO.ANSI.home() + ] + + def ascii_chars(), do: @ascii_chars + def clear_codes(), do: @clear_codes + + def center_rect({rect_width, rect_height}, {parent_width, parent_height}) do + { + div(parent_height - rect_height, 2), + div(parent_width - rect_width, 2) + } + end + def pid_to_str(pid) do pid |> :erlang.pid_to_list() @@ -11,4 +30,9 @@ defmodule Chessh.Utils do split = String.split(text, "\n") {Enum.reduce(split, 0, fn x, acc -> max(acc, String.length(x)) end), length(split)} end + + def wrap_around(index, delta, length) do + calc = index + delta + if(calc < 0, do: length, else: 0) + rem(calc, length) + end end |