import gleam/erlang/atom import gleam/list import input/internal as internal_input pub type Key { Char(String) Left Right Up Down Continue Unknown } pub const esc = "\u{001B}" // control sequence introducer pub const csi = "[" pub fn from_list(l: List(String)) -> Key { case l { [e, c, "D"] if e == esc && c == csi -> Left [e, c, "C"] if e == esc && c == csi -> Right [e, c, "A"] if e == esc && c == csi -> Up [e, c, "B"] if e == esc && c == csi -> Down [e, c] if e == esc && c == csi -> Continue [e] if e == esc -> Continue [char] -> Char(char) [] -> Continue _ -> Unknown } } pub fn start_raw_shell() { let no_shell = atom.create("noshell") let raw = atom.create("raw") internal_input.shell_start_interactive(#(no_shell, raw)) } pub fn read_input_until_key(l: List(String)) -> Key { let l = internal_input.read_input() |> list.wrap |> list.append(l, _) case from_list(l) { Continue -> read_input_until_key(l) k -> k } }