Skip to main content

Built and signed on GitHub Actions

A tool for building "dynamic" CLI.

This package works with Node.js, BunIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Bun
JSR Score
100%
Published
10 months ago (1.1.5)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

class DynamicCLI

The DynamicCLI itself

Constructors

new
DynamicCLI(options?: DynamicCliOptions)

Properties

readonly
currentPage: undefined | string
readonly
cursorY: undefined | number
readonly
input: string
interface: undefined | readline.Interface
readonly
pages: string[]
readonly
size: { width: number; height: number; }
private
_data: { input: string; currentPage: undefined | string; }
private
_layout: any[]
private
_listeners: { [key: string]: Listener; }
private
_pages: { [key: string]: Page; }
private
_size: { width: undefined | number; height: undefined | number; }
private
_style: Style

Methods

private
_callEvent(
type: string,
data: any,
): void

Call an event

private
_getSize(): { width: number; height: number; }

Get the size of the CLI

private
_handleInput(key: Buffer): void

Handle user input

private
_renderComponent(component: any): string[]

Render a component

private
_sperateColor(text: string): { sequence?: string; text: string; }[]

Seperate the color from the text

createPage(
id: string,
name: string,
callback: () => string[],
): DynamicCLI

Create a page

deletePage(id: string): void

Delete a page

listen(
type: "scroll",
callback: (info: { page: string; cursorY: number; scrollY: number; }) => any,
): void

Listen to an event

listen(
type: "switchPage",
callback: (pageID: string) => any,
): void
listen(
type: "enter",
callback: (input: string) => any,
): void
listen(
type: "input" | "keydown",
callback: (key: Buffer) => any,
): void

Remove all listeners

Remove a listener

render(): { line: number; content: string; }[]

Render the CLI

setInput(string: string): void

Set the input

setLayout(layout: { [key: string]: any; type:
"blank"
| "text"
| "pageTabs"
| "pageContent"
| "input"
; }[]
): DynamicCLI

Set the layout of the CLI

setSize(
width: undefined | number,
height: undefined | number,
): DynamicCLI

Set the size of the CLI

Set the style of the CLI

simulateInput(key: Buffer): void

Simulate user input

stop(): void

Stop the CLI

switchPage(id: string): void

Switch the page

Add Package

npx jsr add @lightbery/dynamic-cli

Import symbol

import { DynamicCLI } from "@lightbery/dynamic-cli";

Add Package

yarn dlx jsr add @lightbery/dynamic-cli

Import symbol

import { DynamicCLI } from "@lightbery/dynamic-cli";

Add Package

pnpm dlx jsr add @lightbery/dynamic-cli

Import symbol

import { DynamicCLI } from "@lightbery/dynamic-cli";

Add Package

bunx jsr add @lightbery/dynamic-cli

Import symbol

import { DynamicCLI } from "@lightbery/dynamic-cli";