UNPKG

@nu-art/commando

Version:
62 lines (61 loc) 2.56 kB
import { Logger, LogLevel } from '@nu-art/ts-common'; import { LogTypes } from '../types'; type LogProcessor = (log: string, std: LogTypes) => boolean; export declare class InteractiveShell extends Logger { private _debug; private logProcessors; private shell; private alive; private logLevelFilter; /** * Constructs an InteractiveShell instance, initializes a detached shell session, and sets up log processors. */ constructor(); /** * Toggles or sets the debug mode. * @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode. * @returns {boolean} - The current state of debug mode. */ debug(debug?: boolean): this; /** * Executes a command in the interactive shell. * @param {string} command - The command to execute. */ execute: (command: string) => void; /** * Awaits for the end of the interactive shell session. */ endInteractive: () => Promise<void>; /** * Sends a signal to terminate the shell process. * @param {NodeJS.Signals | number} [signal] - The signal to send to the shell process. * @returns {boolean | undefined} - The result of the kill operation. */ kill: (signal?: NodeJS.Signals | number) => boolean | undefined; /** * Attempts to gracefully terminate the shell process. * @param {number} [pid] - Process ID of the shell to terminate. * @returns {Promise<void>} - Resolves when the shell process is gracefully killed. */ gracefullyKill: (pid?: number) => Promise<void>; /** * Adds a log processor to handle log messages. * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function. * @returns {this} - The InteractiveShell instance for method chaining. */ addLogProcessor(processor: LogProcessor): this; setLogLevelFilter(logLevelFilter: (log: string, std: LogTypes) => LogLevel | undefined): this; /** * Removes a log processor from handling log messages. * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove. * @returns {this} - The InteractiveShell instance for method chaining. */ removeLogProcessor(processor: LogProcessor): this; /** * Sets a unique identifier for the shell session. * @param {string} uid - The unique identifier. * @returns {this} - The InteractiveShell instance for method chaining. */ setUID(uid: string): this; } export {};