@lightbery/dynamic-cli@1.0.6Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
A tool for building "dynamic" CLI.
DynamicCLI
A tool for building "dynamic" CLI.
Example
import { DynamicCLI } from './DynamicCLI' new DynamicCLI() .createPage('Page1', 'A Page', () => ['This', 'Is', 'A', 'Page']) .createPage('Page2', 'Another Page', () => ['This', 'Is', 'Another', 'Page'])
[!Note] DynamicCLI need
@types/wcwidth
andwcwidth
as dependencies.
Contents
DynamicCLI
import { DynamicCLI } from './DynamicCLI' new DynamicCLI(<options>) // Create a CLI
options <undefined | object>
| Options for the CLI.render <boolean>
| Should the CLI render stuff onto the console.Default: true
renderInterval <number>
| The interval(ms) between each render.Default: 50
Getters
.pages <string[]>
| Get IDs of all the pages..input <string>
| Get user input..currentPage <string>
| Get the ID of current page.
Stop()
.stop() // Stop the CLI
return <undefined>
setLayout()
.setLayout(<layout>) // Set the layout of the CLI
layout <any[]>
| An contains components.
return <DynamicCLI>
setStyle()
.setStyle(<style>) // Set the style of the CLI
style <object>
- Default Style -
{ background: BackgroundColor.reset, selectBackground: BackgroundColor.white, selectFont: TextColor.gray, notSelectBackground: BackgroundColor.gray, notSelectFont: TextColor.white }
return <DynamicCLI>
createPage()
.createPage(<id>, <name>, <callback>) // Create a page
id <string>
| The ID of the page.name <string>
| The name of the page.callback <function>
| The render function of the page, the function must return<string[]>
.
return <DynamicCLI>
deletePage()
.deletePage(<id>) // Delete a page
id <string>
| The ID of the page.
return <DynamicCLI>
setInput
.setInput(<string>) // Set the input
string <string>
| The content of the input.
return <undefined>
simulateInput
.simulateInput(<input>, <key>) // Simulate user input
input <string>
| The full input.key <Buffer>
| The keystroke of the input.
return <undefined>
switchPage
.switchPage(<id>) // Switch page
id <string>
| The id of the page.
return <undefined>
listen
.listen(<name>, <callback>) // Listen to an event
name <string>
| The name of the event.callback <function>
| The function that triggers when the event is called.
- All Events -
name | callback data | description |
---|---|---|
scroll | ({ page, cursorY, scrollY }) | Triggered when user scrolls. |
switchPage | (pageID) | Triggered when user switches pages. |
enter | (input) | Triggered when user press enter. |
input | (key) | Triggered when user input. |
return <undefined>
Component
import { Component } from './DynamicCLI' Component.<name>(<parameters>)
- All Components -
name | parameters | description |
---|---|---|
blank | () | A blank line. |
text | (callback) | A line of text, callback must be a function that return a . |
pageTabs | () | A line of page tabs. |
pageContent | () | Multiple lines of page content. |
input | (placeholder) | A line of input. |
TextColor
import { TextColor } from './DynamicCLI' TextColor.<name>
- All Colors -
reset
, red
, brightRed
, yellow
, brightYellow
, green
, brightGreen
, cyan
, brightCyan
, blue
, brightBlue
, purple
, brightPurple
, white
, black
, gray
BackgroundColor
import { BackgroundColor } from './DynamicCLI' BackgroundColor.<name>
- All Colors -
reset
, red
, brightRed
, yellow
, brightYellow
, green
, brightGreen
, cyan
, brightCyan
, blue
, brightBlue
, purple
, brightPurple
, white
, black
, gray
Add Package
pnpm i jsr:@lightbery/dynamic-cli
pnpm dlx jsr add @lightbery/dynamic-cli
Import symbol
import * as dynamic_cli from "@lightbery/dynamic-cli";
Add Package
yarn add jsr:@lightbery/dynamic-cli
yarn dlx jsr add @lightbery/dynamic-cli
Import symbol
import * as dynamic_cli from "@lightbery/dynamic-cli";
Add Package
vlt install jsr:@lightbery/dynamic-cli
Import symbol
import * as dynamic_cli from "@lightbery/dynamic-cli";
Add Package
npx jsr add @lightbery/dynamic-cli
Import symbol
import * as dynamic_cli from "@lightbery/dynamic-cli";
Add Package
bunx jsr add @lightbery/dynamic-cli
Import symbol
import * as dynamic_cli from "@lightbery/dynamic-cli";