summaryrefslogtreecommitdiff
path: root/lib/chessh/utils.ex
diff options
context:
space:
mode:
authorLogan Hunt <logan.hunt@usu.edu>2023-01-13 12:20:01 -0700
committerLogan Hunt <logan.hunt@usu.edu>2023-01-13 12:21:04 -0700
commit07eaad9b8ded7a719183eec84faaf5b168744f01 (patch)
treea6a9ea14ba261e7c5a142613d800c19774965bc1 /lib/chessh/utils.ex
parenta93119b25033248decda7477575e214a1b254fbd (diff)
downloadchessh-07eaad9b8ded7a719183eec84faaf5b168744f01.tar.gz
chessh-07eaad9b8ded7a719183eec84faaf5b168744f01.zip
Move renderer to its own module
Diffstat (limited to 'lib/chessh/utils.ex')
-rw-r--r--lib/chessh/utils.ex19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/chessh/utils.ex b/lib/chessh/utils.ex
index d1acf44..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()