question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add sync version of std/io readLines

See original GitHub issue

It would be useful to provide a function that can read a line of input from stdin that has a simple interface. It would probably good to support both async and sync versions, something like

const name: string = await Deno.readLine('What is your name? ');
const age: string = Deno.readLineSync('What is your age? ');

I think readLine might be too close to the file functions, so maybe something like getInput or ttyReadLine

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:31 (20 by maintainers)

github_iconTop GitHub Comments

15reactions
bartlomiejucommented, Feb 29, 2020

It’s now possible to do that using readLines from std/io/bufio.ts

import { readLines } from "https://deno.land/std@v0.35.0/io/bufio.ts";

async function main() {
   for await (const line of readLines(Deno.stdin)) {
      console.log("read line", line);
  }
}

console.log("reading lines from stdin");
main();
$ deno index.ts
Compile file:///Users/biwanczuk/dev/deno/index.ts
reading lines from stdin
asdf
read line asdf
qwer
read line qwer
tryu
read line tryu
6reactions
kevinkassimocommented, Feb 18, 2019

I believe this could be implemented in pure TS with Deno.stdin, so we should probably put this in deno_std

Read more comments on GitHub >

github_iconTop Results From Across the Web

readline-sync - npm
Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).. Latest version: 1.4.10, ...
Read more >
4.8. Input with readline-sync - LaunchCode Education
Try adding another + name term inside the console.log statement and see what happens. Next, add code to prompt the user for a...
Read more >
How to get synchronous readline, or "simulate" it using async ...
My condition is to allow reading (single) lines using the getline type function using the readline interface in a clean "synchronous" way or...
Read more >
readLineSync method - Stdin class - Flutter - Dart API docs
API docs for the readLineSync method from the Stdin class, for the Dart programming language.
Read more >
How to use the readline-sync.question function in ... - Snyk
readFileSync (infoPath)) || {}; } else { console.log('Creating ' + infoPath + ' -- please add it to .gitignore if applicable'); } if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found