I would like to build a CLI application using Deno however I can't find a module that allows me to keep prompting the user for interaction similar to command line applications to the REPL module on Node.js
Any suggestions?
You can use std/io
to build a REPL.
import { readLines } from "https://deno.land/[email protected]/io/bufio.ts";
async function read() {
// Listen to stdin input, once a new line is entered return
for await(const line of readLines(Deno.stdin)) {
console.log('Received', line)
return line;
}
}
console.log('Start typing');
while(true) {
await read()
}
You can build from here, process each line, add commands and so on.
If you just want one line,you can do this
import { readLines } from "https://raw.githubusercontent.com/denoland/deno/master/std/io/bufio.ts";
const word = (await readLines(Deno.stdin).next()).value.trim()
console.log(`You typed: ${word}`)
D:\WorkSpace\VSCode\deno-play>deno run -A main.ts
hello
You typed: hello
Current denoland lib Commits on Jun 19, 2020
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With