summaryrefslogtreecommitdiff
path: root/lib/chessh/utils.ex
blob: d1acf44ed425290f96729468531c8fae71169ca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
defmodule Chessh.Utils do
  def pid_to_str(pid) do
    pid
    |> :erlang.pid_to_list()
    |> List.delete_at(0)
    |> List.delete_at(-1)
    |> to_string()
  end

  def text_dim(text) 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