Extract mpv/key to input
To separate the concern from `mpv`
This commit is contained in:
@@ -2,8 +2,8 @@ import gleam/json
|
||||
import gleam/result
|
||||
import gleam/string
|
||||
|
||||
import input/key.{type Key, Char}
|
||||
import mpv/internal/control as internal_control
|
||||
import mpv/key.{type Key, Char}
|
||||
import tcp/reason.{type Reason}
|
||||
import tcp/tcp.{type Socket}
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import gleam/erlang/atom
|
||||
|
||||
pub fn read_input() -> String {
|
||||
io_get_chars("", 1)
|
||||
}
|
||||
|
||||
pub type NotUsed
|
||||
|
||||
// https://www.erlang.org/doc/apps/stdlib/shell.html#start_interactive/1
|
||||
@external(erlang, "shell", "start_interactive")
|
||||
pub fn shell_start_interactive(options: #(atom.Atom, atom.Atom)) -> NotUsed
|
||||
|
||||
// https://www.erlang.org/doc/apps/stdlib/io.html#get_line/1
|
||||
@external(erlang, "io", "get_chars")
|
||||
fn io_get_chars(prompt: String, count: Int) -> String
|
||||
@@ -1,53 +0,0 @@
|
||||
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))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import gleam/otp/actor
|
||||
import gleam/result
|
||||
import gleam/string
|
||||
|
||||
import input/key
|
||||
import mpv/control.{type Control}
|
||||
import mpv/key
|
||||
import tcp/reason
|
||||
import tcp/tcp.{type Socket}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user