An open API service indexing awesome lists of open source software.

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.

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`.