0.0.21 • Published 11 months ago

niclijs v0.0.21

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

▶️ NICLI - Node Interactive (Redis-like) CLIs builder

Install

npm install niclijs

Basic Usage

Just put the prompt function in an endless loop and react to the returned input. Use ctrl+c as exit sequence.

import { nicliPrompt } from "niclijs"

(async function () {

	while (true) {
		const { raw, exit } = await nicliPrompt("nicli >")

		if (exit) break

		console.log(">>>", raw)
	}

	process.exit(0)
})()

Returned Input

  • raw: (string) raw typed string
  • command: (string) first word of the input
  • args: (strings array) following words of the input
  • choiche: (Choice) choiche object if the input matches something
  • exit: (boolean) exit signal

Special Keys

  • Ctrl + c: return exit signal
  • Ctrl + a: move the cursor to the first position
  • Ctrl + e: move the cursor to the last position
  • Up/Down arrows: move through commands history
  • Tab: autocomplete (if a command is suggested)

Options

  • triggerActions: automatically trigger choiches actions (default: true)
  • caseSensitive: case sensitive while trying to match input with provided choiches (default: false)
  • spaceAfterPrompt: sets a space character between the prompt and the input (default: true)
  • suggestionColor: sets the colors of the suggested commands
  • promptColor: sets the color of the prompt
  • inputColor: sets the color of the typed input

Example

import { nicliPrompt, Choiche, PromptOptions } from "niclijs"

const choiches: Choiche[] = [{
	command: "SAY_HELLO",
	description: "prints 'hello'",
	action: () => console.log("hello")
}, {
	command: "ECHO",
	description: "prints arguments",
	action: (args) => console.log(...args)
}];

const options: PromptOptions = {
	promptColor: ["FgRed", "BgYellow"],
	inputColor: ["FgYellow"]
};

(async function () {
	while (true) {
		const { command, choiche, exit } = await nicliPrompt("nicli >", choiches, options)
		if (exit) process.exit(0)
		if (!choiche) console.log("unknow command: ", command)
	}	
})()

Next steps

  • Better arguments parsing: implement the use of quotation marks to allow space char in arguments (done)
  • Smart Autocompletion: provide arguments in the description and keep suggesting while inserting them

Known Bugs

  • sometimes, when typing fast, the character gets placed at the begining of the input and not on the cursor position
  • when suggestion text goes to a new line, so does the cursor (even if it's placed in the right position horizontally) (fixed)
0.0.21

11 months ago

0.0.20

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago