@poppinss/cliui
Advanced tools
Comparing version 6.2.0 to 6.2.1
import { Colors } from '@poppinss/colors/types'; | ||
export { default as colors } from '@poppinss/colors'; | ||
import { TableOptions, RendererContract, TableHead, TableRow, ActionOptions, SpinnerMessage, LoggerMessageOptions, LoggerOptions, InstructionsOptions, TaskManagerOptions, TaskCallback } from './src/types.js'; | ||
import 'cli-table3'; | ||
import { default as poppinssColors } from '@poppinss/colors'; | ||
import { icons } from './src/icons.js'; | ||
import { Table } from './src/table.js'; | ||
import { Logger } from './src/logger/main.js'; | ||
import { Instructions } from './src/instructions.js'; | ||
import { TaskManager } from './src/tasks/manager.js'; | ||
import { MemoryRenderer } from './src/renderers/memory.js'; | ||
import { ConsoleRenderer } from './src/renderers/console.js'; | ||
import type { RendererContract, TableOptions, TaskManagerOptions } from './src/types.js'; | ||
export { icons, Table, Logger, TaskManager, Instructions, MemoryRenderer, ConsoleRenderer, poppinssColors as colors, }; | ||
/** | ||
* A collection of platform specific icons | ||
*/ | ||
declare const icons: { | ||
tick: string; | ||
cross: string; | ||
bullet: string; | ||
nodejs: string; | ||
pointer: string; | ||
info: string; | ||
warning: string; | ||
squareSmallFilled: string; | ||
}; | ||
/** | ||
* Exposes the API to represent a table | ||
*/ | ||
declare class Table { | ||
#private; | ||
constructor(options?: Partial<TableOptions>); | ||
/** | ||
* Returns the renderer for rendering the messages | ||
*/ | ||
getRenderer(): RendererContract; | ||
/** | ||
* Define a custom renderer. Logs to "stdout" and "stderr" | ||
* by default | ||
*/ | ||
useRenderer(renderer: RendererContract): this; | ||
/** | ||
* Returns the colors implementation in use | ||
*/ | ||
getColors(): Colors; | ||
/** | ||
* Define a custom colors implementation | ||
*/ | ||
useColors(color: Colors): this; | ||
/** | ||
* Define table head | ||
*/ | ||
head(headColumns: TableHead): this; | ||
/** | ||
* Add a new table row | ||
*/ | ||
row(row: TableRow): this; | ||
/** | ||
* Define custom column widths | ||
*/ | ||
columnWidths(widths: number[]): this; | ||
/** | ||
* Toggle whether or render in full width or not | ||
*/ | ||
fullWidth(renderFullWidth?: boolean): this; | ||
/** | ||
* Define the column index that should take | ||
* will remaining width when rendering in | ||
* full-width | ||
*/ | ||
fluidColumnIndex(index: number): this; | ||
/** | ||
* Render table | ||
*/ | ||
render(): void; | ||
} | ||
/** | ||
* Exposes the API to print actions in one of the following three states | ||
* | ||
* - failed | ||
* - succeeded | ||
* - skipped | ||
*/ | ||
declare class Action { | ||
#private; | ||
constructor(message: string, options?: Partial<ActionOptions>); | ||
/** | ||
* Returns the renderer for rendering the messages | ||
*/ | ||
getRenderer(): RendererContract; | ||
/** | ||
* Define a custom renderer. | ||
*/ | ||
useRenderer(renderer: RendererContract): this; | ||
/** | ||
* Returns the colors implementation in use | ||
*/ | ||
getColors(): Colors; | ||
/** | ||
* Define a custom colors implementation | ||
*/ | ||
useColors(color: Colors): this; | ||
/** | ||
* Toggle whether to display duration for completed | ||
* tasks or not. | ||
*/ | ||
displayDuration(displayDuration?: boolean): this; | ||
/** | ||
* Prepares the message to mark action as successful | ||
*/ | ||
prepareSucceeded(): string; | ||
/** | ||
* Mark action as successful | ||
*/ | ||
succeeded(): void; | ||
/** | ||
* Prepares the message to mark action as skipped | ||
*/ | ||
prepareSkipped(skipReason?: string): string; | ||
/** | ||
* Mark action as skipped. An optional skip reason can be | ||
* supplied | ||
*/ | ||
skipped(skipReason?: string): void; | ||
/** | ||
* Prepares the message to mark action as failed | ||
*/ | ||
prepareFailed(error: string | Error): string; | ||
/** | ||
* Mark action as failed. An error message is required | ||
*/ | ||
failed(error: string | Error): void; | ||
} | ||
/** | ||
* Textual spinner to print a message with dotted progress | ||
* bar. | ||
*/ | ||
declare class Spinner { | ||
#private; | ||
constructor(message: SpinnerMessage); | ||
/** | ||
* Returns the renderer for rendering the messages | ||
*/ | ||
getRenderer(): RendererContract; | ||
/** | ||
* Define the custom renderer | ||
*/ | ||
useRenderer(renderer: RendererContract): this; | ||
/** | ||
* Star the spinner | ||
*/ | ||
start(): this; | ||
/** | ||
* Update spinner | ||
*/ | ||
update(text: string, options?: LoggerMessageOptions): this; | ||
/** | ||
* Stop spinner | ||
*/ | ||
stop(): void; | ||
/** | ||
* Tap into spinner to manually write the | ||
* output. | ||
*/ | ||
tap(callback: (line: string) => void): this; | ||
} | ||
/** | ||
* CLI logger to log messages to the console. The output is consistently | ||
* formatted. | ||
*/ | ||
declare class Logger implements RendererContract { | ||
#private; | ||
getLogs(): { | ||
message: string; | ||
stream: 'stdout' | 'stderr'; | ||
}[]; | ||
constructor(options?: Partial<LoggerOptions>); | ||
/** | ||
* Returns the renderer for rendering the messages | ||
*/ | ||
getRenderer(): RendererContract; | ||
/** | ||
* Define a custom renderer to output logos | ||
*/ | ||
useRenderer(renderer: RendererContract): this; | ||
/** | ||
* Returns the colors implementation in use | ||
*/ | ||
getColors(): Colors; | ||
/** | ||
* Define a custom colors implementation | ||
*/ | ||
useColors(color: Colors): this; | ||
/** | ||
* Log message | ||
*/ | ||
log(message: string): void; | ||
/** | ||
* Log message by updating the existing line | ||
*/ | ||
logUpdate(message: string): void; | ||
/** | ||
* Persist log line written using the `logUpdate` | ||
* method. | ||
*/ | ||
logUpdatePersist(): void; | ||
/** | ||
* Log error message using the renderer. It is similar to `console.error` | ||
* but uses the underlying renderer instead | ||
*/ | ||
logError(message: string): void; | ||
/** | ||
* Prepares the success message | ||
*/ | ||
prepareSuccess(message: string, options?: LoggerMessageOptions): string; | ||
/** | ||
* Log success message | ||
*/ | ||
success(message: string, options?: LoggerMessageOptions): void; | ||
/** | ||
* Prepares the error message | ||
*/ | ||
prepareError(message: string | { | ||
message: string; | ||
}, options?: LoggerMessageOptions): string; | ||
/** | ||
* Log error message | ||
*/ | ||
error(message: string | { | ||
message: string; | ||
}, options?: LoggerMessageOptions): void; | ||
/** | ||
* Prepares the fatal message | ||
*/ | ||
prepareFatal(message: string | { | ||
message: string; | ||
stack?: string; | ||
}, options?: LoggerMessageOptions): string; | ||
/** | ||
* Log fatal message | ||
*/ | ||
fatal(message: string | { | ||
message: string; | ||
stack?: string; | ||
}, options?: LoggerMessageOptions): void; | ||
/** | ||
* Prepares the warning message | ||
*/ | ||
prepareWarning(message: string, options?: LoggerMessageOptions): string; | ||
/** | ||
* Log warning message | ||
*/ | ||
warning(message: string, options?: LoggerMessageOptions): void; | ||
/** | ||
* Prepares the info message | ||
*/ | ||
prepareInfo(message: string, options?: LoggerMessageOptions): string; | ||
/** | ||
* Log info message | ||
*/ | ||
info(message: string, options?: LoggerMessageOptions): void; | ||
/** | ||
* Prepares the debug message | ||
*/ | ||
prepareDebug(message: string, options?: LoggerMessageOptions): string; | ||
/** | ||
* Log debug message | ||
*/ | ||
debug(message: string, options?: LoggerMessageOptions): void; | ||
/** | ||
* Log a message with a spinner | ||
*/ | ||
await(text: string, options?: LoggerMessageOptions): Spinner; | ||
/** | ||
* Initiates a new action | ||
*/ | ||
action(title: string): Action; | ||
/** | ||
* Create a new child instance of self | ||
*/ | ||
child(options?: Partial<LoggerOptions>): Logger; | ||
} | ||
/** | ||
* The API to render instructions wrapped inside a box | ||
*/ | ||
declare class Instructions { | ||
#private; | ||
constructor(options?: Partial<InstructionsOptions>); | ||
/** | ||
* Returns the renderer for rendering the messages | ||
*/ | ||
getRenderer(): RendererContract; | ||
/** | ||
* Define a custom renderer. Logs to "stdout" and "stderr" | ||
* by default | ||
*/ | ||
useRenderer(renderer: RendererContract): this; | ||
/** | ||
* Returns the colors implementation in use | ||
*/ | ||
getColors(): Colors; | ||
/** | ||
* Define a custom colors implementation | ||
*/ | ||
useColors(color: Colors): this; | ||
/** | ||
* Draw the instructions box in fullscreen | ||
*/ | ||
fullScreen(): this; | ||
/** | ||
* Attach a callback to self draw the borders | ||
*/ | ||
drawBorder(callback: (borderChar: string, colors: Colors) => string): this; | ||
/** | ||
* Define heading for instructions | ||
*/ | ||
heading(text: string): this; | ||
/** | ||
* Add new instruction. Each instruction is rendered | ||
* in a new line inside a box | ||
*/ | ||
add(text: string): this; | ||
prepare(): string; | ||
/** | ||
* Render instructions | ||
*/ | ||
render(): void; | ||
} | ||
/** | ||
* Task exposes a very simple API to create tasks with states, along with a | ||
* listener to listen for the task state updates. | ||
* | ||
* The task itself has does not render anything to the console. The task | ||
* renderers does that. | ||
*/ | ||
declare class Task { | ||
#private; | ||
title: string; | ||
constructor(title: string); | ||
/** | ||
* Access the task state | ||
*/ | ||
getState(): "failed" | "idle" | "running" | "succeeded"; | ||
/** | ||
* Get the time spent in running the task | ||
*/ | ||
getDuration(): string | null; | ||
/** | ||
* Get error occurred while running the task | ||
*/ | ||
getError(): string | { | ||
message: string; | ||
stack?: string | undefined; | ||
} | null; | ||
/** | ||
* Get task completion success message | ||
*/ | ||
getSuccessMessage(): string | null; | ||
/** | ||
* Last logged line for the task | ||
*/ | ||
getLastLoggedLine(): string | null; | ||
/** | ||
* Bind a listener to listen to the state updates of the task | ||
*/ | ||
onUpdate(listener: (task: this) => void): this; | ||
/** | ||
* Start the task | ||
*/ | ||
start(): this; | ||
/** | ||
* Update task with log messages. Based upon the renderer | ||
* in use, it may only display one line at a time. | ||
*/ | ||
update(message: string): this; | ||
/** | ||
* Mark task as completed | ||
*/ | ||
markAsSucceeded(message?: string): this; | ||
/** | ||
* Mark task as failed | ||
*/ | ||
markAsFailed(error: string | { | ||
message: string; | ||
stack?: string; | ||
}): this; | ||
} | ||
/** | ||
* Exposes the API to create a group of tasks and run them in sequence | ||
*/ | ||
declare class TaskManager { | ||
#private; | ||
constructor(options?: Partial<TaskManagerOptions>); | ||
/** | ||
* Access the task state | ||
*/ | ||
getState(): "failed" | "idle" | "running" | "succeeded"; | ||
/** | ||
* Register a new task | ||
*/ | ||
add(title: string, callback: TaskCallback): this; | ||
/** | ||
* Get access to registered tasks | ||
*/ | ||
tasks(): Task[]; | ||
/** | ||
* Returns the renderer for rendering the messages | ||
*/ | ||
getRenderer(): RendererContract; | ||
/** | ||
* Define a custom renderer. Logs to "stdout" and "stderr" | ||
* by default | ||
*/ | ||
useRenderer(renderer: RendererContract): this; | ||
/** | ||
* Define a custom colors implementation | ||
*/ | ||
useColors(color: Colors): this; | ||
/** | ||
* Run tasks | ||
*/ | ||
run(): Promise<void>; | ||
} | ||
/** | ||
* Keeps log messages within memory. Useful for testing | ||
*/ | ||
declare class MemoryRenderer implements RendererContract { | ||
#private; | ||
getLogs(): { | ||
message: string; | ||
stream: "stdout" | "stderr"; | ||
}[]; | ||
/** | ||
* Log message | ||
*/ | ||
log(message: string): void; | ||
/** | ||
* For memory renderer the logUpdate is similar to log | ||
*/ | ||
logUpdate(message: string): void; | ||
/** | ||
* Its a noop | ||
*/ | ||
logUpdatePersist(): void; | ||
/** | ||
* Log message as error | ||
*/ | ||
logError(message: string): void; | ||
} | ||
/** | ||
* Renders messages to the "stdout" and "stderr" | ||
*/ | ||
declare class ConsoleRenderer implements RendererContract { | ||
getLogs(): never[]; | ||
log(message: string): void; | ||
/** | ||
* Log message by overwriting the existing one | ||
*/ | ||
logUpdate(message: string): void; | ||
/** | ||
* Persist the last logged message | ||
*/ | ||
logUpdatePersist(): void; | ||
/** | ||
* Log error | ||
*/ | ||
logError(message: string): void; | ||
} | ||
/** | ||
* Create a new CLI UI instance. | ||
@@ -478,3 +19,3 @@ * | ||
*/ | ||
declare function cliui(options?: Partial<{ | ||
export declare function cliui(options?: Partial<{ | ||
mode: 'raw' | 'silent' | 'normal'; | ||
@@ -502,3 +43,1 @@ }>): { | ||
}; | ||
export { ConsoleRenderer, Instructions, Logger, MemoryRenderer, Table, TaskManager, cliui, icons }; |
import { | ||
TERMINAL_SIZE | ||
} from "./chunk-QU5FTD3C.js"; | ||
} from "./chunk-ELPEUXI6.js"; | ||
@@ -1853,1 +1853,2 @@ // index.ts | ||
}; | ||
//# sourceMappingURL=index.js.map |
/** | ||
* Total number of columns for the terminal | ||
*/ | ||
declare const TERMINAL_SIZE: number; | ||
export declare const TERMINAL_SIZE: number; | ||
/** | ||
@@ -11,3 +11,3 @@ * Justify the columns to have the same width by filling | ||
*/ | ||
declare function justify(columns: string[], options: { | ||
export declare function justify(columns: string[], options: { | ||
maxWidth: number; | ||
@@ -23,3 +23,3 @@ align?: 'left' | 'right'; | ||
*/ | ||
declare function wrap(columns: string[], options: { | ||
export declare function wrap(columns: string[], options: { | ||
startColumn: number; | ||
@@ -32,3 +32,3 @@ endColumn: number; | ||
*/ | ||
declare function truncate(columns: string[], options: { | ||
export declare function truncate(columns: string[], options: { | ||
maxWidth: number; | ||
@@ -38,3 +38,1 @@ truncationChar?: string; | ||
}): string[]; | ||
export { TERMINAL_SIZE, justify, truncate, wrap }; |
@@ -6,3 +6,3 @@ import { | ||
wrap | ||
} from "../chunk-QU5FTD3C.js"; | ||
} from "../chunk-ELPEUXI6.js"; | ||
export { | ||
@@ -14,1 +14,2 @@ TERMINAL_SIZE, | ||
}; | ||
//# sourceMappingURL=helpers.js.map |
import { CharName } from 'cli-table3'; | ||
export { Colors } from '@poppinss/colors/types'; | ||
import type { Colors } from '@poppinss/colors/types'; | ||
export { Colors }; | ||
/** | ||
@@ -8,3 +8,3 @@ * Shape of the renderer contract. Renderers are responsible for | ||
*/ | ||
interface RendererContract { | ||
export interface RendererContract { | ||
getLogs(): { | ||
@@ -35,3 +35,3 @@ message: string; | ||
*/ | ||
type TaskCallback = (task: { | ||
export type TaskCallback = (task: { | ||
/** | ||
@@ -58,3 +58,3 @@ * Update task progress with a log message | ||
*/ | ||
type TaskRendererOptions = { | ||
export type TaskRendererOptions = { | ||
/** | ||
@@ -70,3 +70,3 @@ * Enable/disable icons. | ||
*/ | ||
type TaskManagerOptions = TaskRendererOptions & { | ||
export type TaskManagerOptions = TaskRendererOptions & { | ||
/** | ||
@@ -91,3 +91,3 @@ * Display tasks output in raw mode. | ||
*/ | ||
type LoggerOptions = { | ||
export type LoggerOptions = { | ||
/** | ||
@@ -110,3 +110,3 @@ * Output message with dim transformation. | ||
*/ | ||
type ActionOptions = { | ||
export type ActionOptions = { | ||
/** | ||
@@ -122,3 +122,3 @@ * Output message with dim transformation. | ||
*/ | ||
type TableOptions = { | ||
export type TableOptions = { | ||
/** | ||
@@ -136,3 +136,3 @@ * Disable ansi output | ||
*/ | ||
type InstructionsOptions = { | ||
export type InstructionsOptions = { | ||
/** | ||
@@ -152,7 +152,7 @@ * Enable/disable icons. | ||
*/ | ||
type LoggingTypes = 'success' | 'error' | 'fatal' | 'warning' | 'info' | 'debug' | 'await'; | ||
export type LoggingTypes = 'success' | 'error' | 'fatal' | 'warning' | 'info' | 'debug' | 'await'; | ||
/** | ||
* The data type to represent the table head | ||
*/ | ||
type TableHead = (string | { | ||
export type TableHead = (string | { | ||
colSpan?: number; | ||
@@ -169,3 +169,3 @@ hAlign?: 'left' | 'center' | 'right'; | ||
*/ | ||
type TableRow = (string | { | ||
export type TableRow = (string | { | ||
colSpan?: number; | ||
@@ -185,3 +185,3 @@ hAlign?: 'left' | 'center' | 'right'; | ||
*/ | ||
type LoggerMessageOptions = { | ||
export type LoggerMessageOptions = { | ||
prefix?: string; | ||
@@ -193,7 +193,5 @@ suffix?: string; | ||
*/ | ||
type SpinnerMessage = { | ||
export type SpinnerMessage = { | ||
text: string; | ||
render(): string; | ||
}; | ||
export { ActionOptions, InstructionsOptions, LoggerMessageOptions, LoggerOptions, LoggingTypes, RendererContract, SpinnerMessage, TableHead, TableOptions, TableRow, TaskCallback, TaskManagerOptions, TaskRendererOptions }; |
{ | ||
"name": "@poppinss/cliui", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "Opinionated UI KIT for Command Line apps", | ||
@@ -8,3 +8,6 @@ "main": "build/index.js", | ||
"files": [ | ||
"build" | ||
"build", | ||
"!build/bin", | ||
"!build/examples", | ||
"!build/tests" | ||
], | ||
@@ -24,3 +27,4 @@ "exports": { | ||
"typecheck": "tsc --noEmit", | ||
"compile": "npm run lint && npm run clean && tsup-node", | ||
"precompile": "npm run lint && npm run clean", | ||
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration", | ||
"build": "npm run compile", | ||
@@ -46,13 +50,13 @@ "prepublishOnly": "npm run build", | ||
"@adonisjs/tsconfig": "^1.1.8", | ||
"@commitlint/cli": "^17.7.2", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
"@commitlint/cli": "^18.2.0", | ||
"@commitlint/config-conventional": "^18.1.0", | ||
"@japa/assert": "^2.0.0", | ||
"@japa/runner": "^3.0.1", | ||
"@swc/core": "1.3.82", | ||
"@types/node": "^20.8.6", | ||
"@types/pretty-hrtime": "^1.0.1", | ||
"@types/wordwrap": "^1.0.1", | ||
"@japa/runner": "^3.0.4", | ||
"@swc/core": "^1.3.96", | ||
"@types/node": "^20.8.10", | ||
"@types/pretty-hrtime": "^1.0.2", | ||
"@types/wordwrap": "^1.0.2", | ||
"cross-env": "^7.0.3", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.51.0", | ||
"eslint": "^8.53.0", | ||
"github-label-sync": "^2.3.1", | ||
@@ -67,11 +71,11 @@ "husky": "^8.0.3", | ||
"dependencies": { | ||
"@poppinss/colors": "^4.1.0", | ||
"@poppinss/colors": "^4.1.1", | ||
"cli-boxes": "^3.0.0", | ||
"cli-table3": "^0.6.3", | ||
"cli-truncate": "^3.1.0", | ||
"log-update": "^5.0.1", | ||
"cli-truncate": "^4.0.0", | ||
"log-update": "^6.0.0", | ||
"pretty-hrtime": "^1.0.3", | ||
"string-width": "^6.1.0", | ||
"string-width": "^7.0.0", | ||
"supports-color": "^9.4.0", | ||
"term-size": "^3.0.2", | ||
"term-size": "^4.0.0", | ||
"wordwrap": "^1.0.0" | ||
@@ -115,5 +119,6 @@ }, | ||
"format": "esm", | ||
"dts": true, | ||
"dts": false, | ||
"sourcemap": true, | ||
"target": "esnext" | ||
} | ||
} |
@@ -283,3 +283,3 @@ # @poppinss/cliui | ||
const ui = cliui() | ||
const sticker = ui.instructions() | ||
const sticker = ui.sticker() | ||
@@ -286,0 +286,0 @@ sticker |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178071
28
2758
+ Addedansi-escapes@7.0.0(transitive)
+ Addedcli-cursor@5.0.0(transitive)
+ Addedcli-truncate@4.0.0(transitive)
+ Addedenvironment@1.1.0(transitive)
+ Addedget-east-asian-width@1.3.0(transitive)
+ Addedis-fullwidth-code-point@5.0.0(transitive)
+ Addedlog-update@6.1.0(transitive)
+ Addedmimic-function@5.0.1(transitive)
+ Addedonetime@7.0.0(transitive)
+ Addedrestore-cursor@5.1.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedslice-ansi@7.1.0(transitive)
+ Addedstring-width@7.2.0(transitive)
+ Addedterm-size@4.0.0(transitive)
+ Addedwrap-ansi@9.0.0(transitive)
- Removedansi-escapes@5.0.0(transitive)
- Removedcli-cursor@4.0.0(transitive)
- Removedcli-truncate@3.1.0(transitive)
- Removedeastasianwidth@0.2.0(transitive)
- Removedemoji-regex@9.2.2(transitive)
- Removedlog-update@5.0.1(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removedonetime@5.1.2(transitive)
- Removedrestore-cursor@4.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@5.1.26.1.0(transitive)
- Removedterm-size@3.0.2(transitive)
- Removedtype-fest@1.4.0(transitive)
- Removedwrap-ansi@8.1.0(transitive)
Updated@poppinss/colors@^4.1.1
Updatedcli-truncate@^4.0.0
Updatedlog-update@^6.0.0
Updatedstring-width@^7.0.0
Updatedterm-size@^4.0.0