28 lines
554 B
Gleam
28 lines
554 B
Gleam
import mpv/internal.{type Key}
|
|
import tcp/reason.{type Reason}
|
|
import tcp/tcp.{type Socket}
|
|
|
|
pub type Control {
|
|
TogglePlayPause
|
|
Exit
|
|
}
|
|
|
|
pub fn from_key(key: Key) -> Result(Control, Nil) {
|
|
case key {
|
|
internal.Char(char) -> char_control(char)
|
|
_ -> Error(Nil)
|
|
}
|
|
}
|
|
|
|
fn char_control(char: String) -> Result(Control, Nil) {
|
|
case char {
|
|
" " -> Ok(TogglePlayPause)
|
|
"q" -> Ok(Exit)
|
|
_ -> Error(Nil)
|
|
}
|
|
}
|
|
|
|
pub fn toggle_play_pause(socket: Socket) -> Result(Nil, Reason) {
|
|
tcp.send(socket, "{\"command\":[\"cycle\",\"pause\"]}\n")
|
|
}
|