Compare commits

4 Commits

Author SHA1 Message Date
Alexander Heldt
875eb9ced9 wip 2025-11-19 18:00:17 +01:00
Alexander Heldt
79c30060c3 Add ability to listen (tap) the input
By doing something like
```
fn input_output_loop(input_output: Subject(List(String))) -> Nil {
  let output = process.receive_forever(input_output)

  echo output

  input_output_loop(input_output)
}
```
2025-11-19 18:00:17 +01:00
Alexander Heldt
6681cc3c69 Add ability to inject characters into the input 2025-11-19 17:57:49 +01:00
Alexander Heldt
6518fd4b30 Add ability to create character sequences as Input 2025-11-19 17:48:51 +01:00
3 changed files with 12 additions and 2 deletions

View File

@@ -38,9 +38,7 @@ pub fn from_list(l: List(String)) -> Key {
[ci] | [ci, _] if ci == input_introducer -> Continue(l) [ci] | [ci, _] if ci == input_introducer -> Continue(l)
[ii, cmd, tail] if ii == input_introducer -> { [ii, cmd, tail] if ii == input_introducer -> {
case tail { case tail {
// Return
"\r" -> Input(cmd) "\r" -> Input(cmd)
// Backspace
"\u{007F}" -> Continue([ii, string.drop_end(cmd, 1)]) "\u{007F}" -> Continue([ii, string.drop_end(cmd, 1)])
_ -> Continue([ii, cmd <> tail]) _ -> Continue([ii, cmd <> tail])
} }

View File

@@ -10,6 +10,8 @@ import tcp/tcp.{type Socket}
pub type Control { pub type Control {
TogglePlayPause TogglePlayPause
Search
Exit Exit
} }
@@ -17,7 +19,12 @@ pub type ControlError {
ControlError(details: String) ControlError(details: String)
} }
// TODO this should also have a context:
// `/` in "artist list" "context will should be`control.Search`
// `<some char>` in "create new playlist" context should be `control.Input`
// `q` in most contexts should be `Exit`, but in a popup it should be `Close`
pub fn from_key(key: Key) -> Result(Control, Nil) { pub fn from_key(key: Key) -> Result(Control, Nil) {
echo key
case key { case key {
key.Char(char) -> char_control(char) key.Char(char) -> char_control(char)
_ -> Error(Nil) _ -> Error(Nil)
@@ -28,6 +35,7 @@ fn char_control(char: String) -> Result(Control, Nil) {
case char { case char {
" " -> Ok(TogglePlayPause) " " -> Ok(TogglePlayPause)
"q" -> Ok(Exit) "q" -> Ok(Exit)
"/" -> Ok(Search)
_ -> Error(Nil) _ -> Error(Nil)
} }
} }

View File

@@ -64,6 +64,10 @@ fn handle_message(
control: Control, control: Control,
) -> actor.Next(State(socket, inject, input_output, exit), Control) { ) -> actor.Next(State(socket, inject, input_output, exit), Control) {
case control { case control {
control.Search -> {
process.send(state.inject_input, key.Continue([key.input_introducer]))
actor.continue(state)
}
control.TogglePlayPause -> { control.TogglePlayPause -> {
echo "toggling play/pause" echo "toggling play/pause"