UNPKG

r3bl-ts-utils

Version:

The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu

45 lines (44 loc) 1.76 kB
/// <reference types="node" /> import EventEmitter from "events"; import { render } from "ink"; /** * Launches a CLI app. This is the "bootloader" equivalent for a CLI app. * * If you have any event listeners attached (eg, using `useKeyboard()`, or `useNodeKeypress()`) then * your app won't exit if you don't call `LifecycleHelper.fireExit()`. * * Usage example: * ```tsx * const App:FC = ()=> { * const createShortcutsFn = (): ShortcutToActionMap => * _also( * createNewShortcutToActionMap(), * map => map.set("q", LifecycleHelper.fireExit) * ) * useKeyboardWithMapCached(createShortcutsFn) * return( <Text>"Hello"</Text> ) * } * * inkCLIAppMainFn( ()=>{ * const args = processCommandLineArgs() * return createInkApp(args) * } ).catch(console.error) * ``` * * @param {() => ReturnType<typeof render>} runFn Do what you need to create an Ink instance * @param okExitMsg If non empty string (truthy) display this on exit w/out errors * @param errExitMsg If non empty string (truthy) display this on exit w/ errors * @return {Promise<void>} Optionally attach a catch block to this promise */ export declare const inkCLIAppMainFn: (runFn: () => ReturnType<typeof render>, okExitMsg?: string, errExitMsg?: string) => Promise<void>; declare type EventName = "exit" | "start"; declare type EventListener = (name: EventName) => void; export declare class LifecycleHelper extends EventEmitter { static instance: LifecycleHelper; static addStartListener: (listener: EventListener) => LifecycleHelper; static addExitListener: (listener: EventListener) => LifecycleHelper; static fireExit: () => boolean; static fireStart: () => boolean; static removeAll: () => LifecycleHelper; } export {};