-
Notifications
You must be signed in to change notification settings - Fork 66
Key input handler #1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Key input handler #1214
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e5ce626
add primitive `key` type
byorgey fe4e861
add primitive `key` command
byorgey 47118d0
add `Key` values with parsing+pretty-printing
byorgey d111812
add placeholder `installKeyHandler` command
byorgey dbc859c
piloting -> input handler
byorgey fce993b
add replInputHandler to REPL state
byorgey df64259
add `inputHandler` field to game state
byorgey 36cf92e
add back piloting mode
byorgey 7ac2f24
WIP: deal with keypresses in input handler mode
byorgey 0926a81
WIP: get basic key handler working
byorgey 5c38cf4
change REPL prompt when key handler is running
byorgey 951497e
add todo, and fix import
byorgey 6c5df04
add `handle` device
byorgey a5e77d3
use hint line for handler, clean up comments
byorgey f1d4672
add list of special key names under `swarm generate keys`
byorgey b6ce2f9
add some key handler examples
byorgey 44b35ca
Merge branch 'main' into feature/input-handler
byorgey 4406960
remove completed todo
byorgey 1c771b9
remove accidentally added file and remove completed todo
byorgey eba6e87
add `key` and `installKeyHandler` to editor configs
byorgey 62bb1f4
Merge branch 'main' into feature/input-handler
byorgey ed69f15
fix `hlint` warning
byorgey 6013760
remove redundant parentheses
byorgey aaf94aa
add a few explanatory comments
byorgey 129b849
fix comment
byorgey 9a4942c
group input handler + hint text
byorgey 7fb3416
Merge branch 'main' into feature/input-handler
byorgey 2df977e
add installed `handle` device to `bridge-building` challenge
byorgey 6cb11bb
Merge branch 'main' into feature/input-handler
byorgey b3ebc94
remove duplicate `handle` entity, and add `key` + `keyboard` devices
byorgey f0fc631
WIP: add logging to pilot mode example
byorgey c595701
update hint string in pilot mode example
byorgey bf692e7
Merge branch 'main' into feature/input-handler
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Proof of concept illustrating the possibility of key | ||
| // handlers that process multi-key sequences. | ||
|
|
||
| def cons : a * b -> (a -> b) -> (a -> b) = \p. \k. \a. | ||
| if (a == fst p) {snd p} {k a} | ||
| end | ||
|
|
||
| def nil : a -> cmd unit = \a. return () end | ||
|
|
||
| // The delay around the first argument is necessary to prevent | ||
| // infinite recursion | ||
| def handlerB : {key -> cmd unit} -> key -> cmd unit = \hA. \k. | ||
| cons (key "b", move) nil k; | ||
| installKeyHandler "" (force hA) | ||
| end | ||
|
|
||
| // Typing 'a' then 'b' in sequence will cause the robot to move. | ||
| def handlerA : key -> cmd unit = | ||
| cons (key "a", installKeyHandler "" (handlerB {handlerA})) nil | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| def cons : a * b -> (a -> b) -> (a -> b) = \p. \k. \a. | ||
| if (a == fst p) {snd p} {k a} | ||
| end | ||
|
|
||
| def nil : a -> cmd unit = \a. return () end | ||
|
|
||
| // Suitable to use as e.g. | ||
| // installKeyHandler "(S-)←↓↑→ [Del] [g]rab [h]arvest [d]rill [s]can [b]locked [u]pload" pilot | ||
| def pilot : key -> cmd unit = | ||
| cons (key "Up", move) $ | ||
| cons (key "Down", turn back) $ | ||
| cons (key "Left", turn left) $ | ||
| cons (key "Right", turn right) $ | ||
| cons (key "S-Up", turn north) $ | ||
| cons (key "S-Down", turn south) $ | ||
| cons (key "S-Left", turn west) $ | ||
| cons (key "S-Right", turn east) $ | ||
| cons (key "Del", selfdestruct) $ | ||
| cons (key "g", res <- grab; log res) $ | ||
| cons (key "h", res <- harvest; log res) $ | ||
| cons (key "d", res <- drill forward; case res (\_. return ()) log) $ | ||
| cons (key "s", res <- scan forward; case res (\_. return ()) log) $ | ||
| cons (key "b", b <- blocked; if b {log "blocked"} {log "not blocked"}) $ | ||
| cons (key "u", upload base) $ | ||
| nil | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.