Map Key to Control
This commit is contained in:
27
src/mpv/control.gleam
Normal file
27
src/mpv/control.gleam
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user