@topcli/stdin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Stdin

version Maintenance Security Responsible Disclosure mit build

Node.js light and interactive standard input (stdin) crafted for REPL (like) experience (with auto-completion and history). Under the hood it use process.stdin and TTY Stream with the raw mode enabled to catch key by key.

Demo with the SlimIO CLI

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @topcli/stdin
# or
$ yarn add @topcli/stdin

Usage example

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}`);

👀 the reference to the history array is keeped. So if you want to achieve a while of input, think to declare a top array history that will be used by all inputs.

API

stdin(query: null | string, options?: StdinOptions): Promise< string >

Query paramaters can be set to null to disable the title. Options is described by the following TypeScript interface:

interface StdinOptions {
    history?: string[];
    autocomplete?: string[];
}

history and autocomplete are optional. There is no thing as a cache or limitation for history (you have to implement that kind of stuff yourself with cacache).

Contributors

All Contributors

Thanks goes to these wonderful people (emoji key):


Gentilhomme

💻 📖 👀 🛡️ 🐛

Alexandre Malaj

💻 📖

License

MIT

Package Sidebar

Install

npm i @topcli/stdin

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

13.9 kB

Total Files

6

Last publish

Collaborators

  • pierred
  • fraxken