Is there a way to have a command prompt (just a question
prompt, or something similar) fixed to the bottom of the Terminal, and to log output above it, using Node.js.
A really bad example:
Your favourite food is sushi.
Your favourite food is chicken.
Your favourite food is okra.
--> What is your favourite food?
So essentially, I'm looking to have the user always able to type, and have input echoed above the prompt.
interface.question("What is your favourite food?", function(answer) {
// output the answer above where this prompt was
// and somehow keep this same prompt where is is
});
The particular application I'm hoping to use this in is a simple IRC client, where I have a spot for the user to type, and have all the output (what the user has typed, and what others have also typed) outputted above where the user is typing. The lines in the diagram below are imaginary.
----------------------------------------------------------------------
| |
| |
| |
| |
| |
| |
| |
| Stuff |
| Stuff |
| Stuff |
----------------------------------------------------------------------
| --> The user can type here |
----------------------------------------------------------------------
It is a computer environment the same as command prompt and an easy way to test simple Node. js/JavaScript code and allows to execute multiple javascript codes. we can simply run REPL on the command prompt using node command on the command prompt.
Node. js files must be initiated in the "Command Line Interface" program of your computer. How to open the command line interface on your computer depends on the operating system. For Windows users, press the start button and look for "Command Prompt", or simply write "cmd" in the search field.
In Node. js, you usually bind functions (using 'on' or other functions) to listen to events.
process.stdout.write("\x1Bc")
console.log(Array(process.stdout.rows + 1).join('\n'));
const myRL = require("serverline")
myRL.init()
myRL.getRL().question("What is your favourite food? ", function(answer) {
console.log(`Your favourite food is ${answer}.`)
});
function main() {
let i = 0
setInterval(function() {
const num = () => Math.floor(Math.random() * 255) + 1
i++
console.log(i + " " + num() + "." + num() + "." + num() + " user connected.")
}, 700)
}
main()
Old version :
https://stackoverflow.com/posts/24519813/revisions
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