Skip to content

Instantly share code, notes, and snippets.

@mihai-vlc
Created February 17, 2023 10:17
Show Gist options
  • Save mihai-vlc/d8c7fe38aa1b24910899fd873517182b to your computer and use it in GitHub Desktop.
Save mihai-vlc/d8c7fe38aa1b24910899fd873517182b to your computer and use it in GitHub Desktop.
import { wordWrap } from "./word";
import readline from "readline";
const rl = readline.createInterface(process.stdin, process.stdout);
let i = 0;
rl.setPrompt(`Text(${i}) = `);
rl.prompt();
rl.on("line", (line) => {
console.log(wordWrap(3, line));
i++;
rl.setPrompt(`Text(${i}) = `);
rl.prompt();
});
let closing = false;
rl.on("SIGINT", () => {
if (closing) {
rl.close();
return;
}
closing = true;
rl.question("Are you sure you want to exit (yes/no) ? ", (answer) => {
if (answer.match(/^y(es)?$/i)) {
rl.close();
return;
}
closing = false;
rl.prompt();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment