UNPKG

@types/blessed

Version:
1,739 lines (1,385 loc) 100 kB
/// <reference types="node" /> import * as child_process from "child_process"; import { EventEmitter } from "events"; import { Readable, Writable } from "stream"; export interface IBlessedProgramOptions { input?: Readable | undefined; output?: Writable | undefined; log?: string | undefined; dump?: boolean | undefined; zero?: boolean | undefined; buffer?: boolean | undefined; terminal?: string | undefined; term?: string | undefined; tput?: string | undefined; debug?: boolean | undefined; resizeTimeout?: boolean | undefined; } export class BlessedProgram extends EventEmitter { type: string; options: IBlessedProgramOptions; input: Readable; output: Writable; zero: boolean; useBuffer: boolean; x: number; y: number; savedX: number; savedY: number; cols: number; rows: number; scrollTop: number; scrollBottom: number; isOSXTerm: boolean; isiTerm2: boolean; isXFCE: boolean; isTerminator: boolean; isLXDE: boolean; isVTE: boolean; isRxvt: boolean; isXterm: boolean; tmux: boolean; tmuxVersion: number; constructor(options?: IBlessedProgramOptions); log(): boolean; debug(): boolean; setupDump(): void; setupTput(): void; setTerminal(terminal: string): void; has(name: string): boolean; term(is: string): boolean; listen(): void; destroy(): void; key(key: string | string[], listener: Function): void; onceKey(key: string | string[], listener: Function): void; unKey(key: string | string[], listener: Function): void; removeKey(key: string | string[], listener: Function): void; bindMouse(): void; enableGpm(): void; disableGpm(): void; bindResponse(): void; response(name: string, text: string, callback: Function, noBypass?: boolean): boolean; response(name: string, callback?: Function): boolean; write(text: string): boolean; flush(): void; print(text: string, attr?: boolean): boolean; echo(text: string, attr?: boolean): boolean; setx(x: number): boolean; sety(y: number): boolean; move(x: number, y: number): boolean; omove(x: number, y: number): void; rsetx(x: number): boolean; rsety(y: number): boolean; rmove(x: number, y: number): void; simpleInsert(ch: string, i?: number, attr?: boolean): boolean; repeat(ch: string, i?: number): string; copyToClipboard(text: string): boolean; cursorShape(shape: string, blink?: boolean): boolean; cursorColor(color: string): boolean; cursorReset(): boolean; resetCursor(): boolean; getTextParams(param: string, callback: Function): boolean; getCursorColor(callback: Function): boolean; nul(): boolean; bell(): boolean; bel(): boolean; vtab(): boolean; form(): boolean; ff(): boolean; backspace(): boolean; kbs(): boolean; tab(): boolean; ht(): boolean; shiftOut(): boolean; shiftIn(): boolean; return(): boolean; cr(): boolean; feed(): boolean; newline(): boolean; nl(): boolean; index(): boolean; ind(): boolean; reverseIndex(): boolean; reverse(): boolean; ri(): boolean; nextLine(): boolean; reset(): boolean; tabSet(): boolean; saveCursor(key: string): boolean; sc(key: string): boolean; restoreCursor(key?: string, hide?: boolean): boolean; rc(key?: string, hide?: boolean): boolean; lsaveCursor(key?: string): void; lrestoreCursor(key?: string, hide?: boolean): void; lineHeight(): boolean; charset(val?: string, level?: number): boolean; enter_alt_charset_mode(): boolean; as(): boolean; smacs(): boolean; exit_alt_charset_mode(): boolean; ae(): boolean; rmacs(): boolean; setG(val: number): boolean; setTitle(title: string): boolean; resetColors(param?: string): boolean; dynamicColors(param?: string): boolean; selData(a: string, b: string): boolean; cursorUp(param?: number): boolean; cuu(param?: number): boolean; up(param?: number): boolean; cursorDown(param?: number): boolean; cud(param?: number): boolean; down(param?: number): boolean; cursorForward(param?: number): boolean; cuf(param?: number): boolean; right(param?: number): boolean; forward(param?: number): boolean; cursorBackward(param?: number): boolean; cub(param?: number): boolean; left(param?: number): boolean; back(param?: number): boolean; cursorPos(row?: number, col?: number): boolean; cup(row?: number, col?: number): boolean; pos(row?: number, col?: number): boolean; eraseInDisplay(param?: string): boolean; ed(param?: string): boolean; clear(): boolean; eraseInLine(param?: string): boolean; el(param?: string): boolean; charAttributes(param: string, val?: boolean): boolean; charAttributes(param: string[], val?: boolean): boolean; setForeground(color: string, val?: boolean): boolean; fg(color: string, val?: boolean): boolean; setBackground(color: string, val?: boolean): boolean; bg(color: string, val?: boolean): boolean; deviceStatuses(param?: string, callback?: Function, dec?: boolean, noBypass?: boolean): boolean; dsr(param?: string, callback?: Function, dec?: boolean, noBypass?: boolean): boolean; getCursor(callback: Function): boolean; saveReportedCursor(callback: Function): void; restoreReportedCursor: () => boolean; insertChars(param?: number): boolean; ich(param?: number): boolean; cursorNextLine(param?: number): boolean; cnl(param?: number): boolean; cursorPrecedingLine(param?: number): boolean; cpl(param?: number): boolean; cursorCharAbsolute(param?: number): boolean; cha(param?: number): boolean; insertLines(param?: number): boolean; il(param?: number): boolean; deleteLines(param?: number): boolean; dl(param?: number): boolean; deleteChars(param?: number): boolean; dch(param?: number): boolean; eraseChars(param?: number): boolean; ech(param?: number): boolean; charPosAbsolute(param?: number): boolean; hpa(param?: number): boolean; HPositionRelative(param?: number): boolean; sendDeviceAttributes(param?: number, callback?: Function): boolean; da(param?: number, callback?: Function): boolean; linePosAbsolute(param?: number): boolean; vpa(param?: number): boolean; VPositionRelative(param?: number): boolean; vpr(param?: number): boolean; HVPosition(row?: number, col?: number): boolean; hvp(row?: number, col?: number): boolean; setMode(...args: string[]): boolean; sm(...args: string[]): boolean; decset(...args: string[]): boolean; showCursor(): boolean; alternateBuffer(): boolean; smcup(): boolean; alternate(): boolean; resetMode(...args: string[]): boolean; rm(...args: string[]): boolean; decrst(...args: string[]): boolean; hideCursor(): boolean; civis(): boolean; vi(): boolean; cursor_invisible(): boolean; dectcemh(): boolean; normalBuffer(): boolean; rmcup(): boolean; enableMouse(): void; disableMouse(): void; setMouse(opt?: {}, enable?: boolean): void; setScrollRegion(top: number, bottom: number): boolean; csr(top: number, bottom: number): boolean; decstbm(top: number, bottom: number): boolean; saveCursorA(): boolean; scA(): boolean; restoreCursorA(): boolean; rcA(): boolean; cursorForwardTab(param?: number): boolean; cht(param?: number): boolean; scrollUp(param?: number): boolean; su(param?: number): boolean; scrollDown(param?: number): boolean; sd(param?: number): boolean; initMouseTracking(...args: string[]): boolean; resetTitleModes(...args: string[]): boolean; cursorBackwardTab(param?: number): boolean; cbt(param?: number): boolean; repeatPrecedingCharacter(param?: number): boolean; rep(param?: number): boolean; tabClear(param?: number): boolean; tbc(param?: number): boolean; mediaCopy(...args: string[]): boolean; mc(...args: string[]): boolean; mc0(): boolean; print_screen(): boolean; ps(): boolean; mc5(): boolean; prtr_on(): boolean; po(): boolean; mc4(): boolean; prtr_off(): boolean; pf(): boolean; mc5p(): boolean; prtr_non(): boolean; p0(): boolean; setResources(...args: string[]): boolean; disableModifieres(...args: string[]): boolean; setPointerMode(...args: string[]): boolean; softReset(): boolean; rs2(): boolean; decstr(): boolean; requestAnsiMode(param?: number): boolean; decrqm(param?: number): boolean; requestPrivateMode(param?: number): boolean; decrqmp(param?: number): boolean; setConformanceLevel(...args: string[]): boolean; decscl(...args: string[]): boolean; loadLEDs(param?: number): boolean; decll(param?: number): boolean; setCursorStyle(param?: string): boolean; decscursr(param?: string): boolean; setCharProtectionAttr(param?: number): boolean; decsca(param?: number): boolean; restorePrivateValues(...args: string[]): boolean; setAttrInRectangle(...args: string[]): boolean; deccara(...args: string[]): boolean; savePrivateValues(...args: string[]): boolean; manipulateWindow(...args: any[]): boolean; getWindowSize(callback?: Function): boolean; reverseAttrInRectangle(...args: string[]): boolean; decrara(...args: string[]): boolean; setTitleModeFeature(...args: string[]): boolean; setWarningBellVolume(param?: number): boolean; decswbv(param?: number): boolean; setMarginBellVolume(param?: number): boolean; copyRectangle(...args: string[]): boolean; deccra(...args: string[]): boolean; enableFilterRectangle(...args: string[]): boolean; decefr(...args: string[]): boolean; requestParameters(param?: number): boolean; decreqtparm(param: number): boolean; selectChangeExtent(param?: number): boolean; decsace(param?: number): boolean; fillRectangle(...args: string[]): boolean; decfra(...args: string[]): boolean; enableLocatorReporting(...args: string[]): boolean; decelr(...args: string[]): boolean; eraseRectangle(...args: string[]): boolean; decera(...args: string[]): boolean; setLocatorEvents(...args: string[]): boolean; decsle(...args: string[]): boolean; selectiveEraseRectangle(...args: string[]): boolean; decsera(...args: string[]): boolean; requestLocatorPosition(param?: string, callback?: Function): boolean; reqmp(param?: string, callback?: Function): boolean; req_mouse_pos(param?: string, callback?: Function): boolean; decrqlp(param?: string, callback?: Function): boolean; insertColumns(...args: string[]): boolean; decic(...args: string[]): boolean; deleteColumns(...args: string[]): boolean; decdc(...args: string[]): boolean; out(param: string, ...args: any[]): boolean; sigtstp(callback?: Function): boolean; pause(callback?: Function): Function; resume: () => void; } export namespace Widgets { namespace Types { type TTopLeft = string | number | "center"; type TPosition = string | number; type TMouseAction = "mousedown" | "mouseup" | "mousemove"; interface TStyleBorder { bg?: string | undefined; fg?: string | undefined; } interface Effects { bg?: string; fg?: string; border?: TStyleBorder | undefined; } interface TStyle { bg?: string | undefined; fg?: string | undefined; ch?: string | undefined; bold?: boolean | undefined; underline?: boolean | undefined; blink?: boolean | undefined; inverse?: boolean | undefined; invisible?: boolean | undefined; transparent?: boolean | undefined; border?: TStyleBorder; hover?: Effects | undefined; focus?: Effects | undefined; label?: string | undefined; track?: { bg?: string | undefined; fg?: string | undefined } | undefined; scrollbar?: { bg?: string | undefined; fg?: string | undefined } | undefined; } interface TBorder { /** * Type of border (line or bg). bg by default. */ type?: "line" | "bg" | undefined; /** * Character to use if bg type, default is space. */ ch?: string | undefined; /** * Border foreground and background, must be numbers (-1 for default). */ bg?: number | undefined; fg?: number | undefined; /** * Border attributes. */ bold?: string | undefined; underline?: string | undefined; } interface TCursor { /** * Have blessed draw a custom cursor and hide the terminal cursor (experimental). */ artificial: boolean; /** * Shape of the cursor. Can be: block, underline, or line. */ shape: "block" | "underline" | "line"; /** * Whether the cursor blinks. */ blink: boolean; /** * Color of the color. Accepts any valid color value (null is default). */ color: string; } type TAlign = "left" | "center" | "right"; interface ListbarCommand { key: string; callback(): void; } interface TImage { /** * Pixel width. */ width: number; /** * Pixel height. */ height: number; /** * Image bitmap. */ bmp: any; /** * Image cellmap (bitmap scaled down to cell size). */ cellmap: any; } interface Cursor { /** * Have blessed draw a custom cursor and hide the terminal cursor (experimental). */ artificial: boolean; /** * Shape of the cursor. Can be: block, underline, or line. */ shape: boolean; /** * Whether the cursor blinks. */ blink: boolean; /** * Color of the color. Accepts any valid color value (null is default). */ color: string; } } namespace Events { interface IMouseEventArg { x: number; y: number; action: Types.TMouseAction; } interface IKeyEventArg { full: string; name: string; shift: boolean; ctrl: boolean; meta: boolean; sequence: string; } } interface NodeChildProcessExecOptions { cwd?: string | undefined; stdio?: any; customFds?: any; env?: any; encoding?: string | undefined; timeout?: number | undefined; maxBuffer?: number | undefined; killSignal?: string | undefined; } interface IDestroyable { destroy(): void; } interface IOptions { [name: string]: any; } interface IHasOptions<T extends IOptions> { options: T; } interface TputsOptions extends IOptions { terminal?: string | undefined; extended?: boolean | undefined; debug?: boolean | undefined; termcap?: string | undefined; terminfoFile?: string | undefined; terminfoPrefix?: string | undefined; termcapFile?: string | undefined; } class Tput implements IHasOptions<TputsOptions> { constructor(opts: TputsOptions); /** * Original options object. */ options: TputsOptions; debug: boolean; padding: boolean; extended: boolean; printf: boolean; termcap: string; terminfoPrefix: string; terminfoFile: string; termcapFile: string; error: Error; terminal: string; setup(): void; term(is: any): boolean; readTerminfo(term: string): string; parseTerminfo( data: any, file: string, ): { header: { dataSize: number; headerSize: number; magicNumber: boolean; namesSize: number; boolCount: number; numCount: number; strCount: number; strTableSize: number; extended: { dataSize: number; headerSize: number; boolCount: number; numCount: number; strCount: number; strTableSize: number; lastStrTableOffset: number; }; }; name: string; names: string[]; desc: string; bools: any; numbers: any; strings: any; }; } interface IDestroyable { destroy(): void; } interface INodeOptions extends IOptions { name?: string | undefined; screen?: Screen | undefined; parent?: Node | undefined; children?: Node[] | undefined; focusable?: boolean | undefined; } type NodeEventType = /** Received when node is added to a parent. */ | "adopt" /** Received when node is removed from it's current parent. */ | "remove" /** Received when node gains a new parent. */ | "reparent" /** Received when node is attached to the screen directly or somewhere in its ancestry. */ | "attach" /** Received when node is detached from the screen directly or somewhere in its ancestry. */ | "detach"; abstract class Node extends EventEmitter implements IHasOptions<INodeOptions>, IDestroyable { constructor(options: INodeOptions); focusable: boolean; /** * Original options object. */ options: INodeOptions; /** * An object for any miscellanous user data. */ data: { [index: string]: any }; /** * An object for any miscellanous user data. */ _: { [index: string]: any }; /** * An object for any miscellanous user data. */ $: { [index: string]: any }; /** * Type of the node (e.g. box). */ type: string; /** * Render index (document order index) of the last render call. */ index: number; /** * Parent screen. */ screen: Screen; /** * Parent node. */ parent: Node; /** * Array of node's children. */ children: Node[]; /** * Prepend a node to this node's children. */ prepend(node: Node): void; /** * Append a node to this node's children. */ append(node: Node): void; /** * Remove child node from node. */ remove(node: Node): void; /** * Insert a node to this node's children at index i. */ insert(node: Node, index: number): void; /** * Insert a node to this node's children before the reference node. */ insertBefore(node: Node, refNode: Node): void; /** * Insert a node from node after the reference node. */ insertAfter(node: Node, refNode: Node): void; /** * Remove node from its parent. */ detach(): void; free(): void; forDescendants(iter: (node: Node) => void, s: any): void; forAncestors(iter: (node: Node) => void, s: any): void; collectDescendants(s: any): void; collectAncestors(s: any): void; /** * Emit event for element, and recursively emit same event for all descendants. */ emitDescendants(type?: string, ...args: any[]): void; emitAncestors(): void; hasDescendant(target: Node): void; hasAncestor(target: Node): boolean; destroy(): void; /** * Get user property with a potential default value. */ get<T>(name: string, def: T): T; /** * Set user property to value. */ set(name: string, value: any): void; on(event: string, listener: (...args: any[]) => void): this; on(event: NodeEventType, callback: (arg: Node) => void): this; } type NodeScreenEventType = /** * Received when the terminal window focuses/blurs. Requires a terminal supporting the * focus protocol and focus needs to be passed to program.enableMouse(). */ | "focus" /** * Received when the terminal window focuses/blurs. Requires a terminal supporting the * focus protocol and focus needs to be passed to program.enableMouse(). */ | "blur" /** * Element was clicked (slightly smarter than mouseup). */ | "click" | "element click" | "element mouseover" | "element mouseout" | "element mouseup"; type NodeMouseEventType = | "mouse" | "mouseout" | "mouseover" | "mousedown" | "mouseup" | "mousewheel" | "wheeldown" | "wheelup" | "mousemove"; type NodeGenericEventType = /** Received on screen resize. */ | "resize" /** Received before render. */ | "prerender" /** Received on render. */ | "render" /** Received when the screen is destroyed (only useful when using multiple screens). */ | "destroy" /** Received when the element is moved. */ | "move" /** Received when element is shown. */ | "show" /** Received when element becomes hidden. */ | "hide" | "set content" | "parsed content"; class NodeWithEvents extends Node { /** * Bind a keypress listener for a specific key. */ key(name: string | string[], listener: (ch: any, key: Events.IKeyEventArg) => void): void; /** * Bind a keypress listener for a specific key once. */ onceKey(name: string, listener: (ch: any, key: Events.IKeyEventArg) => void): void; /** * Remove a keypress listener for a specific key. */ unkey(name: string, listener: (ch: any, key: Events.IKeyEventArg) => void): void; removeKey(name: string, listener: (ch: any, key: Events.IKeyEventArg) => void): void; on(event: string, listener: (ch: any, key: Events.IKeyEventArg) => void): this; /** Received on mouse events. */ on(event: NodeMouseEventType, callback: (arg: Events.IMouseEventArg) => void): this; /** Received on key events. */ on(event: "keypress", callback: (ch: string, key: Events.IKeyEventArg) => void): this; on(event: NodeScreenEventType, callback: (arg: Screen) => void): this; /** Received when blessed notices something untoward (output is not a tty, terminfo not found, etc). */ on(event: "warning", callback: (text: string) => void): this; on(event: NodeGenericEventType, callback: () => void): this; } interface IScreenOptions extends INodeOptions { /** * The blessed Program to be associated with. Will be automatically instantiated if none is provided. */ program?: BlessedProgram | undefined; /** * Attempt to perform CSR optimization on all possible elements (not just full-width ones, elements with * uniform cells to their sides). This is known to cause flickering with elements that are not full-width, * however, it is more optimal for terminal rendering. */ smartCSR?: boolean | undefined; /** * Do CSR on any element within 20 cols of the screen edge on either side. Faster than smartCSR, * but may cause flickering depending on what is on each side of the element. */ fastCSR?: boolean | undefined; /** * Attempt to perform back_color_erase optimizations for terminals that support it. It will also work * with terminals that don't support it, but only on lines with the default background color. As it * stands with the current implementation, it's uncertain how much terminal performance this adds at * the cost of overhead within node. */ useBCE?: boolean | undefined; /** * Amount of time (in ms) to redraw the screen after the terminal is resized (Default: 300). */ resizeTimeout?: number | undefined; /** * The width of tabs within an element's content. */ tabSize?: number | undefined; /** * Automatically position child elements with border and padding in mind (NOTE: this is a recommended * option. It may become default in the future). */ autoPadding?: boolean | undefined; cursor?: Types.TCursor | undefined; /** * Create a log file. See log method. */ log?: string | undefined; /** * Dump all output and input to desired file. Can be used together with log option if set as a boolean. */ dump?: string | boolean | undefined; /** * Debug mode. Enables usage of the debug method. Also creates a debug console which will display when * pressing F12. It will display all log and debug messages. */ debug?: boolean | undefined; /** * Array of keys in their full format (e.g. C-c) to ignore when keys are locked or grabbed. Useful * for creating a key that will always exit no matter whether the keys are locked. */ ignoreLocked?: string[] | undefined; /** * Automatically "dock" borders with other elements instead of overlapping, depending on position * (experimental). For example: These border-overlapped elements: */ dockBorders?: boolean | undefined; /** * Normally, dockable borders will not dock if the colors or attributes are different. This option * will allow them to dock regardless. It may produce some odd looking multi-colored borders though. */ ignoreDockContrast?: boolean | undefined; /** * Allow for rendering of East Asian double-width characters, utf-16 surrogate pairs, and unicode * combining characters. This allows you to display text above the basic multilingual plane. This * is behind an option because it may affect performance slightly negatively. Without this option * enabled, all double-width, surrogate pair, and combining characters will be replaced by '??', * '?', '' respectively. (NOTE: iTerm2 cannot display combining characters properly. Blessed simply * removes them from an element's content if iTerm2 is detected). */ fullUnicode?: boolean | undefined; /** * Send focus events after mouse is enabled. */ sendFocus?: boolean | undefined; /** * Display warnings (such as the output not being a TTY, similar to ncurses). */ warnings?: boolean | undefined; /** * Force blessed to use unicode even if it is not detected via terminfo, env variables, or windows code page. * If value is true unicode is forced. If value is false non-unicode is forced (default: null). */ forceUnicode?: boolean | undefined; /** * Input and output streams. process.stdin/process.stdout by default, however, it could be a * net.Socket if you want to make a program that runs over telnet or something of that nature. */ input?: Writable | undefined; /** * Input and output streams. process.stdin/process.stdout by default, however, it could be a * net.Socket if you want to make a program that runs over telnet or something of that nature. */ output?: Readable | undefined; /** * The blessed Tput object (only available if you passed tput: true to the Program constructor.) */ tput?: Tput | undefined; /** * Top of the focus history stack. */ focused?: BlessedElement | undefined; /** * Width of the screen (same as program.cols). */ width?: Types.TPosition | undefined; /** * Height of the screen (same as program.rows). */ height?: Types.TPosition | undefined; /** * Same as screen.width. */ cols?: number | undefined; /** * Same as screen.height. */ rows?: number | undefined; /** * Relative top offset, always zero. */ top?: Types.TTopLeft | undefined; /** * Relative left offset, always zero. */ left?: Types.TTopLeft | undefined; /** * Relative right offset, always zero. */ right?: Types.TPosition | undefined; /** * Relative bottom offset, always zero. */ bottom?: Types.TPosition | undefined; /** * Absolute top offset, always zero. */ atop?: Types.TTopLeft | undefined; /** * Absolute left offset, always zero. */ aleft?: Types.TTopLeft | undefined; /** * Absolute right offset, always zero. */ aright?: Types.TPosition | undefined; /** * Absolute bottom offset, always zero. */ abottom?: Types.TPosition | undefined; /** * Whether the focused element grabs all keypresses. */ grabKeys?: boolean | undefined; /** * Prevent keypresses from being received by any element. */ lockKeys?: boolean | undefined; /** * The currently hovered element. Only set if mouse events are bound. */ hover?: any; /** * Set or get terminal name. Set calls screen.setTerminal() internally. */ terminal?: string | undefined; /** * Set or get window title. */ title?: string | undefined; } class Screen extends NodeWithEvents implements IHasOptions<IScreenOptions> { constructor(opts: IScreenOptions); /** * Original options object. */ options: IScreenOptions; /** * The blessed Program to be associated with. Will be automatically instantiated if none is provided. */ program: BlessedProgram; /** * Attempt to perform CSR optimization on all possible elements (not just full-width ones, elements with * uniform cells to their sides). This is known to cause flickering with elements that are not full-width, * however, it is more optimal for terminal rendering. */ smartCSR: boolean; /** * Do CSR on any element within 20 cols of the screen edge on either side. Faster than smartCSR, * but may cause flickering depending on what is on each side of the element. */ fastCSR: boolean; /** * Attempt to perform back_color_erase optimizations for terminals that support it. It will also work * with terminals that don't support it, but only on lines with the default background color. As it * stands with the current implementation, it's uncertain how much terminal performance this adds at * the cost of overhead within node. */ useBCE: boolean; /** * Amount of time (in ms) to redraw the screen after the terminal is resized (Default: 300). */ resizeTimeout: number; /** * The width of tabs within an element's content. */ tabSize: number; /** * Automatically position child elements with border and padding in mind (NOTE: this is a recommended * option. It may become default in the future). */ autoPadding: boolean; cursor: Types.TCursor; /** * Dump all output and input to desired file. Can be used together with log option if set as a boolean. */ dump: string; /** * Array of keys in their full format (e.g. C-c) to ignore when keys are locked or grabbed. Useful * for creating a key that will always exit no matter whether the keys are locked. */ ignoreLocked: boolean; /** * Automatically "dock" borders with other elements instead of overlapping, depending on position * (experimental). For example: These border-overlapped elements: */ dockBorders: boolean; /** * Normally, dockable borders will not dock if the colors or attributes are different. This option * will allow them to dock regardless. It may produce some odd looking multi-colored borders though. */ ignoreDockContrast: boolean; /** * Allow for rendering of East Asian double-width characters, utf-16 surrogate pairs, and unicode * combining characters. This allows you to display text above the basic multilingual plane. This * is behind an option because it may affect performance slightly negatively. Without this option * enabled, all double-width, surrogate pair, and combining characters will be replaced by '??', * '?', '' respectively. (NOTE: iTerm2 cannot display combining characters properly. Blessed simply * removes them from an element's content if iTerm2 is detected). */ fullUnicode: boolean; /** * Send focus events after mouse is enabled. */ sendFocus: boolean; /** * Display warnings (such as the output not being a TTY, similar to ncurses). */ warnings: boolean; /** * Force blessed to use unicode even if it is not detected via terminfo, env variables, or windows code page. * If value is true unicode is forced. If value is false non-unicode is forced (default: null). */ forceUnicode: boolean; /** * Input and output streams. process.stdin/process.stdout by default, however, it could be a * net.Socket if you want to make a program that runs over telnet or something of that nature. */ input: Writable; /** * Input and output streams. process.stdin/process.stdout by default, however, it could be a * net.Socket if you want to make a program that runs over telnet or something of that nature. */ output: Readable; /** * The blessed Tput object (only available if you passed tput: true to the Program constructor.) */ tput: Tput; /** * Top of the focus history stack. */ focused: BlessedElement; /** * Width of the screen (same as program.cols). */ width: Types.TPosition; /** * Height of the screen (same as program.rows). */ height: Types.TPosition; /** * Same as screen.width. */ cols: number; /** * Same as screen.height. */ rows: number; /** * Relative top offset, always zero. */ top: Types.TTopLeft; /** * Relative left offset, always zero. */ left: Types.TTopLeft; /** * Relative right offset, always zero. */ right: Types.TPosition; /** * Relative bottom offset, always zero. */ bottom: Types.TPosition; /** * Absolute top offset, always zero. */ atop: Types.TTopLeft; /** * Absolute left offset, always zero. */ aleft: Types.TTopLeft; /** * Absolute right offset, always zero. */ aright: Types.TPosition; /** * Absolute bottom offset, always zero. */ abottom: Types.TPosition; /** * Whether the focused element grabs all keypresses. */ grabKeys: boolean; /** * Prevent keypresses from being received by any element. */ lockKeys: boolean; /** * The currently hovered element. Only set if mouse events are bound. */ hover: Widgets.BlessedElement; /** * Set or get terminal name. Set calls screen.setTerminal() internally. */ terminal: string; /** * Set or get window title. */ title: string; /** * Array of `Element` instances that may receive click/mouse events. */ clickable: Widgets.BlessedElement[]; /** * Array of `Element` instances that may receive key events. */ keyable: Widgets.BlessedElement[]; /** * Parse the sides of an element to determine whether an element has uniform cells on both sides. * If it does, we can use CSR to optimize scrolling on a scrollable element. */ cleanSides(el: Widgets.BlessedElement): boolean; /** * Write string to the log file if one was created. */ log(...msg: any[]): void; /** * Same as the log method, but only gets called if the debug option was set. */ debug(...msg: string[]): void; /** * Allocate a new pending screen buffer and a new output screen buffer. */ alloc(): void; /** * Reallocate the screen buffers and clear the screen. */ realloc(): void; /** * Draw the screen based on the contents of the screen buffer. */ draw(start: number, end: number): void; /** * Render all child elements, writing all data to the screen buffer and drawing the screen. */ render(): void; /** * Clear any region on the screen. */ clearRegion(x1: number, x2: number, y1: number, y2: number): void; /** * Fill any region with a character of a certain attribute. */ fillRegion(attr: string, ch: string, x1: number, x2: number, y1: number, y2: number): void; /** * Focus element by offset of focusable elements. */ focusOffset(offset: number): void; /** * Focus previous element in the index. */ focusPrevious(): void; /** * Focus next element in the index. */ focusNext(): void; /** * Push element on the focus stack (equivalent to screen.focused = el). */ focusPush(element: BlessedElement): void; /** * Pop element off the focus stack. */ focusPop(): BlessedElement; /** * Save the focused element. */ saveFocus(): BlessedElement; /** * Restore the saved focused element. */ restoreFocus(): BlessedElement; /** * "Rewind" focus to the last visible and attached element. */ rewindFocus(): BlessedElement; /** * Spawn a process in the foreground, return to blessed app after exit. */ spawn(file: string, args?: string[], options?: NodeChildProcessExecOptions): child_process.ChildProcess; /** * Spawn a process in the foreground, return to blessed app after exit. Executes callback on error or exit. */ exec( file: string, args: string[], options: NodeChildProcessExecOptions, callback: (...args: any[]) => void, ): child_process.ChildProcess; /** * Read data from text editor. */ readEditor(options: any, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; readEditor(callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; /** * Set effects based on two events and attributes. */ setEffects(el: BlessedElement, fel: BlessedElement, over: string, out: string, effects: any, temp: any): void; /** * Insert a line into the screen (using csr: this bypasses the output buffer). */ insertLine(n: number, y: number, top: number, bottom: number): void; /** * Delete a line from the screen (using csr: this bypasses the output buffer). */ deleteLine(n: number, y: number, top: number, bottom: number): void; /** * Insert a line at the bottom of the screen. */ insertBottom(top: number, bottom: number): void; /** * Insert a line at the top of the screen. */ insertTop(top: number, bottom: number): void; /** * Delete a line at the bottom of the screen. */ deleteBottom(top: number, bottom: number): void; /** * Delete a line at the top of the screen. */ deleteTop(top: number, bottom: number): void; /** * Enable mouse events for the screen and optionally an element (automatically called when a form of * on('mouse') is bound). */ enableMouse(el?: BlessedElement): void; /** * Enable keypress events for the screen and optionally an element (automatically called when a form of * on('keypress') is bound). */ enableKeys(el?: BlessedElement): void; /** * Enable key and mouse events. Calls bot enableMouse and enableKeys. */ enableInput(el?: BlessedElement): void; /** * Attempt to copy text to clipboard using iTerm2's proprietary sequence. Returns true if successful. */ copyToClipboard(text: string): void; /** * Attempt to change cursor shape. Will not work in all terminals (see artificial cursors for a solution * to this). Returns true if successful. */ cursorShape(shape: boolean, blink: boolean): any; /** * Attempt to change cursor color. Returns true if successful. */ cursorColor(color: string): void; /** * Attempt to reset cursor. Returns true if successful. */ cursorReset(): void; /** * Take an SGR screenshot of the screen within the region. Returns a string containing only * characters and SGR codes. Can be displayed by simply echoing it in a terminal. */ screenshot(xi: number, xl: number, yi: number, yl: number): string; screenshot(): void; /** * Destroy the screen object and remove it from the global list. Also remove all global events relevant * to the screen object. If all screen objects are destroyed, the node process is essentially reset * to its initial state. */ destroy(): void; /** * Reset the terminal to term. Reloads terminfo. */ setTerminal(term: string): void; } interface Padding { left?: number | undefined; right?: number | undefined; top?: number | undefined; bottom?: number | undefined; } class PositionCoords { xi: number; xl: number; yi: number; yl: number; } interface Position { left: number | string; right: number | string; top: number | string; bottom: number | string; } interface Border { /** * Type of border (line or bg). bg by default. */ type?: "line" | "bg" | undefined; /** * Character to use if bg type, default is space. */ ch?: string | undefined; /** * Border foreground and background, must be numbers (-1 for default). */ bg?: number | undefined; fg?: number | undefined; /** * Border attributes. */ bold?: string | undefined; underline?: string | undefined; } interface ElementOptions extends INodeOptions { tags?: boolean | undefined; fg?: string | undefined; bg?: string | undefined; bold?: string | undefined; underline?: string | undefined; style?: any; /** * Border object, see below. */ border?: Border | "line" | "bg" | undefined; /** * Element's text content. */ content?: string | undefined; /** * Element is clickable. */ clickable?: boolean | undefined; /** * Element is focusable and can receive key input. */ input?: boolean | undefined; keyable?: boolean | undefined; /** * Element is focused. */ focused?: BlessedElement | undefined; /** * Whether the element is hidden. */ hidden?: boolean | undefined; /** * A simple text label for the element. */ label?: string | undefined; /** * A floating text label for the element which appears on mouseover. */ hoverText?: string | undefined; /** * Text alignment: left, center, or right. */ align?: "left" | "center" | "right" | undefined; /** * Vertical text alignment: top, middle, or bottom. */ valign?: "top" | "middle" | "bottom" | undefined; /** * Shrink/flex/grow to content and child elements. Width/height during render. */ shrink?: boolean | undefined; /** * Amount of padding on the inside of the element. Can be a number or an object containing * the properties: left, right, top, and bottom. */ padding?: number | Padding | undefined; top?: Types.TTopLeft | undefined; left?: Types.TTopLeft | undefined; right?: Types.TPosition | undefined; bottom?: Types.TPosition | undefined; /** * Width/height of the element, can be a number, percentage (0-100%), or keyword (half or shrink). * Percentages can also have offsets (50%+1, 50%-1). */ width?: number | string | undefined; /** * Offsets of the element relative to its parent. Can be a number, percentage (0-100%), or * keyword (center). right and bottom do not accept keywords. Percentages can also have * offsets (50%+1, 50%-1). */ height?: number | string | undefined; /** * Can contain the above options. */ position?: Position | undefined; /** * Whether the element is scrollable or not. */ scrollable?: boolean | undefined; /** * Background character (default is whitespace ). */ ch?: string | undefined; /** * Allow the element to be dragged with the mouse. */ draggable?: boolean | undefined; /** * Draw a translucent offset shadow behind the element. */ shadow?: boolean | undefined; } interface Coords { xl: number; xi: number; yl: number; yi: number; base: number; _contentEnd: { x: number; y: number }; notop: Types.TTopLeft; noleft: Types.TTopLeft; noright: Types.TPosition; nobot: Types.TPosition; } interface LabelOptions { text: string; side: Types.TAlign; } // TODO: scrollable - Note: If the scrollable option is enabled, Element inherits all methods from ScrollableBox. abstract class BlessedElement extends NodeWithEvents implements IHasOptions<ElementOptions> { constructor(opts: ElementOptions); /** * Original options object. */ options: ElementOptions; /** * Name of the element. Useful for form submission. */ name: string; /** * Border object. */ border: Border; style: any; position: Position; content: string; hidden: boolean; visible: boolean; detached: boolean; /** * Border foreground and background, must be numbers (-1 for default). */ bg: number; fg: number; /** * Border attributes. */ bold: string; underline: string; /** * Calculated width. */ width: number | string; /**