terminals
v0.1.3
Published
A small interactive terminal prompt helper for Node.js
Maintainers
Readme
Terminals
A small interactive terminal prompt helper for Node.js.
Installation
npm install terminalsUsage
import terminals from 'terminals';
const terminal = terminals.app();
// Ask a question and get answer
const name = await terminal.prompt('What is your name? ');
console.log(`Hello, ${name}!`);
// Start the interactive terminal session
terminal.start('> ', 'exit', async (input) => {
console.log(`You entered: ${input}`);
});
// Stop when needed
terminal.stop();API
terminal.app()
Creates a new terminal instance. Returns the terminal object for chaining.
terminal.start(message, exitCommand, work)
Starts the interactive terminal session with:
message- The prompt message to displayexitCommand- The command that will exit the terminalwork- An async function that processes each input
terminal.prompt(question)
Asks a question and returns the user's answer as a Promise.
question- The prompt message to display
terminal.stop()
Stops the terminal prompt loop and closes the readline interface.
terminals.argv()
Returns the command line arguments passed to the script (excluding node and script path).
Example
See test.js for a complete working example.
License
MIT
