https://github.com/TopCli/stdin
Node.js light ⚡, interactive and elegant input crafted for REPL experience.
https://github.com/TopCli/stdin
cli input interactive repl stdin tty
Last synced: about 1 month ago
JSON representation
Node.js light ⚡, interactive and elegant input crafted for REPL experience.
- Host: GitHub
- URL: https://github.com/TopCli/stdin
- Owner: TopCli
- License: mit
- Created: 2019-09-08T19:13:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T01:11:42.000Z (over 1 year ago)
- Last Synced: 2024-11-07T00:47:28.283Z (8 months ago)
- Topics: cli, input, interactive, repl, stdin, tty
- Language: JavaScript
- Homepage:
- Size: 206 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-crafted-nodejs - @slimio/stdin - Node.js light, interactive and elegant input crafted for REPL experience. (Packages / CLI (TTY etc..))
README
# Stdin

[](https://github.com/TopCli/stdin/commit-activity)
[](https://github.com/TopCli/stdin/blob/master/LICENSE)
[](https://api.securityscorecards.dev/projects/github.com/TopCli/stdin)
A lightweight and interactive standard input (stdin) utility for Node.js, designed for REPL-like experiences with support for auto-completion and history.
Internally, it leverages `process.stdin` in raw mode to capture key-by-key input directly from the TTY stream.
Demo with the SlimIO CLI
![]()
## Requirements
- [Node.js](https://nodejs.org/en/) v22 or higher## Getting Started
This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
```bash
$ npm i @topcli/stdin
# or
$ yarn add @topcli/stdin
```## Usage example
```js
import stdin from "@topcli/stdin";const data = await stdin("Question title > ", {
history: ["command in history 1", "command in history 2"],
autocomplete: [
"events",
"events.get_info"
]
});
console.log(`input data: ${data}`);
```> [!TIP]
> The history array is passed by reference. If you plan to run multiple prompts in a loop, define a shared history array outside the loop to persist input history across calls.## API
### stdin(title: null | string, options?: StdinOptions): Promise< string >
Prompts the user for input with an optional title and options. If **title** is `null`, the prompt will be displayed without a prefix.
`StdinOptions` interface
```ts
interface StdinOptions {
/**
* An array of previous commands or inputs to enable navigation with arrow keys.
*/
history?: string[];
/**
* A list of strings used to suggest autocompletion while typing.
*/
autocomplete?: string[];
}
```> [!CAUTION]
> This module does not implement history persistence or caching. If you want to persist history across sessions, consider using a package like [cacache](https://github.com/npm/cacache#readme).## Contributors ✨
[](#contributors-)
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Gentilhomme
💻 📖 👀 🛡️ 🐛
Alexandre Malaj
💻 📖
PierreDemailly
💻 ⚠️
## License
MIT