Restructure mpv/internal package

This commit is contained in:
Alexander Heldt
2025-11-16 16:04:06 +01:00
parent ebdba09bc2
commit 702313eac2
5 changed files with 51 additions and 48 deletions

54
src/mpv/key.gleam Normal file
View File

@@ -0,0 +1,54 @@
import gleam/erlang/atom
import gleam/list
import mpv/internal/key as internal_key
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_key.shell_start_interactive(#(no_shell, raw))
}
// TODO map key to something like Control, to not leak `Continue` etc.
pub fn read_input_until_key(l: List(String)) -> Key {
let l = internal_key.read_input() |> list.wrap |> list.append(l, _)
case from_list(l) {
Continue -> read_input_until_key(l)
k -> k
}
}