Represents the context in which a command is executed

interface ICliExecutionContext {
    clearCurrentLine: () => void;
    clearLine: () => void;
    clipboard: ICliClipboard;
    currentLine: string;
    cursorPosition: number;
    executor: ICliCommandExecutorService;
    logger: ICliLogger;
    onAbort: Subject<void>;
    options?: CliOptions;
    process: ICliExecutionProcess;
    progressBar: ICliPercentageProgressBar;
    promptLength: number;
    refreshCurrentLine: () => void;
    services: ICliServiceProvider;
    setContextProcessor: (
        processor: ICliCommandProcessor,
        silent?: boolean,
    ) => void;
    setCurrentLine: (line: string) => void;
    showPrompt: (
        options?: {
            keepCurrentLine?: boolean;
            newLine?: boolean;
            reset?: boolean;
        },
    ) => void;
    spinner?: ICliSpinner;
    state: ICliStateStore;
    terminal: Terminal;
    textAnimator?: ICliTextAnimator;
    userSession?: ICliUserSession;
    writer: ICliTerminalWriter;
}

Properties

clearCurrentLine: () => void

Clears the current line content and reprints the prompt.

clearLine: () => void

Clears the current terminal line, including content that wraps across multiple rows. Uses promptLength + currentLine.length to determine how many rows to clear.

clipboard: ICliClipboard

The clipboard to use for copying/pasting

currentLine: string

The current user input text on the active line.

cursorPosition: number

The cursor position within the current line.

The command executor to use for executing commands

logger: ICliLogger

The logger to use for logging

onAbort: Subject<void>

A subject that emits when the command is aborted

options?: CliOptions

The options for the CLI

The process to use for exiting the CLI

The progress bar to use for showing progress

promptLength: number

The number of visible characters the prompt occupies on the current line.

refreshCurrentLine: () => void

Refreshes the display of the current line (clears and redraws prompt + input).

The services to use for the CLI context

setContextProcessor: (processor: ICliCommandProcessor, silent?: boolean) => void

Set the current processor as the context processor, i.e. the processor that will handle the command

Type declaration

    • (processor: ICliCommandProcessor, silent?: boolean): void
    • Parameters

      • processor: ICliCommandProcessor

        The processor to set

      • Optionalsilent: boolean

        Indicates if the setting should be silent, i.e. not write to the terminal

      Returns void

setCurrentLine: (line: string) => void

Sets the current line text.

Type declaration

    • (line: string): void
    • Parameters

      • line: string

        The new line content

      Returns void

showPrompt: (
    options?: {
        keepCurrentLine?: boolean;
        newLine?: boolean;
        reset?: boolean;
    },
) => void

Prints the prompt to the terminal.

spinner?: ICliSpinner

The spinner to use for showing/hiding the loader

The state store to use for storing state

terminal: Terminal

The terminal to use for writing

textAnimator?: ICliTextAnimator

The text animator to use for showing/hiding text

userSession?: ICliUserSession

The current user session

The writer to use for writing to the terminal