https://github.com/hugojosefson/deno-stdin
Trying different ways of reading Deno.stdin.
https://github.com/hugojosefson/deno-stdin
deno input keypress stdin stdout
Last synced: 6 months ago
JSON representation
Trying different ways of reading Deno.stdin.
- Host: GitHub
- URL: https://github.com/hugojosefson/deno-stdin
- Owner: hugojosefson
- Created: 2021-12-24T13:16:30.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-25T18:22:30.000Z (over 2 years ago)
- Last Synced: 2025-01-31T17:48:20.831Z (8 months ago)
- Topics: deno, input, keypress, stdin, stdout
- Language: TypeScript
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deno stdin experiments
Trying different ways of reading
[Deno.stdin](https://deno.land/api?s=Deno.stdin). I hope to be able to switch in
and out of `Deno.stdin.setRaw()`, while waiting for input, without locking up or
encountering errors.That could be useful for making a
[port of ink for Deno](https://github.com/hugojosefson/ink) work correctly.## Conclusion
```sh
deno run --reload https://raw.githubusercontent.com/hugojosefson/deno-stdin/main/src/demo.ts --silent
```Source code in: [src/demo.ts](src/demo.ts)
Apparently, setting raw mode on `Deno.stdin`, and reading/writing is fine, as
long as you await the `Promise` returned from
[Deno.Writer.write](https://deno.land/api?s=Deno.Writer#write).Don't just write in the background haphazardly, and then try to
`Deno.stdin.setRaw()` while that's happening. Instead, in a loop where you await
each `Deno.Writer.write`, check a `let done: boolean` flag for whether to stop
writing and resetting the raw mode to `false`.