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?
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
© 2022 - 2024 — McMap. All rights reserved.