Upgrade Stdin from byte to bytes add support for terminal raw mode#54
Upgrade Stdin from byte to bytes add support for terminal raw mode#54rtfeldman merged 5 commits intoroc-lang:mainfrom
byte to bytes add support for terminal raw mode#54Conversation
@rtfeldman I've conducted a number of experiments and from what I can tell nothing bad. I added the crossterm-rs library which I had used previously for the |
src/Stdin.roc
Outdated
| @@ -17,8 +20,8 @@ line = | |||
| ## Read a single byte from [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). | |||
There was a problem hiding this comment.
I guess the docs for this should be changed? 😄
Also, do we want only one of these two functions, or both?
In other words, is there any situation where I'd want to read a single byte instead of as much as I can from the buffer?
There was a problem hiding this comment.
I thought a single byte would be useful, but after playing with stdin and decoding ANSI string escapes more I discovered that a single byte at a time is really unhelpful and difficult to use.
For example the below is how you might decode the Left key and Escape key. Without using multiple bytes from a Task you cannot process the input until you have looked ahead at the next byte, which may not be available (e.g. if there was only one read from stdin).
- [27, 91, 68, ..] -> Key Left
- [27, ..] -> Key Escape
Also, you can always read a list of bytes using this Task, and then chomp them one by one if that is required or easier for an algorithm such, i.e. recursively processing bytes.
Therefore I cannot think of a situation where we need a Task to read a single byte.
rtfeldman
left a comment
There was a problem hiding this comment.
Sweet, thanks @lukewilliamboswell! 🎉

This PR;
Stdin.bytetoStdin.bytesto read in up to 256 bytes from the input buffer as this is a much more useful function than processing a single byte at a time.