Map Key to Control

This commit is contained in:
Alexander Heldt
2025-11-15 17:47:59 +01:00
parent 702313eac2
commit c42bf67d73
3 changed files with 51 additions and 21 deletions

27
src/mpv/control.gleam Normal file
View File

@@ -0,0 +1,27 @@
import mpv/key.{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 {
key.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")
}