Extract reading of input i/o to input

And add the ability of other modules to listen to either
the final result (a `Key`) or tap into the input as it is read
This commit is contained in:
Alexander Heldt
2025-11-20 17:00:36 +01:00
parent b69852f7ba
commit 249b0671e4
7 changed files with 98 additions and 46 deletions

View File

@@ -1,8 +1,22 @@
import gleam/erlang/process
import gleam/erlang/process.{type Name}
import input/input.{type Listener}
import input/key.{type Key}
import mpv/mpv
pub fn main() -> Nil {
let exit = process.new_subject()
let assert Ok(_) = mpv.new(exit)
// `inject_input` is created by name to allow the `input` process that
// owns `read_input` to be able to register and receive from it,
// while the any other processes can use the name reference to
// inject input
let inject_input_name: Name(Key) = process.new_name("inject_input")
let assert Ok(mpv_listener) = mpv.new(exit)
let listeners: List(Listener) = [mpv_listener]
input.new(listeners, inject_input_name)
process.receive_forever(exit)
}