kdog3682
kdog36825mo ago

Is there a deno function for inputting prompt reply without pressing enter?

Normally, one has to press enter for the input to be accepted. I was wondering if there was a version of prompt or confirm that lets you press a key, and that will automatically register (without pressing enter)
5 Replies
Deno AI Helper
Deno AI Helper5mo ago
I wasn't able to find the answer to your question in the official Deno documentation. Deno's standard library provides a prompt function which requires the user to press enter after typing their input. This is the typical behavior for console input in many environments. However, based on your message, it seems like you're looking for a way to capture a single keypress without the need to press enter. This kind of functionality usually involves more low-level handling of the terminal or command line interface and might not be directly supported by Deno's standard library. Please note that the advice provided here is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you need this functionality, you might need to look into third-party libraries or modules that provide more advanced terminal handling capabilities, or you might need to write a custom solution that interfaces with the system's terminal directly.
NeTT
NeTT5mo ago
maybe you can check out deno.stdin?
Mqx
Mqx5mo ago
This would read one byte aka one letter at a time without pressing enter:
Deno.stdin.setRaw(true) // this is important
await Deno.stdin.readable.getReader().read().then(result => {
console.log(new TextDecoder().decode(result.value));
})
Deno.stdin.setRaw(true) // this is important
await Deno.stdin.readable.getReader().read().then(result => {
console.log(new TextDecoder().decode(result.value));
})
There are probably better ways to do this…
kdog3682
kdog36825mo ago
Thanks! It works.
Mqx
Mqx5mo ago
:deno_thumbs_up:
More Posts
Setting Deno.Command priority and affinity (on windows)Is it possible to set a tasks / commands priority and affinity directly? Code: ```ts await new DenoIs there a way to write a Deno.AtomicCheck that succeeds for any non-null versionstamp?You can write a Deno.AtomicCheck that fails if the versionstamp for a key-value pair in the KV storeImportTypeScript API + get value of `compilerOptions` with default options from `tsconfig.json`?Hello, I'm trying to figure out the proper way to do a few things: 1. What's the correct way to impHow to override the version from a dependency of a project's dependency from npmI'm currently using react-pdf as a dependency, react-pdf uses fontkit as a dependency, and fontkit uHow to publish global types with JSR?I was trying to republish my npm package with JSR via npm jsr package. It all went well with one excCaching results from APIHi, I'm currently working on a project where I get data from an API (https://www.robotevents.com/apiINTERNAL_SERVER_ERROR_2 / 500 response codeSeveral clients concurrently reported INTERNAL_SERVER_ERROR_2 with a 500 error on requests to a deplMy site seems to be under attackI receive a large amount of request last night. Does this mean my site is under attack...?Deno drizzle-kit migrate:pgI don't know if its drizzle error or Deno error... I saw path resolution problem, it is said `C:UseDoes V8 engine eventloop/threading model conflict with rust?hi, I am trying to embed deno's rusty_v8 into rust application. I am confused about the eventloop/th