Restructure mpv/internal package
This commit is contained in:
54
src/mpv/key.gleam
Normal file
54
src/mpv/key.gleam
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user