~ihabunek/aoc2022

74c295425b7714957de77bc10dc47581443c121c — Ivan Habunek 1 year, 9 months ago 5287220
Add dependency on curses and gleam_erlang
4 files changed, 53 insertions(+), 0 deletions(-)

M gleam.toml
M manifest.toml
A src/aoc2022/ncurses.gleam
M src/aoc2022/utils.gleam
M gleam.toml => gleam.toml +2 -0
@@ 3,6 3,8 @@ version = "0.1.0"

[dependencies]
gleam_stdlib = "~> 0.25"
gleam_erlang = "~> 0.17"
ex_ncurses = "~> 0.3"

[dev-dependencies]
gleeunit = "~> 0.7"

M manifest.toml => manifest.toml +6 -0
@@ 2,10 2,16 @@
# You typically do not need to edit this file

packages = [
  { name = "castore", version = "0.1.20", build_tools = ["mix"], requirements = [], otp_app = "castore", source = "hex", outer_checksum = "A020B7650529C986C454A4035B6B13A328E288466986307BEA3AADB4C95AC98A" },
  { name = "elixir_make", version = "0.7.2", build_tools = ["mix"], requirements = ["castore"], otp_app = "elixir_make", source = "hex", outer_checksum = "05FB44ABF9582381C2EB1B73D485A55288C581071DE0EE3EE1084EE69D6A8E5F" },
  { name = "ex_ncurses", version = "0.3.1", build_tools = ["mix", "make"], requirements = ["elixir_make"], otp_app = "ex_ncurses", source = "hex", outer_checksum = "BECDFB047B1A24AFF1CE60C55C805BE52BBFAAD8FCFA7DB5D4DF4BC0B09F1194" },
  { name = "gleam_erlang", version = "0.17.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "BAAA84F5BCC4477E809BA3E03BB3009A3894A6544C1511626C44408E39DB2AE6" },
  { name = "gleam_stdlib", version = "0.25.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "AD0F89928E0B919C8F8EDF640484633B28DBF88630A9E6AE504617A3E3E5B9A2" },
  { name = "gleeunit", version = "0.7.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "5F4FBED3E93CDEDB0570D30E9DECB7058C2D327996B78BB2D245C739C7136010" },
]

[requirements]
ex_ncurses = "~> 0.3"
gleam_erlang = "~> 0.17"
gleam_stdlib = "~> 0.25"
gleeunit = "~> 0.7"

A src/aoc2022/ncurses.gleam => src/aoc2022/ncurses.gleam +38 -0
@@ 0,0 1,38 @@
import gleam/erlang/atom.{Atom}

pub external fn n_begin() -> Nil =
  "Elixir.ExNcurses" "n_begin"

pub external fn n_end() -> Nil =
  "Elixir.ExNcurses" "n_end"

pub external fn printw(String) -> Nil =
  "Elixir.ExNcurses" "printw"

pub external fn mvprintw(Int, Int, String) -> Nil =
  "Elixir.ExNcurses" "mvprintw"

pub external fn curs_set(Int) -> Nil =
  "Elixir.ExNcurses" "curs_set"

pub external fn refresh() -> Nil =
  "Elixir.ExNcurses" "refresh"

pub external fn move(Int, Int) -> Nil =
  "Elixir.ExNcurses" "move"

pub external fn start_color() -> Nil =
  "Elixir.ExNcurses" "start_color"

pub external fn attron(Int) -> Nil =
  "Elixir.ExNcurses" "attron"

pub external fn attroff(Int) -> Nil =
  "Elixir.ExNcurses" "attroff"

external fn init_pair_(Int, Atom, Atom) -> Nil =
  "Elixir.ExNcurses" "init_pair"

pub fn init_pair(code, fg, bg) {
  init_pair_(code, atom.create_from_string(fg), atom.create_from_string(bg))
}

M src/aoc2022/utils.gleam => src/aoc2022/utils.gleam +7 -0
@@ 19,6 19,9 @@ pub external fn binary_to_list(String) -> Charlist =
pub external fn list_to_binary(Charlist) -> String =
  "erlang" "list_to_binary"

pub external fn sleep(Int) -> Nil =
  "timer" "sleep"

// Utils

pub fn read_input(filename: String) -> String {


@@ 46,6 49,10 @@ pub fn ord(str: String) -> Int {
  char
}

pub fn chr(code: Int) -> String {
  list_to_binary([code])
}

/// Like list.at but returns an error if index is smaller than 0
pub fn list_at(list: List(a), at: Int) -> Result(a, Nil) {
  case at >= 0 {