UNPKG

100 kBTypeScriptView Raw
1// Type definitions for blessed 0.1
2// Project: https://github.com/chjj/blessed
3// Definitions by: Bryn Austin Bellomy <https://github.com/brynbellomy>
4// Steve Kellock <https://github.com/skellock>
5// Max Brauer <https://github.com/mamachanko>
6// Nathan Rajlich <https://github.com/TooTallNate>
7// Daniel Berlanga <https://github.com/danikaze>
8// Jeff Huijsmans <https://github.com/jeffhuys>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10// TypeScript Version: 2.1
11
12/// <reference types="node" />
13
14import { EventEmitter } from "events";
15import { Writable, Readable } from "stream";
16import * as child_process from "child_process";
17
18export interface IBlessedProgramOptions {
19 input?: Readable | undefined;
20 output?: Writable | undefined;
21 log?: string | undefined;
22 dump?: boolean | undefined;
23 zero?: boolean | undefined;
24 buffer?: boolean | undefined;
25 terminal?: string | undefined;
26 term?: string | undefined;
27 tput?: string | undefined;
28 debug?: boolean | undefined;
29 resizeTimeout?: boolean | undefined;
30}
31
32export class BlessedProgram extends EventEmitter {
33 type: string;
34 options: IBlessedProgramOptions;
35 input: Readable;
36 output: Writable;
37 zero: boolean;
38 useBuffer: boolean;
39 x: number;
40 y: number;
41 savedX: number;
42 savedY: number;
43 cols: number;
44 rows: number;
45 scrollTop: number;
46 scrollBottom: number;
47 isOSXTerm: boolean;
48 isiTerm2: boolean;
49 isXFCE: boolean;
50 isTerminator: boolean;
51 isLXDE: boolean;
52 isVTE: boolean;
53 isRxvt: boolean;
54 isXterm: boolean;
55 tmux: boolean;
56 tmuxVersion: number;
57
58 constructor(options?: IBlessedProgramOptions);
59
60 log(): boolean;
61 debug(): boolean;
62 setupDump(): void;
63 setupTput(): void;
64 setTerminal(terminal: string): void;
65 has(name: string): boolean;
66 term(is: string): boolean;
67
68 listen(): void;
69 destroy(): void;
70
71 key(key: string|string[], listener: Function): void;
72 onceKey(key: string|string[], listener: Function): void;
73
74 unKey(key: string|string[], listener: Function): void;
75 removeKey(key: string|string[], listener: Function): void;
76
77 bindMouse(): void;
78 enableGpm(): void;
79 disableGpm(): void;
80 bindResponse(): void;
81
82 response(name: string, text: string, callback: Function, noBypass?: boolean): boolean;
83 response(name: string, callback?: Function): boolean;
84
85 write(text: string): boolean;
86 flush(): void;
87 print(text: string, attr?: boolean): boolean;
88 echo(text: string, attr?: boolean): boolean;
89
90 setx(x: number): boolean;
91 sety(y: number): boolean;
92 move(x: number, y: number): boolean;
93 omove(x: number, y: number): void;
94 rsetx(x: number): boolean;
95 rsety(y: number): boolean;
96 rmove(x: number, y: number): void;
97
98 simpleInsert(ch: string, i?: number, attr?: boolean): boolean;
99 repeat(ch: string, i?: number): string;
100 copyToClipboard(text: string): boolean;
101
102 cursorShape(shape: string, blink?: boolean): boolean;
103 cursorColor(color: string): boolean;
104 cursorReset(): boolean;
105 resetCursor(): boolean;
106
107 getTextParams(param: string, callback: Function): boolean;
108 getCursorColor(callback: Function): boolean;
109
110 nul(): boolean;
111
112 bell(): boolean;
113 bel(): boolean;
114
115 vtab(): boolean;
116
117 form(): boolean;
118 ff(): boolean;
119
120 backspace(): boolean;
121 kbs(): boolean;
122
123 tab(): boolean;
124 ht(): boolean;
125
126 shiftOut(): boolean;
127 shiftIn(): boolean;
128
129 return(): boolean;
130 cr(): boolean;
131
132 feed(): boolean;
133 newline(): boolean;
134 nl(): boolean;
135
136 index(): boolean;
137 ind(): boolean;
138
139 reverseIndex(): boolean;
140 reverse(): boolean;
141 ri(): boolean;
142
143 nextLine(): boolean;
144 reset(): boolean;
145 tabSet(): boolean;
146
147 saveCursor(key: string): boolean;
148 sc(key: string): boolean;
149
150 restoreCursor(key?: string, hide?: boolean): boolean;
151 rc(key?: string, hide?: boolean): boolean;
152
153 lsaveCursor(key?: string): void;
154 lrestoreCursor(key?: string, hide?: boolean): void;
155
156 lineHeight(): boolean;
157
158 charset(val?: string, level?: number): boolean;
159
160 enter_alt_charset_mode(): boolean;
161 as(): boolean;
162 smacs(): boolean;
163
164 exit_alt_charset_mode(): boolean;
165 ae(): boolean;
166 rmacs(): boolean;
167
168 setG(val: number): boolean;
169
170 setTitle(title: string): boolean;
171
172 resetColors(param?: string): boolean;
173
174 dynamicColors(param?: string): boolean;
175
176 selData(a: string, b: string): boolean;
177
178 cursorUp(param?: number): boolean;
179 cuu(param?: number): boolean;
180 up(param?: number): boolean;
181
182 cursorDown(param?: number): boolean;
183 cud(param?: number): boolean;
184 down(param?: number): boolean;
185
186 cursorForward(param?: number): boolean;
187 cuf(param?: number): boolean;
188 right(param?: number): boolean;
189 forward(param?: number): boolean;
190
191 cursorBackward(param?: number): boolean;
192 cub(param?: number): boolean;
193 left(param?: number): boolean;
194 back(param?: number): boolean;
195
196 cursorPos(row?: number, col?: number): boolean;
197 cup(row?: number, col?: number): boolean;
198 pos(row?: number, col?: number): boolean;
199
200 eraseInDisplay(param?: string): boolean;
201 ed(param?: string): boolean;
202
203 clear(): boolean;
204
205 eraseInLine(param?: string): boolean;
206 el(param?: string): boolean;
207
208 charAttributes(param: string, val?: boolean): boolean;
209 charAttributes(param: string[], val?: boolean): boolean;
210
211 setForeground(color: string, val?: boolean): boolean;
212 fg(color: string, val?: boolean): boolean;
213
214 setBackground(color: string, val?: boolean): boolean;
215 bg(color: string, val?: boolean): boolean;
216
217 deviceStatuses(param?: string, callback?: Function, dec?: boolean, noBypass?: boolean): boolean;
218 dsr(param?: string, callback?: Function, dec?: boolean, noBypass?: boolean): boolean;
219
220 getCursor(callback: Function): boolean;
221 saveReportedCursor(callback: Function): void;
222
223 restoreReportedCursor: () => boolean;
224
225 insertChars(param?: number): boolean;
226 ich(param?: number): boolean;
227
228 cursorNextLine(param?: number): boolean;
229 cnl(param?: number): boolean;
230
231 cursorPrecedingLine(param?: number): boolean;
232 cpl(param?: number): boolean;
233
234 cursorCharAbsolute(param?: number): boolean;
235 cha(param?: number): boolean;
236
237 insertLines(param?: number): boolean;
238 il(param?: number): boolean;
239
240 deleteLines(param?: number): boolean;
241 dl(param?: number): boolean;
242
243 deleteChars(param?: number): boolean;
244 dch(param?: number): boolean;
245
246 eraseChars(param?: number): boolean;
247 ech(param?: number): boolean;
248
249 charPosAbsolute(param?: number): boolean;
250 hpa(param?: number): boolean;
251
252 HPositionRelative(param?: number): boolean;
253
254 sendDeviceAttributes(param?: number, callback?: Function): boolean;
255 da(param?: number, callback?: Function): boolean;
256
257 linePosAbsolute(param?: number): boolean;
258 vpa(param?: number): boolean;
259
260 VPositionRelative(param?: number): boolean;
261 vpr(param?: number): boolean;
262
263 HVPosition(row?: number, col?: number): boolean;
264 hvp(row?: number, col?: number): boolean;
265
266 setMode(...args: string[]): boolean;
267 sm(...args: string[]): boolean;
268
269 decset(...args: string[]): boolean;
270
271 showCursor(): boolean;
272
273 alternateBuffer(): boolean;
274 smcup(): boolean;
275 alternate(): boolean;
276
277 resetMode(...args: string[]): boolean;
278 rm(...args: string[]): boolean;
279
280 decrst(...args: string[]): boolean;
281
282 hideCursor(): boolean;
283 civis(): boolean;
284 vi(): boolean;
285 cursor_invisible(): boolean;
286 dectcemh(): boolean;
287
288 normalBuffer(): boolean;
289 rmcup(): boolean;
290
291 enableMouse(): void;
292 disableMouse(): void;
293
294 setMouse(opt?: {}, enable?: boolean): void;
295
296 setScrollRegion(top: number, bottom: number): boolean;
297 csr(top: number, bottom: number): boolean;
298 decstbm(top: number, bottom: number): boolean;
299
300 saveCursorA(): boolean;
301 scA(): boolean;
302
303 restoreCursorA(): boolean;
304 rcA(): boolean;
305
306 cursorForwardTab(param?: number): boolean;
307 cht(param?: number): boolean;
308
309 scrollUp(param?: number): boolean;
310 su(param?: number): boolean;
311
312 scrollDown(param?: number): boolean;
313 sd(param?: number): boolean;
314
315 initMouseTracking(...args: string[]): boolean;
316
317 resetTitleModes(...args: string[]): boolean;
318
319 cursorBackwardTab(param?: number): boolean;
320 cbt(param?: number): boolean;
321
322 repeatPrecedingCharacter(param?: number): boolean;
323 rep(param?: number): boolean;
324
325 tabClear(param?: number): boolean;
326 tbc(param?: number): boolean;
327
328 mediaCopy(...args: string[]): boolean;
329 mc(...args: string[]): boolean;
330
331 mc0(): boolean;
332 print_screen(): boolean;
333 ps(): boolean;
334
335 mc5(): boolean;
336 prtr_on(): boolean;
337 po(): boolean;
338
339 mc4(): boolean;
340 prtr_off(): boolean;
341 pf(): boolean;
342
343 mc5p(): boolean;
344 prtr_non(): boolean;
345 p0(): boolean;
346
347 setResources(...args: string[]): boolean;
348
349 disableModifieres(...args: string[]): boolean;
350
351 setPointerMode(...args: string[]): boolean;
352
353 softReset(): boolean;
354 rs2(): boolean;
355 decstr(): boolean;
356
357 requestAnsiMode(param?: number): boolean;
358 decrqm(param?: number): boolean;
359
360 requestPrivateMode(param?: number): boolean;
361 decrqmp(param?: number): boolean;
362
363 setConformanceLevel(...args: string[]): boolean;
364 decscl(...args: string[]): boolean;
365
366 loadLEDs(param?: number): boolean;
367 decll(param?: number): boolean;
368
369 setCursorStyle(param?: string): boolean;
370 decscursr(param?: string): boolean;
371
372 setCharProtectionAttr(param?: number): boolean;
373 decsca(param?: number): boolean;
374
375 restorePrivateValues(...args: string[]): boolean;
376
377 setAttrInRectangle(...args: string[]): boolean;
378 deccara(...args: string[]): boolean;
379
380 savePrivateValues(...args: string[]): boolean;
381
382 manipulateWindow(...args: any[]): boolean;
383
384 getWindowSize(callback?: Function): boolean;
385
386 reverseAttrInRectangle(...args: string[]): boolean;
387 decrara(...args: string[]): boolean;
388
389 setTitleModeFeature(...args: string[]): boolean;
390
391 setWarningBellVolume(param?: number): boolean;
392 decswbv(param?: number): boolean;
393
394 setMarginBellVolume(param?: number): boolean;
395
396 copyRectangle(...args: string[]): boolean;
397 deccra(...args: string[]): boolean;
398
399 enableFilterRectangle(...args: string[]): boolean;
400 decefr(...args: string[]): boolean;
401
402 requestParameters(param?: number): boolean;
403 decreqtparm(param: number): boolean;
404
405 selectChangeExtent(param?: number): boolean;
406 decsace(param?: number): boolean;
407
408 fillRectangle(...args: string[]): boolean;
409 decfra(...args: string[]): boolean;
410
411 enableLocatorReporting(...args: string[]): boolean;
412 decelr(...args: string[]): boolean;
413
414 eraseRectangle(...args: string[]): boolean;
415 decera(...args: string[]): boolean;
416
417 setLocatorEvents(...args: string[]): boolean;
418 decsle(...args: string[]): boolean;
419
420 selectiveEraseRectangle(...args: string[]): boolean;
421 decsera(...args: string[]): boolean;
422
423 requestLocatorPosition(param?: string, callback?: Function): boolean;
424 reqmp(param?: string, callback?: Function): boolean;
425 req_mouse_pos(param?: string, callback?: Function): boolean;
426 decrqlp(param?: string, callback?: Function): boolean;
427
428 insertColumns(...args: string[]): boolean;
429 decic(...args: string[]): boolean;
430
431 deleteColumns(...args: string[]): boolean;
432 decdc(...args: string[]): boolean;
433
434 out(param: string, ...args: any[]): boolean;
435
436 sigtstp(callback?: Function): boolean;
437
438 pause(callback?: Function): Function;
439
440 resume: () => void;
441}
442
443export namespace Widgets {
444 namespace Types {
445 type TTopLeft = string | number | "center";
446
447 type TPosition = string | number;
448
449 type TMouseAction = "mousedown" | "mouseup" | "mousemove";
450
451 interface TStyle {
452 type?: string | undefined;
453 bg?: string | undefined;
454 fg?: string | undefined;
455 ch?: string | undefined;
456 bold?: boolean | undefined;
457 underline?: boolean | undefined;
458 blink?: boolean | undefined;
459 inverse?: boolean | undefined;
460 invisible?: boolean | undefined;
461 transparent?: boolean | undefined;
462 border?: "line" | "bg" | TBorder | undefined;
463 hover?: boolean | undefined;
464 focus?: boolean | undefined;
465 label?: string | undefined;
466 track?: { bg?: string | undefined; fg?: string | undefined } | undefined;
467 scrollbar?: { bg?: string | undefined; fg?: string | undefined } | undefined;
468 }
469
470 interface TBorder {
471 /**
472 * Type of border (line or bg). bg by default.
473 */
474 type?: "line" | "bg" | undefined;
475
476 /**
477 * Character to use if bg type, default is space.
478 */
479 ch?: string | undefined;
480
481 /**
482 * Border foreground and background, must be numbers (-1 for default).
483 */
484 bg?: number | undefined;
485 fg?: number | undefined;
486
487 /**
488 * Border attributes.
489 */
490 bold?: string | undefined;
491 underline?: string | undefined;
492 }
493
494 interface TCursor {
495 /**
496 * Have blessed draw a custom cursor and hide the terminal cursor (experimental).
497 */
498 artificial: boolean;
499
500 /**
501 * Shape of the cursor. Can be: block, underline, or line.
502 */
503 shape: "block" | "underline" | "line";
504
505 /**
506 * Whether the cursor blinks.
507 */
508 blink: boolean;
509
510 /**
511 * Color of the color. Accepts any valid color value (null is default).
512 */
513 color: string;
514 }
515
516 type TAlign = "left" | "center" | "right";
517
518 interface ListbarCommand {
519 key: string;
520 callback(): void;
521 }
522
523 interface TImage {
524 /**
525 * Pixel width.
526 */
527 width: number;
528
529 /**
530 * Pixel height.
531 */
532 height: number;
533
534 /**
535 * Image bitmap.
536 */
537 bmp: any;
538
539 /**
540 * Image cellmap (bitmap scaled down to cell size).
541 */
542 cellmap: any;
543 }
544
545 interface Cursor {
546 /**
547 * Have blessed draw a custom cursor and hide the terminal cursor (experimental).
548 */
549 artificial: boolean;
550
551 /**
552 * Shape of the cursor. Can be: block, underline, or line.
553 */
554 shape: boolean;
555
556 /**
557 * Whether the cursor blinks.
558 */
559 blink: boolean;
560
561 /**
562 * Color of the color. Accepts any valid color value (null is default).
563 */
564 color: string;
565 }
566 }
567
568 namespace Events {
569 interface IMouseEventArg {
570 x: number;
571 y: number;
572 action: Types.TMouseAction;
573 }
574
575 interface IKeyEventArg {
576 full: string;
577 name: string;
578 shift: boolean;
579 ctrl: boolean;
580 meta: boolean;
581 sequence: string;
582 }
583 }
584
585 interface NodeChildProcessExecOptions {
586 cwd?: string | undefined;
587 stdio?: any;
588 customFds?: any;
589 env?: any;
590 encoding?: string | undefined;
591 timeout?: number | undefined;
592 maxBuffer?: number | undefined;
593 killSignal?: string | undefined;
594 }
595
596 interface IDestroyable {
597 destroy(): void;
598 }
599
600 interface IOptions {
601 [name: string]: any;
602 }
603
604 interface IHasOptions<T extends IOptions> {
605 options: T;
606 }
607
608 interface TputsOptions extends IOptions {
609 terminal?: string | undefined;
610 extended?: boolean | undefined;
611 debug?: boolean | undefined;
612 termcap?: string | undefined;
613 terminfoFile?: string | undefined;
614 terminfoPrefix?: string | undefined;
615 termcapFile?: string | undefined;
616 }
617
618 class Tput implements IHasOptions<TputsOptions> {
619 constructor(opts: TputsOptions);
620
621 /**
622 * Original options object.
623 */
624 options: TputsOptions;
625
626 debug: boolean;
627 padding: boolean;
628 extended: boolean;
629 printf: boolean;
630 termcap: string;
631 terminfoPrefix: string;
632 terminfoFile: string;
633 termcapFile: string;
634 error: Error;
635 terminal: string;
636
637 setup(): void;
638 term(is: any): boolean;
639 readTerminfo(term: string): string;
640 parseTerminfo(
641 data: any,
642 file: string
643 ): {
644 header: {
645 dataSize: number;
646 headerSize: number;
647 magicNumber: boolean;
648 namesSize: number;
649 boolCount: number;
650 numCount: number;
651 strCount: number;
652 strTableSize: number;
653 extended: {
654 dataSize: number;
655 headerSize: number;
656 boolCount: number;
657 numCount: number;
658 strCount: number;
659 strTableSize: number;
660 lastStrTableOffset: number;
661 };
662 };
663 name: string;
664 names: string[];
665 desc: string;
666 bools: any;
667 numbers: any;
668 strings: any;
669 };
670 }
671
672 interface IDestroyable {
673 destroy(): void;
674 }
675
676 interface INodeOptions extends IOptions {
677 name?: string | undefined;
678 screen?: Screen | undefined;
679 parent?: Node | undefined;
680 children?: Node[] | undefined;
681 focusable?: boolean | undefined;
682 }
683
684 type NodeEventType =
685 /** Received when node is added to a parent. */
686 | "adopt"
687 /** Received when node is removed from it's current parent. */
688 | "remove"
689 /** Received when node gains a new parent. */
690 | "reparent"
691 /** Received when node is attached to the screen directly or somewhere in its ancestry. */
692 | "attach"
693 /** Received when node is detached from the screen directly or somewhere in its ancestry. */
694 | "detach";
695
696 abstract class Node extends EventEmitter implements IHasOptions<INodeOptions>, IDestroyable {
697 constructor(options: INodeOptions);
698
699 focusable: boolean;
700
701 /**
702 * Original options object.
703 */
704 options: INodeOptions;
705
706 /**
707 * An object for any miscellanous user data.
708 */
709 data: { [index: string]: any };
710
711 /**
712 * An object for any miscellanous user data.
713 */
714 _: { [index: string]: any };
715
716 /**
717 * An object for any miscellanous user data.
718 */
719 $: { [index: string]: any };
720
721 /**
722 * Type of the node (e.g. box).
723 */
724 type: string;
725
726 /**
727 * Render index (document order index) of the last render call.
728 */
729 index: number;
730
731 /**
732 * Parent screen.
733 */
734 screen: Screen;
735
736 /**
737 * Parent node.
738 */
739 parent: Node;
740
741 /**
742 * Array of node's children.
743 */
744 children: Node[];
745
746 /**
747 * Prepend a node to this node's children.
748 */
749 prepend(node: Node): void;
750
751 /**
752 * Append a node to this node's children.
753 */
754 append(node: Node): void;
755
756 /**
757 * Remove child node from node.
758 */
759 remove(node: Node): void;
760
761 /**
762 * Insert a node to this node's children at index i.
763 */
764 insert(node: Node, index: number): void;
765
766 /**
767 * Insert a node to this node's children before the reference node.
768 */
769 insertBefore(node: Node, refNode: Node): void;
770
771 /**
772 * Insert a node from node after the reference node.
773 */
774 insertAfter(node: Node, refNode: Node): void;
775
776 /**
777 * Remove node from its parent.
778 */
779 detach(): void;
780 free(): void;
781 forDescendants(iter: (node: Node) => void, s: any): void;
782 forAncestors(iter: (node: Node) => void, s: any): void;
783 collectDescendants(s: any): void;
784 collectAncestors(s: any): void;
785
786 /**
787 * Emit event for element, and recursively emit same event for all descendants.
788 */
789 emitDescendants(type?: string, ...args: any[]): void;
790 emitAncestors(): void;
791 hasDescendant(target: Node): void;
792 hasAncestor(target: Node): boolean;
793 destroy(): void;
794
795 /**
796 * Get user property with a potential default value.
797 */
798 get<T>(name: string, def: T): T;
799
800 /**
801 * Set user property to value.
802 */
803 set(name: string, value: any): void;
804
805 on(event: string, listener: (...args: any[]) => void): this;
806 on(event: NodeEventType, callback: (arg: Node) => void): this;
807 }
808
809 type NodeScreenEventType =
810 /**
811 * Received when the terminal window focuses/blurs. Requires a terminal supporting the
812 * focus protocol and focus needs to be passed to program.enableMouse().
813 */
814 | "focus"
815 /**
816 * Received when the terminal window focuses/blurs. Requires a terminal supporting the
817 * focus protocol and focus needs to be passed to program.enableMouse().
818 */
819 | "blur"
820 /**
821 * Element was clicked (slightly smarter than mouseup).
822 */
823 | "click"
824 | "element click"
825 | "element mouseover"
826 | "element mouseout"
827 | "element mouseup";
828
829 type NodeMouseEventType =
830 | "mouse"
831 | "mouseout"
832 | "mouseover"
833 | "mousedown"
834 | "mouseup"
835 | "mousewheel"
836 | "wheeldown"
837 | "wheelup"
838 | "mousemove";
839
840 type NodeGenericEventType =
841 /** Received on screen resize. */
842 | "resize"
843 /** Received before render. */
844 | "prerender"
845 /** Received on render. */
846 | "render"
847 /** Received when the screen is destroyed (only useful when using multiple screens). */
848 | "destroy"
849 /** Received when the element is moved. */
850 | "move"
851 /** Received when element is shown. */
852 | "show"
853 /** Received when element becomes hidden. */
854 | "hide"
855 | "set content"
856 | "parsed content";
857
858 class NodeWithEvents extends Node {
859 /**
860 * Bind a keypress listener for a specific key.
861 */
862 key(name: string | string[], listener: (ch: any, key: Events.IKeyEventArg) => void): void;
863
864 /**
865 * Bind a keypress listener for a specific key once.
866 */
867 onceKey(name: string, listener: (ch: any, key: Events.IKeyEventArg) => void): void;
868
869 /**
870 * Remove a keypress listener for a specific key.
871 */
872 unkey(name: string, listener: (ch: any, key: Events.IKeyEventArg) => void): void;
873 removeKey(name: string, listener: (ch: any, key: Events.IKeyEventArg) => void): void;
874
875 on(event: string, listener: (ch: any, key: Events.IKeyEventArg) => void): this;
876 /** Received on mouse events. */
877 on(event: NodeMouseEventType, callback: (arg: Events.IMouseEventArg) => void): this;
878 /** Received on key events. */
879 on(event: "keypress", callback: (ch: string, key: Events.IKeyEventArg) => void): this;
880 on(event: NodeScreenEventType, callback: (arg: Screen) => void): this;
881 /** Received when blessed notices something untoward (output is not a tty, terminfo not found, etc). */
882 on(event: "warning", callback: (text: string) => void): this;
883 on(event: NodeGenericEventType, callback: () => void): this;
884 }
885
886 interface IScreenOptions extends INodeOptions {
887 /**
888 * The blessed Program to be associated with. Will be automatically instantiated if none is provided.
889 */
890 program?: BlessedProgram | undefined;
891
892 /**
893 * Attempt to perform CSR optimization on all possible elements (not just full-width ones, elements with
894 * uniform cells to their sides). This is known to cause flickering with elements that are not full-width,
895 * however, it is more optimal for terminal rendering.
896 */
897 smartCSR?: boolean | undefined;
898
899 /**
900 * Do CSR on any element within 20 cols of the screen edge on either side. Faster than smartCSR,
901 * but may cause flickering depending on what is on each side of the element.
902 */
903 fastCSR?: boolean | undefined;
904
905 /**
906 * Attempt to perform back_color_erase optimizations for terminals that support it. It will also work
907 * with terminals that don't support it, but only on lines with the default background color. As it
908 * stands with the current implementation, it's uncertain how much terminal performance this adds at
909 * the cost of overhead within node.
910 */
911 useBCE?: boolean | undefined;
912
913 /**
914 * Amount of time (in ms) to redraw the screen after the terminal is resized (Default: 300).
915 */
916 resizeTimeout?: number | undefined;
917
918 /**
919 * The width of tabs within an element's content.
920 */
921 tabSize?: number | undefined;
922
923 /**
924 * Automatically position child elements with border and padding in mind (NOTE: this is a recommended
925 * option. It may become default in the future).
926 */
927 autoPadding?: boolean | undefined;
928
929 cursor?: Types.TCursor | undefined;
930
931 /**
932 * Create a log file. See log method.
933 */
934 log?: string | undefined;
935
936 /**
937 * Dump all output and input to desired file. Can be used together with log option if set as a boolean.
938 */
939 dump?: string | boolean | undefined;
940
941 /**
942 * Debug mode. Enables usage of the debug method. Also creates a debug console which will display when
943 * pressing F12. It will display all log and debug messages.
944 */
945 debug?: boolean | undefined;
946
947 /**
948 * Array of keys in their full format (e.g. C-c) to ignore when keys are locked or grabbed. Useful
949 * for creating a key that will always exit no matter whether the keys are locked.
950 */
951 ignoreLocked?: string[] | undefined;
952
953 /**
954 * Automatically "dock" borders with other elements instead of overlapping, depending on position
955 * (experimental). For example: These border-overlapped elements:
956 */
957 dockBorders?: boolean | undefined;
958
959 /**
960 * Normally, dockable borders will not dock if the colors or attributes are different. This option
961 * will allow them to dock regardless. It may produce some odd looking multi-colored borders though.
962 */
963 ignoreDockContrast?: boolean | undefined;
964
965 /**
966 * Allow for rendering of East Asian double-width characters, utf-16 surrogate pairs, and unicode
967 * combining characters. This allows you to display text above the basic multilingual plane. This
968 * is behind an option because it may affect performance slightly negatively. Without this option
969 * enabled, all double-width, surrogate pair, and combining characters will be replaced by '??',
970 * '?', '' respectively. (NOTE: iTerm2 cannot display combining characters properly. Blessed simply
971 * removes them from an element's content if iTerm2 is detected).
972 */
973 fullUnicode?: boolean | undefined;
974
975 /**
976 * Send focus events after mouse is enabled.
977 */
978 sendFocus?: boolean | undefined;
979
980 /**
981 * Display warnings (such as the output not being a TTY, similar to ncurses).
982 */
983 warnings?: boolean | undefined;
984
985 /**
986 * Force blessed to use unicode even if it is not detected via terminfo, env variables, or windows code page.
987 * If value is true unicode is forced. If value is false non-unicode is forced (default: null).
988 */
989 forceUnicode?: boolean | undefined;
990
991 /**
992 * Input and output streams. process.stdin/process.stdout by default, however, it could be a
993 * net.Socket if you want to make a program that runs over telnet or something of that nature.
994 */
995 input?: Writable | undefined;
996
997 /**
998 * Input and output streams. process.stdin/process.stdout by default, however, it could be a
999 * net.Socket if you want to make a program that runs over telnet or something of that nature.
1000 */
1001 output?: Readable | undefined;
1002
1003 /**
1004 * The blessed Tput object (only available if you passed tput: true to the Program constructor.)
1005 */
1006 tput?: Tput | undefined;
1007
1008 /**
1009 * Top of the focus history stack.
1010 */
1011 focused?: BlessedElement | undefined;
1012
1013 /**
1014 * Width of the screen (same as program.cols).
1015 */
1016 width?: Types.TPosition | undefined;
1017
1018 /**
1019 * Height of the screen (same as program.rows).
1020 */
1021 height?: Types.TPosition | undefined;
1022
1023 /**
1024 * Same as screen.width.
1025 */
1026 cols?: number | undefined;
1027
1028 /**
1029 * Same as screen.height.
1030 */
1031 rows?: number | undefined;
1032
1033 /**
1034 * Relative top offset, always zero.
1035 */
1036 top?: Types.TTopLeft | undefined;
1037
1038 /**
1039 * Relative left offset, always zero.
1040 */
1041 left?: Types.TTopLeft | undefined;
1042
1043 /**
1044 * Relative right offset, always zero.
1045 */
1046 right?: Types.TPosition | undefined;
1047
1048 /**
1049 * Relative bottom offset, always zero.
1050 */
1051 bottom?: Types.TPosition | undefined;
1052
1053 /**
1054 * Absolute top offset, always zero.
1055 */
1056 atop?: Types.TTopLeft | undefined;
1057
1058 /**
1059 * Absolute left offset, always zero.
1060 */
1061 aleft?: Types.TTopLeft | undefined;
1062
1063 /**
1064 * Absolute right offset, always zero.
1065 */
1066 aright?: Types.TPosition | undefined;
1067
1068 /**
1069 * Absolute bottom offset, always zero.
1070 */
1071 abottom?: Types.TPosition | undefined;
1072
1073 /**
1074 * Whether the focused element grabs all keypresses.
1075 */
1076 grabKeys?: boolean | undefined;
1077
1078 /**
1079 * Prevent keypresses from being received by any element.
1080 */
1081 lockKeys?: boolean | undefined;
1082
1083 /**
1084 * The currently hovered element. Only set if mouse events are bound.
1085 */
1086 hover?: any;
1087
1088 /**
1089 * Set or get terminal name. Set calls screen.setTerminal() internally.
1090 */
1091 terminal?: string | undefined;
1092
1093 /**
1094 * Set or get window title.
1095 */
1096 title?: string | undefined;
1097 }
1098
1099 class Screen extends NodeWithEvents implements IHasOptions<IScreenOptions> {
1100 constructor(opts: IScreenOptions);
1101
1102 /**
1103 * Original options object.
1104 */
1105 options: IScreenOptions;
1106
1107 /**
1108 * The blessed Program to be associated with. Will be automatically instantiated if none is provided.
1109 */
1110 program: BlessedProgram;
1111
1112 /**
1113 * Attempt to perform CSR optimization on all possible elements (not just full-width ones, elements with
1114 * uniform cells to their sides). This is known to cause flickering with elements that are not full-width,
1115 * however, it is more optimal for terminal rendering.
1116 */
1117 smartCSR: boolean;
1118
1119 /**
1120 * Do CSR on any element within 20 cols of the screen edge on either side. Faster than smartCSR,
1121 * but may cause flickering depending on what is on each side of the element.
1122 */
1123 fastCSR: boolean;
1124
1125 /**
1126 * Attempt to perform back_color_erase optimizations for terminals that support it. It will also work
1127 * with terminals that don't support it, but only on lines with the default background color. As it
1128 * stands with the current implementation, it's uncertain how much terminal performance this adds at
1129 * the cost of overhead within node.
1130 */
1131 useBCE: boolean;
1132
1133 /**
1134 * Amount of time (in ms) to redraw the screen after the terminal is resized (Default: 300).
1135 */
1136 resizeTimeout: number;
1137
1138 /**
1139 * The width of tabs within an element's content.
1140 */
1141 tabSize: number;
1142
1143 /**
1144 * Automatically position child elements with border and padding in mind (NOTE: this is a recommended
1145 * option. It may become default in the future).
1146 */
1147 autoPadding: boolean;
1148
1149 cursor: Types.TCursor;
1150
1151 /**
1152 * Dump all output and input to desired file. Can be used together with log option if set as a boolean.
1153 */
1154 dump: string;
1155
1156 /**
1157 * Array of keys in their full format (e.g. C-c) to ignore when keys are locked or grabbed. Useful
1158 * for creating a key that will always exit no matter whether the keys are locked.
1159 */
1160 ignoreLocked: boolean;
1161
1162 /**
1163 * Automatically "dock" borders with other elements instead of overlapping, depending on position
1164 * (experimental). For example: These border-overlapped elements:
1165 */
1166 dockBorders: boolean;
1167
1168 /**
1169 * Normally, dockable borders will not dock if the colors or attributes are different. This option
1170 * will allow them to dock regardless. It may produce some odd looking multi-colored borders though.
1171 */
1172 ignoreDockContrast: boolean;
1173
1174 /**
1175 * Allow for rendering of East Asian double-width characters, utf-16 surrogate pairs, and unicode
1176 * combining characters. This allows you to display text above the basic multilingual plane. This
1177 * is behind an option because it may affect performance slightly negatively. Without this option
1178 * enabled, all double-width, surrogate pair, and combining characters will be replaced by '??',
1179 * '?', '' respectively. (NOTE: iTerm2 cannot display combining characters properly. Blessed simply
1180 * removes them from an element's content if iTerm2 is detected).
1181 */
1182 fullUnicode: boolean;
1183
1184 /**
1185 * Send focus events after mouse is enabled.
1186 */
1187 sendFocus: boolean;
1188
1189 /**
1190 * Display warnings (such as the output not being a TTY, similar to ncurses).
1191 */
1192 warnings: boolean;
1193
1194 /**
1195 * Force blessed to use unicode even if it is not detected via terminfo, env variables, or windows code page.
1196 * If value is true unicode is forced. If value is false non-unicode is forced (default: null).
1197 */
1198 forceUnicode: boolean;
1199
1200 /**
1201 * Input and output streams. process.stdin/process.stdout by default, however, it could be a
1202 * net.Socket if you want to make a program that runs over telnet or something of that nature.
1203 */
1204 input: Writable;
1205
1206 /**
1207 * Input and output streams. process.stdin/process.stdout by default, however, it could be a
1208 * net.Socket if you want to make a program that runs over telnet or something of that nature.
1209 */
1210 output: Readable;
1211
1212 /**
1213 * The blessed Tput object (only available if you passed tput: true to the Program constructor.)
1214 */
1215 tput: Tput;
1216
1217 /**
1218 * Top of the focus history stack.
1219 */
1220 focused: BlessedElement;
1221
1222 /**
1223 * Width of the screen (same as program.cols).
1224 */
1225 width: Types.TPosition;
1226
1227 /**
1228 * Height of the screen (same as program.rows).
1229 */
1230 height: Types.TPosition;
1231
1232 /**
1233 * Same as screen.width.
1234 */
1235 cols: number;
1236
1237 /**
1238 * Same as screen.height.
1239 */
1240 rows: number;
1241
1242 /**
1243 * Relative top offset, always zero.
1244 */
1245 top: Types.TTopLeft;
1246
1247 /**
1248 * Relative left offset, always zero.
1249 */
1250 left: Types.TTopLeft;
1251
1252 /**
1253 * Relative right offset, always zero.
1254 */
1255 right: Types.TPosition;
1256
1257 /**
1258 * Relative bottom offset, always zero.
1259 */
1260 bottom: Types.TPosition;
1261
1262 /**
1263 * Absolute top offset, always zero.
1264 */
1265 atop: Types.TTopLeft;
1266
1267 /**
1268 * Absolute left offset, always zero.
1269 */
1270 aleft: Types.TTopLeft;
1271
1272 /**
1273 * Absolute right offset, always zero.
1274 */
1275 aright: Types.TPosition;
1276
1277 /**
1278 * Absolute bottom offset, always zero.
1279 */
1280 abottom: Types.TPosition;
1281
1282 /**
1283 * Whether the focused element grabs all keypresses.
1284 */
1285 grabKeys: boolean;
1286
1287 /**
1288 * Prevent keypresses from being received by any element.
1289 */
1290 lockKeys: boolean;
1291
1292 /**
1293 * The currently hovered element. Only set if mouse events are bound.
1294 */
1295 hover: Widgets.BlessedElement;
1296
1297 /**
1298 * Set or get terminal name. Set calls screen.setTerminal() internally.
1299 */
1300 terminal: string;
1301
1302 /**
1303 * Set or get window title.
1304 */
1305 title: string;
1306
1307 /**
1308 * Array of `Element` instances that may receive click/mouse events.
1309 */
1310 clickable: Widgets.BlessedElement[];
1311
1312 /**
1313 * Array of `Element` instances that may receive key events.
1314 */
1315 keyable: Widgets.BlessedElement[];
1316
1317 /**
1318 * Parse the sides of an element to determine whether an element has uniform cells on both sides.
1319 * If it does, we can use CSR to optimize scrolling on a scrollable element.
1320 */
1321 cleanSides(el: Widgets.BlessedElement): boolean;
1322
1323 /**
1324 * Write string to the log file if one was created.
1325 */
1326 log(...msg: any[]): void;
1327
1328 /**
1329 * Same as the log method, but only gets called if the debug option was set.
1330 */
1331 debug(...msg: string[]): void;
1332
1333 /**
1334 * Allocate a new pending screen buffer and a new output screen buffer.
1335 */
1336 alloc(): void;
1337
1338 /**
1339 * Reallocate the screen buffers and clear the screen.
1340 */
1341 realloc(): void;
1342
1343 /**
1344 * Draw the screen based on the contents of the screen buffer.
1345 */
1346 draw(start: number, end: number): void;
1347
1348 /**
1349 * Render all child elements, writing all data to the screen buffer and drawing the screen.
1350 */
1351 render(): void;
1352
1353 /**
1354 * Clear any region on the screen.
1355 */
1356 clearRegion(x1: number, x2: number, y1: number, y2: number): void;
1357
1358 /**
1359 * Fill any region with a character of a certain attribute.
1360 */
1361 fillRegion(attr: string, ch: string, x1: number, x2: number, y1: number, y2: number): void;
1362
1363 /**
1364 * Focus element by offset of focusable elements.
1365 */
1366 focusOffset(offset: number): void;
1367
1368 /**
1369 * Focus previous element in the index.
1370 */
1371 focusPrevious(): void;
1372
1373 /**
1374 * Focus next element in the index.
1375 */
1376 focusNext(): void;
1377
1378 /**
1379 * Push element on the focus stack (equivalent to screen.focused = el).
1380 */
1381 focusPush(element: BlessedElement): void;
1382
1383 /**
1384 * Pop element off the focus stack.
1385 */
1386 focusPop(): BlessedElement;
1387
1388 /**
1389 * Save the focused element.
1390 */
1391 saveFocus(): BlessedElement;
1392
1393 /**
1394 * Restore the saved focused element.
1395 */
1396 restoreFocus(): BlessedElement;
1397
1398 /**
1399 * "Rewind" focus to the last visible and attached element.
1400 */
1401 rewindFocus(): BlessedElement;
1402
1403 /**
1404 * Spawn a process in the foreground, return to blessed app after exit.
1405 */
1406 spawn(file: string, args?: string[], options?: NodeChildProcessExecOptions): child_process.ChildProcess;
1407
1408 /**
1409 * Spawn a process in the foreground, return to blessed app after exit. Executes callback on error or exit.
1410 */
1411 exec(
1412 file: string,
1413 args: string[],
1414 options: NodeChildProcessExecOptions,
1415 callback: (...args: any[]) => void
1416 ): child_process.ChildProcess;
1417
1418 /**
1419 * Read data from text editor.
1420 */
1421 readEditor(options: any, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
1422 readEditor(callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
1423
1424 /**
1425 * Set effects based on two events and attributes.
1426 */
1427 setEffects(el: BlessedElement, fel: BlessedElement, over: string, out: string, effects: any, temp: any): void;
1428
1429 /**
1430 * Insert a line into the screen (using csr: this bypasses the output buffer).
1431 */
1432 insertLine(n: number, y: number, top: number, bottom: number): void;
1433
1434 /**
1435 * Delete a line from the screen (using csr: this bypasses the output buffer).
1436 */
1437 deleteLine(n: number, y: number, top: number, bottom: number): void;
1438
1439 /**
1440 * Insert a line at the bottom of the screen.
1441 */
1442 insertBottom(top: number, bottom: number): void;
1443
1444 /**
1445 * Insert a line at the top of the screen.
1446 */
1447 insertTop(top: number, bottom: number): void;
1448
1449 /**
1450 * Delete a line at the bottom of the screen.
1451 */
1452 deleteBottom(top: number, bottom: number): void;
1453
1454 /**
1455 * Delete a line at the top of the screen.
1456 */
1457 deleteTop(top: number, bottom: number): void;
1458
1459 /**
1460 * Enable mouse events for the screen and optionally an element (automatically called when a form of
1461 * on('mouse') is bound).
1462 */
1463 enableMouse(el?: BlessedElement): void;
1464
1465 /**
1466 * Enable keypress events for the screen and optionally an element (automatically called when a form of
1467 * on('keypress') is bound).
1468 */
1469 enableKeys(el?: BlessedElement): void;
1470
1471 /**
1472 * Enable key and mouse events. Calls bot enableMouse and enableKeys.
1473 */
1474 enableInput(el?: BlessedElement): void;
1475
1476 /**
1477 * Attempt to copy text to clipboard using iTerm2's proprietary sequence. Returns true if successful.
1478 */
1479 copyToClipboard(text: string): void;
1480
1481 /**
1482 * Attempt to change cursor shape. Will not work in all terminals (see artificial cursors for a solution
1483 * to this). Returns true if successful.
1484 */
1485 cursorShape(shape: boolean, blink: boolean): any;
1486
1487 /**
1488 * Attempt to change cursor color. Returns true if successful.
1489 */
1490 cursorColor(color: string): void;
1491
1492 /**
1493 * Attempt to reset cursor. Returns true if successful.
1494 */
1495 cursorReset(): void;
1496
1497 /**
1498 * Take an SGR screenshot of the screen within the region. Returns a string containing only
1499 * characters and SGR codes. Can be displayed by simply echoing it in a terminal.
1500 */
1501 screenshot(xi: number, xl: number, yi: number, yl: number): string;
1502 screenshot(): void;
1503
1504 /**
1505 * Destroy the screen object and remove it from the global list. Also remove all global events relevant
1506 * to the screen object. If all screen objects are destroyed, the node process is essentially reset
1507 * to its initial state.
1508 */
1509 destroy(): void;
1510
1511 /**
1512 * Reset the terminal to term. Reloads terminfo.
1513 */
1514 setTerminal(term: string): void;
1515 }
1516
1517 interface Padding {
1518 left?: number | undefined;
1519 right?: number | undefined;
1520 top?: number | undefined;
1521 bottom?: number | undefined;
1522 }
1523
1524 class PositionCoords {
1525 xi: number;
1526 xl: number;
1527 yi: number;
1528 yl: number;
1529 }
1530
1531 interface Position {
1532 left: number | string;
1533 right: number | string;
1534 top: number | string;
1535 bottom: number | string;
1536 }
1537
1538 interface Border {
1539 /**
1540 * Type of border (line or bg). bg by default.
1541 */
1542 type?: "line" | "bg" | undefined;
1543
1544 /**
1545 * Character to use if bg type, default is space.
1546 */
1547 ch?: string | undefined;
1548
1549 /**
1550 * Border foreground and background, must be numbers (-1 for default).
1551 */
1552 bg?: number | undefined;
1553 fg?: number | undefined;
1554
1555 /**
1556 * Border attributes.
1557 */
1558 bold?: string | undefined;
1559 underline?: string | undefined;
1560 }
1561
1562 interface ElementOptions extends INodeOptions {
1563 tags?: boolean | undefined;
1564
1565 fg?: string | undefined;
1566 bg?: string | undefined;
1567 bold?: string | undefined;
1568 underline?: string | undefined;
1569
1570 style?: any;
1571
1572 /**
1573 * Border object, see below.
1574 */
1575 border?: Border | "line" | "bg" | undefined;
1576
1577 /**
1578 * Element's text content.
1579 */
1580 content?: string | undefined;
1581
1582 /**
1583 * Element is clickable.
1584 */
1585 clickable?: boolean | undefined;
1586
1587 /**
1588 * Element is focusable and can receive key input.
1589 */
1590 input?: boolean | undefined;
1591 keyable?: boolean | undefined;
1592
1593 /**
1594 * Element is focused.
1595 */
1596 focused?: BlessedElement | undefined;
1597
1598 /**
1599 * Whether the element is hidden.
1600 */
1601 hidden?: boolean | undefined;
1602
1603 /**
1604 * A simple text label for the element.
1605 */
1606 label?: string | undefined;
1607
1608 /**
1609 * A floating text label for the element which appears on mouseover.
1610 */
1611 hoverText?: string | undefined;
1612
1613 /**
1614 * Text alignment: left, center, or right.
1615 */
1616 align?: "left" | "center" | "right" | undefined;
1617
1618 /**
1619 * Vertical text alignment: top, middle, or bottom.
1620 */
1621 valign?: "top" | "middle" | "bottom" | undefined;
1622
1623 /**
1624 * Shrink/flex/grow to content and child elements. Width/height during render.
1625 */
1626 shrink?: boolean | undefined;
1627
1628 /**
1629 * Amount of padding on the inside of the element. Can be a number or an object containing
1630 * the properties: left, right, top, and bottom.
1631 */
1632 padding?: number | Padding | undefined;
1633
1634 top?: Types.TTopLeft | undefined;
1635 left?: Types.TTopLeft | undefined;
1636 right?: Types.TPosition | undefined;
1637 bottom?: Types.TPosition | undefined;
1638
1639 /**
1640 * Width/height of the element, can be a number, percentage (0-100%), or keyword (half or shrink).
1641 * Percentages can also have offsets (50%+1, 50%-1).
1642 */
1643 width?: number | string | undefined;
1644
1645 /**
1646 * Offsets of the element relative to its parent. Can be a number, percentage (0-100%), or
1647 * keyword (center). right and bottom do not accept keywords. Percentages can also have
1648 * offsets (50%+1, 50%-1).
1649 */
1650 height?: number | string | undefined;
1651
1652 /**
1653 * Can contain the above options.
1654 */
1655 position?: Position | undefined;
1656
1657 /**
1658 * Whether the element is scrollable or not.
1659 */
1660 scrollable?: boolean | undefined;
1661
1662 /**
1663 * Background character (default is whitespace ).
1664 */
1665 ch?: string | undefined;
1666
1667 /**
1668 * Allow the element to be dragged with the mouse.
1669 */
1670 draggable?: boolean | undefined;
1671
1672 /**
1673 * Draw a translucent offset shadow behind the element.
1674 */
1675 shadow?: boolean | undefined;
1676 }
1677
1678 interface Coords {
1679 xl: number;
1680 xi: number;
1681 yl: number;
1682 yi: number;
1683 base: number;
1684 _contentEnd: { x: number; y: number };
1685 notop: Types.TTopLeft;
1686 noleft: Types.TTopLeft;
1687 noright: Types.TPosition;
1688 nobot: Types.TPosition;
1689 }
1690
1691 interface LabelOptions {
1692 text: string;
1693 side: Types.TAlign;
1694 }
1695
1696 // TODO: scrollable - Note: If the scrollable option is enabled, Element inherits all methods from ScrollableBox.
1697 abstract class BlessedElement extends NodeWithEvents implements IHasOptions<ElementOptions> {
1698 constructor(opts: ElementOptions);
1699
1700 /**
1701 * Original options object.
1702 */
1703 options: ElementOptions;
1704
1705 /**
1706 * Name of the element. Useful for form submission.
1707 */
1708 name: string;
1709
1710 /**
1711 * Border object.
1712 */
1713 border: Border;
1714
1715 style: any;
1716 position: Position;
1717 content: string;
1718 hidden: boolean;
1719 visible: boolean;
1720 detached: boolean;
1721
1722 /**
1723 * Border foreground and background, must be numbers (-1 for default).
1724 */
1725 bg: number;
1726 fg: number;
1727
1728 /**
1729 * Border attributes.
1730 */
1731 bold: string;
1732 underline: string;
1733
1734 /**
1735 * Calculated width.
1736 */
1737 width: number | string;
1738
1739 /**
1740 * Calculated height.
1741 */
1742 height: number | string;
1743
1744 /**
1745 * Calculated relative top offset.
1746 */
1747 top: Types.TTopLeft;
1748
1749 /**
1750 * Calculated relative left offset.
1751 */
1752 left: Types.TTopLeft;
1753
1754 /**
1755 * Calculated relative right offset.
1756 */
1757 right: Types.TPosition;
1758
1759 /**
1760 * Calculated relative bottom offset.
1761 */
1762 bottom: Types.TPosition;
1763
1764 /**
1765 * Calculated absolute top offset.
1766 */
1767 atop: Types.TTopLeft;
1768
1769 /**
1770 * Calculated absolute left offset.
1771 */
1772 aleft: Types.TTopLeft;
1773
1774 /**
1775 * Calculated absolute right offset.
1776 */
1777 aright: Types.TPosition;
1778
1779 /**
1780 * Calculated absolute bottom offset.
1781 */
1782 abottom: Types.TPosition;
1783
1784 /**
1785 * Whether the element is draggable. Set to true to allow dragging.
1786 */
1787 draggable: boolean;
1788
1789 itop: Types.TTopLeft;
1790 ileft: Types.TTopLeft;
1791 iheight: Types.TPosition;
1792 iwidth: Types.TPosition;
1793
1794 /**
1795 * Calculated relative top offset.
1796 */
1797 rtop: Types.TTopLeft;
1798
1799 /**
1800 * Calculated relative left offset.
1801 */
1802 rleft: Types.TTopLeft;
1803
1804 /**
1805 * Calculated relative right offset.
1806 */
1807 rright: Types.TPosition;
1808
1809 /**
1810 * Calculated relative bottom offset.
1811 */
1812 rbottom: Types.TPosition;
1813
1814 lpos: PositionCoords;
1815
1816 /**
1817 * Write content and children to the screen buffer.
1818 */
1819 render(): Coords;
1820
1821 /**
1822 * Hide element.
1823 */
1824 hide(): void;
1825
1826 /**
1827 * Show element.
1828 */
1829 show(): void;
1830
1831 /**
1832 * Toggle hidden/shown.
1833 */
1834 toggle(): void;
1835
1836 /**
1837 * Focus element.
1838 */
1839 focus(): void;
1840
1841 /**
1842 * Same asel.on('screen', ...) except this will automatically keep track of which listeners
1843 * are bound to the screen object. For use with removeScreenEvent(), free(), and destroy().
1844 */
1845 onScreenEvent(type: string, handler: (...args: any[]) => void): void;
1846
1847 /**
1848 * Same asel.removeListener('screen', ...) except this will automatically keep track of which
1849 * listeners are bound to the screen object. For use with onScreenEvent(), free(), and destroy().
1850 */
1851 removeScreenEvent(type: string, handler: (...args: any[]) => void): void;
1852
1853 /**
1854 * Free up the element. Automatically unbind all events that may have been bound to the screen
1855 * object. This prevents memory leaks. For use with onScreenEvent(), removeScreenEvent(),
1856 * and destroy().
1857 */
1858 free(): void;
1859
1860 /**
1861 * Same as the detach() method, except this will automatically call free() and unbind any screen
1862 * events to prevent memory leaks. for use with onScreenEvent(), removeScreenEvent(), and free().
1863 */
1864 destroy(): void;
1865
1866 /**
1867 * Set the z-index of the element (changes rendering order).
1868 */
1869 setIndex(z: number): void;
1870
1871 /**
1872 * Put the element in front of its siblings.
1873 */
1874 setFront(): void;
1875
1876 /**
1877 * Put the element in back of its siblings.
1878 */
1879 setBack(): void;
1880
1881 /**
1882 * text/options - Set the label text for the top-left corner. Example options: {text:'foo',side:'left'}
1883 */
1884 setLabel(arg: string | LabelOptions): void;
1885
1886 /**
1887 * Remove the label completely.
1888 */
1889 removeLabel(): any;
1890
1891 /**
1892 * text/options - Set a hover text box to follow the cursor. Similar to the "title" DOM attribute
1893 * in the browser. Example options: {text:'foo'}
1894 */
1895 setHover(arg: string | LabelOptions): void;
1896
1897 /**
1898 * Remove the hover label completely.
1899 */
1900 removeHover(): void;
1901
1902 /**
1903 * Enable mouse events for the element (automatically called when a form of on('mouse') is bound).
1904 */
1905 enableMouse(): void;
1906
1907 /**
1908 * Enable keypress events for the element (automatically called when a form of on('keypress') is bound).
1909 */
1910 enableKeys(): void;
1911
1912 /**
1913 * Enable key and mouse events. Calls both `enableMouse()` and `enableKeys()`.
1914 */
1915 enableInput(): void;
1916
1917 /**
1918 * Enable dragging of the element.
1919 */
1920 enableDrag(): void;
1921
1922 /**
1923 * Disable dragging of the element.
1924 */
1925 disableDrag(): void;
1926
1927 /**
1928 * Take an SGR screenshot of the screen within the region. Returns a string containing only
1929 * characters and SGR codes. Can be displayed by simply echoing it in a terminal.
1930 */
1931 screenshot(xi: number, xl: number, yi: number, yl: number): string;
1932 screenshot(): void;
1933
1934 /*
1935 Content Methods
1936
1937 Methods for dealing with text content, line by line. Useful for writing a text editor,
1938 irc client, etc.
1939
1940 Note: All of these methods deal with pre-aligned, pre-wrapped text. If you use deleteTop()
1941 on a box with a wrapped line at the top, it may remove 3-4 "real" lines (rows) depending
1942 on how long the original line was.
1943
1944 The lines parameter can be a string or an array of strings. The line parameter must
1945 be a string.
1946 */
1947
1948 /**
1949 * Set the content. Note: When text is input, it will be stripped of all non-SGR
1950 * escape codes, tabs will be replaced with 8 spaces, and tags will be replaced
1951 * with SGR codes (if enabled).
1952 */
1953 setContent(text: string): void;
1954
1955 /**
1956 * Return content, slightly different from el.content. Assume the above formatting.
1957 */
1958 getContent(): string;
1959
1960 /**
1961 * Similar to setContent, but ignore tags and remove escape codes.
1962 */
1963 setText(text: string): void;
1964
1965 /**
1966 * Similar to getContent, but return content with tags and escape codes removed.
1967 */
1968 getText(): string;
1969
1970 /**
1971 * Insert a line into the box's content.
1972 */
1973 insertLine(i: number, lines: string | string[]): void;
1974
1975 /**
1976 * Delete a line from the box's content.
1977 */
1978 deleteLine(i: number): void;
1979
1980 /**
1981 * Get a line from the box's content.
1982 */
1983 getLine(i: number): string;
1984
1985 /**
1986 * Get a line from the box's content from the visible top.
1987 */
1988 getBaseLine(i: number): string;
1989
1990 /**
1991 * Set a line in the box's content.
1992 */
1993 setLine(i: number, line: string | string[]): void;
1994
1995 /**
1996 * Set a line in the box's content from the visible top.
1997 */
1998 setBaseLine(i: number, line: string | string[]): void;
1999
2000 /**
2001 * Clear a line from the box's content.
2002 */
2003 clearLine(i: number): void;
2004
2005 /**
2006 * Clear a line from the box's content from the visible top.
2007 */
2008 clearBaseLine(i: number): void;
2009
2010 /**
2011 * Insert a line at the top of the box.
2012 */
2013 insertTop(lines: string | string[]): void;
2014
2015 /**
2016 * Insert a line at the bottom of the box.
2017 */
2018 insertBottom(lines: string | string[]): void;
2019
2020 /**
2021 * Delete a line at the top of the box.
2022 */
2023 deleteTop(): void;
2024
2025 /**
2026 * Delete a line at the bottom of the box.
2027 */
2028 deleteBottom(): void;
2029
2030 /**
2031 * Unshift a line onto the top of the content.
2032 */
2033 unshiftLine(lines: string | string[]): void;
2034
2035 /**
2036 * Shift a line off the top of the content.
2037 */
2038 shiftLine(i: number): void;
2039
2040 /**
2041 * Push a line onto the bottom of the content.
2042 */
2043 pushLine(lines: string | string[]): void;
2044
2045 /**
2046 * Pop a line off the bottom of the content.
2047 */
2048 popLine(i: number): string;
2049
2050 /**
2051 * An array containing the content lines.
2052 */
2053 getLines(): string[];
2054
2055 /**
2056 * An array containing the lines as they are displayed on the screen.
2057 */
2058 getScreenLines(): string[];
2059
2060 /**
2061 * Get a string's displayed width, taking into account double-width, surrogate pairs,
2062 * combining characters, tags, and SGR escape codes.
2063 */
2064 strWidth(text: string): string;
2065 }
2066
2067 interface ScrollableBoxOptions extends ElementOptions {
2068 /**
2069 * A limit to the childBase. Default is Infinity.
2070 */
2071 baseLimit?: number | undefined;
2072
2073 /**
2074 * A option which causes the ignoring of childOffset. This in turn causes the
2075 * childBase to change every time the element is scrolled.
2076 */
2077 alwaysScroll?: boolean | undefined;
2078
2079 /**
2080 * Object enabling a scrollbar.
2081 * Style of the scrollbar track if present (takes regular style options).
2082 */
2083 scrollbar?: { style?: any; track?: any; ch?: string | undefined } | undefined;
2084 }
2085
2086 interface ScrollableTextOptions extends ScrollableBoxOptions {
2087 /**
2088 * Whether to enable automatic mouse support for this element.
2089 * Use pre-defined mouse events (right-click for editor).
2090 */
2091 mouse?: boolean | (() => void) | undefined;
2092
2093 /**
2094 * Use pre-defined keys (i or enter for insert, e for editor, C-e for editor while inserting).
2095 */
2096 keys?: string | string[] | boolean | undefined;
2097
2098 /**
2099 * Use vi keys with the keys option.
2100 */
2101 vi?: boolean | undefined;
2102 }
2103
2104 interface BoxOptions extends ScrollableTextOptions {
2105 bindings?: any;
2106 }
2107
2108 /**
2109 * DEPRECATED - Use Box with the scrollable option instead. A box with scrollable content.
2110 */
2111 class ScrollableBoxElement extends BlessedElement {
2112 /**
2113 * The offset of the top of the scroll content.
2114 */
2115 childBase: number;
2116
2117 /**
2118 * The offset of the chosen item/line.
2119 */
2120 childOffset: number;
2121
2122 /**
2123 * Scroll the content by a relative offset.
2124 */
2125 scroll(offset: number, always?: boolean): void;
2126
2127 /**
2128 * Scroll the content to an absolute index.
2129 */
2130 scrollTo(index: number): void;
2131
2132 /**
2133 * Same as scrollTo.
2134 */
2135 setScroll(index: number): void;
2136
2137 /**
2138 * Set the current scroll index in percentage (0-100).
2139 */
2140 setScrollPerc(perc: number): void;
2141
2142 /**
2143 * Get the current scroll index in lines.
2144 */
2145 getScroll(): number;
2146
2147 /**
2148 * Get the actual height of the scrolling area.
2149 */
2150 getScrollHeight(): number;
2151
2152 /**
2153 * Get the current scroll index in percentage.
2154 */
2155 getScrollPerc(): number;
2156
2157 /**
2158 * Reset the scroll index to its initial state.
2159 */
2160 resetScroll(): void;
2161
2162 on(event: string, listener: (...args: any[]) => void): this;
2163
2164 /**
2165 * Received when the element is scrolled.
2166 */
2167 on(event: "scroll", callback: () => void): this;
2168 }
2169
2170 /**
2171 * DEPRECATED - Use Box with the scrollable and alwaysScroll options instead.
2172 * A scrollable text box which can display and scroll text, as well as handle
2173 * pre-existing newlines and escape codes.
2174 */
2175 class ScrollableTextElement extends ScrollableBoxElement {}
2176
2177 /**
2178 * A box element which draws a simple box containing content or other elements.
2179 */
2180 class BoxElement extends ScrollableTextElement implements IHasOptions<BoxOptions> {
2181 constructor(opts: BoxOptions);
2182
2183 /**
2184 * Original options object.
2185 */
2186 options: BoxOptions;
2187 }
2188
2189 interface TextOptions extends ElementOptions {
2190 /**
2191 * Fill the entire line with chosen bg until parent bg ends, even if there
2192 * is not enough text to fill the entire width.
2193 */
2194 fill?: boolean | undefined;
2195
2196 /**
2197 * Text alignment: left, center, or right.
2198 */
2199 align?: Types.TAlign | undefined;
2200 }
2201
2202 /**
2203 * An element similar to Box, but geared towards rendering simple text elements.
2204 */
2205 class TextElement extends BlessedElement implements IHasOptions<TextOptions> {
2206 constructor(opts: TextOptions);
2207
2208 /**
2209 * Original options object.
2210 */
2211 options: TextOptions;
2212 }
2213
2214 /**
2215 * A simple line which can be line or bg styled.
2216 */
2217 interface LineOptions extends BoxOptions {
2218 /**
2219 * Can be vertical or horizontal.
2220 */
2221 orientation?: "vertical" | "horizontal" | undefined;
2222
2223 /**
2224 * Treated the same as a border object. (attributes can be contained in style).
2225 */
2226 type?: string | undefined;
2227 bg?: string | undefined;
2228 fg?: string | undefined;
2229 ch?: string | undefined;
2230 }
2231
2232 /**
2233 * A simple line which can be line or bg styled.
2234 */
2235 class LineElement extends BoxElement implements IHasOptions<LineOptions> {
2236 constructor(opts: LineOptions);
2237
2238 /**
2239 * Original options object.
2240 */
2241 options: LineOptions;
2242 }
2243
2244 interface BigTextOptions extends BoxOptions {
2245 /**
2246 * bdf->json font file to use (see ttystudio for instructions on compiling BDFs to JSON).
2247 */
2248 font?: string | undefined;
2249
2250 /**
2251 * bdf->json bold font file to use (see ttystudio for instructions on compiling BDFs to JSON).
2252 */
2253 fontBold?: string | undefined;
2254
2255 /**
2256 * foreground character. (default: ' ')
2257 */
2258 fch?: string | undefined;
2259 }
2260
2261 /**
2262 * A box which can render content drawn as 8x14 cell characters using the terminus font.
2263 */
2264 class BigTextElement extends BoxElement implements IHasOptions<BigTextOptions> {
2265 constructor(opts: BigTextOptions);
2266
2267 /**
2268 * Original options object.
2269 */
2270 options: BigTextOptions;
2271 }
2272
2273 interface ListElementStyle {
2274 selected?: any;
2275 item?: any;
2276 }
2277
2278 interface ListOptions<TStyle extends ListElementStyle> extends BoxOptions {
2279 /**
2280 * Style for a selected item. Style for an unselected item.
2281 */
2282 style?: TStyle | undefined;
2283
2284 /**
2285 * An array of strings which become the list's items.
2286 */
2287 items?: string[] | undefined;
2288
2289 /**
2290 * A function that is called when vi mode is enabled and the key / is pressed. This function accepts a
2291 * callback function which should be called with the search string. The search string is then used to
2292 * jump to an item that is found in items.
2293 */
2294 search?(err: any, value?: string): void;
2295
2296 /**
2297 * Whether the list is interactive and can have items selected (Default: true).
2298 */
2299 interactive?: boolean | undefined;
2300
2301 /**
2302 * Whether to automatically override tags and invert fg of item when selected (Default: true).
2303 */
2304 invertSelected?: boolean | undefined;
2305 }
2306
2307 type ListElementEventType =
2308 /** List was canceled (when esc is pressed with the keys option). */
2309 | "cancel"
2310 /** Either a select or a cancel event was received. */
2311 | "action"
2312 | "create item"
2313 | "add item"
2314 | "remove item"
2315 | "insert item"
2316 | "set items";
2317
2318 class ListElement extends BoxElement implements IHasOptions<ListOptions<ListElementStyle>> {
2319 constructor(opts: ListOptions<ListElementStyle>);
2320
2321 /**
2322 * Original options object.
2323 */
2324 options: ListOptions<ListElementStyle>;
2325
2326 /**
2327 * Add an item based on a string.
2328 */
2329 add(text: string): void;
2330
2331 /**
2332 * Add an item based on a string.
2333 */
2334 addItem(text: string): void;
2335
2336 /**
2337 * Removes an item from the list. Child can be an element, index, or string.
2338 */
2339 removeItem(child: BlessedElement | number | string): BlessedElement;
2340
2341 /**
2342 * Push an item onto the list.
2343 */
2344 pushItem(child: BlessedElement): number;
2345
2346 /**
2347 * Pop an item off the list.
2348 */
2349 popItem(): BlessedElement;
2350
2351 /**
2352 * Unshift an item onto the list.
2353 */
2354 unshiftItem(child: BlessedElement): number;
2355
2356 /**
2357 * Shift an item off the list.
2358 */
2359 shiftItem(): BlessedElement;
2360
2361 /**
2362 * Inserts an item to the list. Child can be an element, index, or string.
2363 */
2364 insertItem(i: number, child: BlessedElement | number | string): void;
2365
2366 /**
2367 * Returns the item element. Child can be an element, index, or string.
2368 */
2369 getItem(child: BlessedElement | number | string): BlessedElement;
2370
2371 /**
2372 * Set item to content.
2373 */
2374 setItem(child: BlessedElement, content: BlessedElement | string): void;
2375
2376 /**
2377 * Remove and insert items to the list.
2378 */
2379 spliceItem(i: number, n: number, ...items: BlessedElement[]): void;
2380
2381 /**
2382 * Clears all items from the list.
2383 */
2384 clearItems(): void;
2385
2386 /**
2387 * Sets the list items to multiple strings.
2388 */
2389 setItems(items: BlessedElement[]): void;
2390
2391 /**
2392 * Returns the item index from the list. Child can be an element, index, or string.
2393 */
2394 getItemIndex(child: BlessedElement | number | string): number;
2395
2396 /**
2397 * Select an index of an item.
2398 */
2399 select(index: number): void;
2400
2401 /**
2402 * Select item based on current offset.
2403 */
2404 move(offset: number): void;
2405
2406 /**
2407 * Select item above selected.
2408 */
2409 up(amount: number): void;
2410
2411 /**
2412 * Select item below selected.
2413 */
2414 down(amount: number): void;
2415
2416 /**
2417 * Show/focus list and pick an item. The callback is executed with the result.
2418 */
2419 pick(callback: () => void): void;
2420
2421 /**
2422 * Find an item based on its text content.
2423 */
2424 fuzzyFind(arg: string | RegExp | (() => void)): void;
2425
2426 on(event: string, listener: (...args: any[]) => void): this;
2427 /** Received when an item is selected. */
2428 on(event: "select", callback: (item: BoxElement, index: number) => void): this;
2429 on(event: ListElementEventType, callback: () => void): this;
2430 on(event: "select item", callback: (item: BlessedElement, index: number) => void): this;
2431 }
2432
2433 interface FileManagerOptions extends ListOptions<ListElementStyle> {
2434 /**
2435 * Current working directory.
2436 */
2437 cwd?: string | undefined;
2438 }
2439
2440 class FileManagerElement extends ListElement implements IHasOptions<FileManagerOptions> {
2441 constructor(opts: FileManagerOptions);
2442
2443 /**
2444 * Original options object.
2445 */
2446 options: FileManagerOptions;
2447
2448 /**
2449 * Current working directory.
2450 */
2451 cwd: string;
2452
2453 /**
2454 * Refresh the file list (perform a readdir on cwd and update the list items).
2455 */
2456 refresh(cwd: string, callback: () => void): void;
2457 refresh(callback?: () => void): void;
2458
2459 /**
2460 * Pick a single file and return the path in the callback.
2461 */
2462 pick(cwd: string, callback: () => void): void;
2463 pick(callback: () => void): void;
2464
2465 /**
2466 * Reset back to original cwd.
2467 */
2468 reset(cwd: string, callback: () => void): void;
2469 reset(callback?: () => void): void;
2470
2471 on(event: string, listener: (...args: any[]) => void): this;
2472 /** Received when an item is selected. */
2473 on(event: "cd", callback: (file: string, cwd: string) => void): this;
2474 /** Received when an item is selected. */
2475 on(event: "file", callback: (file: string) => void): this;
2476 on(event: "error", callback: (err: any, file: string) => void): this;
2477 on(event: "refresh", callback: () => void): this;
2478 }
2479
2480 interface StyleListTable extends ListElementStyle {
2481 /**
2482 * Header style.
2483 */
2484 header?: any;
2485
2486 /**
2487 * Cell style.
2488 */
2489 cell?: any;
2490 }
2491
2492 interface ListTableOptions extends ListOptions<StyleListTable> {
2493 /**
2494 * Array of array of strings representing rows.
2495 */
2496 rows?: string[] | undefined;
2497 data?: string[][] | undefined;
2498
2499 /**
2500 * Spaces to attempt to pad on the sides of each cell. 2 by default: one space on each side
2501 * (only useful if the width is shrunken).
2502 */
2503 pad?: number | undefined;
2504
2505 /**
2506 * Do not draw inner cells.
2507 */
2508 noCellBorders?: boolean | undefined;
2509
2510 style?: StyleListTable | undefined;
2511 }
2512
2513 class ListTableElement extends ListElement implements IHasOptions<ListTableOptions> {
2514 constructor(opts: ListTableOptions);
2515
2516 /**
2517 * Original options object.
2518 */
2519 options: ListTableOptions;
2520
2521 /**
2522 * Set rows in table. Array of arrays of strings.
2523 * @example:
2524 *
2525 * table.setData([
2526 * [ 'Animals', 'Foods' ],
2527 * [ 'Elephant', 'Apple' ],
2528 * [ 'Bird', 'Orange' ]
2529 * ]);
2530 */
2531 setRows(rows: string[][]): void;
2532
2533 /**
2534 * Set rows in table. Array of arrays of strings.
2535 * @example:
2536 *
2537 * table.setData([
2538 * [ 'Animals', 'Foods' ],
2539 * [ 'Elephant', 'Apple' ],
2540 * [ 'Bird', 'Orange' ]
2541 * ]);
2542 */
2543 setData(rows: string[][]): void;
2544 }
2545
2546 interface ListbarOptions extends BoxOptions {
2547 style?: ListElementStyle | undefined;
2548
2549 /**
2550 * Set buttons using an object with keys as titles of buttons, containing of objects
2551 * containing keys of keys and callback.
2552 */
2553 commands: Types.ListbarCommand[];
2554 items: Types.ListbarCommand[];
2555
2556 /**
2557 * Automatically bind list buttons to keys 0-9.
2558 */
2559 autoCommandKeys: boolean;
2560 }
2561
2562 class ListbarElement extends BoxElement implements IHasOptions<ListbarOptions> {
2563 constructor(opts: ListbarOptions);
2564
2565 /**
2566 * Original options object.
2567 */
2568 options: ListbarOptions;
2569
2570 /**
2571 * Set commands (see commands option above).
2572 */
2573 setItems(commands: Types.ListbarCommand[]): void;
2574
2575 /**
2576 * Append an item to the bar.
2577 */
2578 add(item: Types.ListbarCommand, callback: () => void): void;
2579
2580 /**
2581 * Append an item to the bar.
2582 */
2583 addItem(item: Types.ListbarCommand, callback: () => void): void;
2584
2585 /**
2586 * Append an item to the bar.
2587 */
2588 appendItem(item: Types.ListbarCommand, callback: () => void): void;
2589
2590 /**
2591 * Select an item on the bar.
2592 */
2593 select(offset: number): void;
2594
2595 /**
2596 * Remove item from the bar.
2597 */
2598 removeItem(child: BlessedElement): void;
2599
2600 /**
2601 * Move relatively across the bar.
2602 */
2603 move(offset: number): void;
2604
2605 /**
2606 * Move left relatively across the bar.
2607 */
2608 moveLeft(offset: number): void;
2609
2610 /**
2611 * Move right relatively across the bar.
2612 */
2613 moveRight(offset: number): void;
2614
2615 /**
2616 * Select button and execute its callback.
2617 */
2618 selectTab(index: number): void;
2619
2620 on(event: string, listener: (...args: any[]) => void): this;
2621 on(event: "set items" | "remove item" | "select tab", callback: () => void): this;
2622 }
2623
2624 interface FormOptions extends BoxOptions {
2625 /**
2626 * Allow default keys (tab, vi keys, enter).
2627 */
2628 keys?: any;
2629
2630 /**
2631 * Allow vi keys.
2632 */
2633 vi?: boolean | undefined;
2634 }
2635
2636 class FormElement<TFormData> extends BoxElement implements IHasOptions<FormOptions> {
2637 constructor(opts: FormOptions);
2638
2639 /**
2640 * Original options object.
2641 */
2642 options: FormOptions;
2643
2644 /**
2645 * Last submitted data.
2646 */
2647 submission: TFormData;
2648
2649 /**
2650 * Focus next form element.
2651 */
2652 focusNext(): void;
2653
2654 /**
2655 * Focus previous form element.
2656 */
2657 focusPrevious(): void;
2658
2659 /**
2660 * Submit the form.
2661 */
2662 submit(): void;
2663
2664 /**
2665 * Discard the form.
2666 */
2667 cancel(): void;
2668
2669 /**
2670 * Clear the form.
2671 */
2672 reset(): void;
2673
2674 on(event: string, listener: (...args: any[]) => void): this;
2675 /** Form is submitted. Receives a data object. */
2676 on(event: "submit", callback: (out: TFormData) => void): this;
2677 on(event: "cancel" | "reset", callback: () => void): this;
2678 }
2679
2680 interface InputOptions extends BoxOptions {}
2681
2682 abstract class InputElement extends BoxElement {
2683 constructor(opts: InputOptions);
2684 }
2685
2686 /**
2687 * A box which allows multiline text input.
2688 */
2689 interface TextareaOptions extends InputOptions {
2690 /**
2691 * Call readInput() when the element is focused. Automatically unfocus.
2692 */
2693 inputOnFocus?: boolean | undefined;
2694 }
2695
2696 type TextareaElementEventType =
2697 /** Value is an error. */
2698 | "error"
2699 /** Value is submitted (enter). */
2700 | "submit"
2701 /** Value is discared (escape). */
2702 | "cancel"
2703 /** Either submit or cancel. */
2704 | "action";
2705
2706 class TextareaElement extends InputElement implements IHasOptions<TextareaOptions> {
2707 constructor(opts: TextareaOptions);
2708
2709 /**
2710 * Original options object.
2711 */
2712 options: TextareaOptions;
2713
2714 /**
2715 * The input text. read-only.
2716 */
2717 value: string;
2718
2719 /**
2720 * Submit the textarea (emits submit).
2721 */
2722 submit(): void;
2723
2724 /**
2725 * Cancel the textarea (emits cancel).
2726 */
2727 cancel(): void;
2728
2729 /**
2730 * Grab key events and start reading text from the keyboard. Takes a callback which receives
2731 * the final value.
2732 */
2733 readInput(callback?: (err: any, value?: string) => void): void;
2734
2735 /**
2736 * Grab key events and start reading text from the keyboard. Takes a callback which receives
2737 * the final value.
2738 */
2739 input(callback: (err: any, value?: string) => void): void;
2740
2741 /**
2742 * Grab key events and start reading text from the keyboard. Takes a callback which receives
2743 * the final value.
2744 */
2745 setInput(callback: (err: any, value?: string) => void): void;
2746
2747 /**
2748 * Open text editor in $EDITOR, read the output from the resulting file. Takes a callback which
2749 * receives the final value.
2750 */
2751 readEditor(callback: (err: any, value?: string) => void): void;
2752
2753 /**
2754 * Open text editor in $EDITOR, read the output from the resulting file. Takes a callback which
2755 * receives the final value.
2756 */
2757 editor(callback: (err: any, value?: string) => void): void;
2758
2759 /**
2760 * Open text editor in $EDITOR, read the output from the resulting file. Takes a callback which
2761 * receives the final value.
2762 */
2763 setEditor(callback: (err: any, value?: string) => void): void;
2764
2765 /**
2766 * The same as this.value, for now.
2767 */
2768 getValue(): string;
2769
2770 /**
2771 * Clear input.
2772 */
2773 clearValue(): void;
2774
2775 /**
2776 * Set value.
2777 */
2778 setValue(text: string): void;
2779
2780 on(event: string, listener: (...args: any[]) => void): this;
2781 on(event: TextareaElementEventType, callback: (err: any) => void): this;
2782 }
2783
2784 interface TextboxOptions extends TextareaOptions {
2785 /**
2786 * Completely hide text.
2787 */
2788 secret?: boolean | undefined;
2789
2790 /**
2791 * Replace text with asterisks (*).
2792 */
2793 censor?: boolean | undefined;
2794 }
2795
2796 class TextboxElement extends TextareaElement implements IHasOptions<TextboxOptions> {
2797 constructor(opts: TextboxOptions);
2798
2799 /**
2800 * Original options object.
2801 */
2802 options: TextboxOptions;
2803
2804 /**
2805 * Completely hide text.
2806 */
2807 secret: boolean;
2808
2809 /**
2810 * Replace text with asterisks (*).
2811 */
2812 censor: boolean;
2813 }
2814
2815 interface ButtonOptions extends BoxOptions {}
2816
2817 class ButtonElement extends InputElement implements IHasOptions<ButtonOptions> {
2818 constructor(opts: ButtonOptions);
2819
2820 /**
2821 * Original options object.
2822 */
2823 options: ButtonOptions;
2824
2825 /**
2826 * Press button. Emits press.
2827 */
2828 press(): void;
2829
2830 on(event: string, listener: (...args: any[]) => void): this;
2831 on(event: "press", callback: () => void): this;
2832 }
2833
2834 interface CheckboxOptions extends BoxOptions {
2835 /**
2836 * whether the element is checked or not.
2837 */
2838 checked?: boolean | undefined;
2839
2840 /**
2841 * enable mouse support.
2842 */
2843 mouse?: boolean | undefined;
2844 }
2845
2846 /**
2847 * A checkbox which can be used in a form element.
2848 */
2849 class CheckboxElement extends InputElement implements IHasOptions<CheckboxOptions> {
2850 constructor(options?: CheckboxOptions);
2851
2852 /**
2853 * Original options object.
2854 */
2855 options: CheckboxOptions;
2856
2857 /**
2858 * the text next to the checkbox (do not use setcontent, use `check.text = ''`).
2859 */
2860 text: string;
2861
2862 /**
2863 * whether the element is checked or not.
2864 */
2865 checked: boolean;
2866
2867 /**
2868 * same as `checked`.
2869 */
2870 value: boolean;
2871
2872 /**
2873 * check the element.
2874 */
2875 check(): void;
2876
2877 /**
2878 * uncheck the element.
2879 */
2880 uncheck(): void;
2881
2882 /**
2883 * toggle checked state.
2884 */
2885 toggle(): void;
2886 }
2887
2888 interface RadioSetOptions extends BoxOptions {}
2889
2890 /**
2891 * An element wrapping RadioButtons. RadioButtons within this element will be mutually exclusive
2892 * with each other.
2893 */
2894 abstract class RadioSetElement extends BoxElement {
2895 constructor(opts: RadioSetOptions);
2896 }
2897
2898 interface RadioButtonOptions extends BoxOptions {}
2899
2900 /**
2901 * A radio button which can be used in a form element.
2902 */
2903 abstract class RadioButtonElement extends CheckboxElement {
2904 constructor(opts: RadioButtonOptions);
2905 }
2906
2907 interface PromptOptions extends BoxOptions {}
2908
2909 /**
2910 * A prompt box containing a text input, okay, and cancel buttons (automatically hidden).
2911 */
2912 class PromptElement extends BoxElement implements IHasOptions<PromptOptions> {
2913 constructor(opts: PromptOptions);
2914
2915 options: PromptOptions;
2916
2917 /**
2918 * Show the prompt and wait for the result of the textbox. Set text and initial value.
2919 */
2920 input(text: string, value: string, callback: (err: any, value: string) => void): void;
2921 setInput(text: string, value: string, callback: (err: any, value: string) => void): void;
2922 readInput(text: string, value: string, callback: (err: any, value: string) => void): void;
2923 }
2924
2925 interface QuestionOptions extends BoxOptions {}
2926
2927 /**
2928 * A question box containing okay and cancel buttons (automatically hidden).
2929 */
2930 class QuestionElement extends BoxElement implements IHasOptions<QuestionOptions> {
2931 constructor(opts: QuestionOptions);
2932
2933 options: QuestionOptions;
2934
2935 /**
2936 * Ask a question. callback will yield the result.
2937 */
2938 ask(question: string, callback: (err: any, value: string) => void): void;
2939 }
2940
2941 interface MessageOptions extends BoxOptions {}
2942
2943 /**
2944 * A box containing a message to be displayed (automatically hidden).
2945 */
2946 class MessageElement extends BoxElement implements IHasOptions<MessageOptions> {
2947 constructor(opts: MessageOptions);
2948
2949 options: MessageOptions;
2950
2951 /**
2952 * Display a message for a time (default is 3 seconds). Set time to 0 for a
2953 * perpetual message that is dismissed on keypress.
2954 */
2955 log(text: string, time: number, callback: (err: any) => void): void;
2956 log(text: string, callback: (err: any) => void): void;
2957 display(text: string, time: number, callback: (err: any) => void): void;
2958 display(text: string, callback: (err: any) => void): void;
2959
2960 /**
2961 * Display an error in the same way.
2962 */
2963 error(text: string, time: number, callback: () => void): void;
2964 error(text: string, callback: () => void): void;
2965 }
2966
2967 interface LoadingOptions extends BoxOptions {}
2968
2969 /**
2970 * A box with a spinning line to denote loading (automatically hidden).
2971 */
2972 class LoadingElement extends BoxElement implements IHasOptions<LoadingOptions> {
2973 constructor(opts: LoadingOptions);
2974
2975 options: LoadingOptions;
2976
2977 /**
2978 * Display the loading box with a message. Will lock keys until stop is called.
2979 */
2980 load(text: string): void;
2981
2982 /**
2983 * Hide loading box. Unlock keys.
2984 */
2985 stop(): void;
2986 }
2987
2988 interface ProgressBarOptions extends BoxOptions {
2989 /**
2990 * can be `horizontal` or `vertical`.
2991 */
2992 orientation?: string | undefined;
2993
2994 /**
2995 * the character to fill the bar with (default is space).
2996 */
2997 pch?: string | undefined;
2998
2999 /**
3000 * the amount filled (0 - 100).
3001 */
3002 filled?: number | undefined;
3003
3004 /**
3005 * same as `filled`.
3006 */
3007 value?: number | undefined;
3008
3009 /**
3010 * enable key support.
3011 */
3012 keys?: boolean | undefined;
3013
3014 /**
3015 * enable mouse support.
3016 */
3017 mouse?: boolean | undefined;
3018 }
3019
3020 /**
3021 * A progress bar allowing various styles. This can also be used as a form input.
3022 */
3023 class ProgressBarElement extends InputElement implements IHasOptions<ProgressBarOptions> {
3024 constructor(options?: ProgressBarOptions);
3025
3026 options: ProgressBarOptions;
3027
3028 /**
3029 * progress the bar by a fill amount.
3030 */
3031 progress(amount: number): void;
3032
3033 /**
3034 * set progress to specific amount.
3035 */
3036 setProgress(amount: number): void;
3037
3038 /**
3039 * reset the bar.
3040 */
3041 reset(): void;
3042
3043 on(event: string, listener: (...args: any[]) => void): this;
3044 on(event: "reset" | "complete", callback: () => void): this;
3045 }
3046
3047 interface LogOptions extends ScrollableTextOptions {
3048 /**
3049 * amount of scrollback allowed. default: Infinity.
3050 */
3051 scrollback?: number | undefined;
3052
3053 /**
3054 * scroll to bottom on input even if the user has scrolled up. default: false.
3055 */
3056 scrollOnInput?: boolean | undefined;
3057 }
3058
3059 /**
3060 * A log permanently scrolled to the bottom.
3061 */
3062 class Log extends ScrollableTextElement implements IHasOptions<LogOptions> {
3063 constructor(options?: LogOptions);
3064
3065 options: LogOptions;
3066
3067 /**
3068 * amount of scrollback allowed. default: Infinity.
3069 */
3070 scrollback: number;
3071
3072 /**
3073 * scroll to bottom on input even if the user has scrolled up. default: false.
3074 */
3075 scrollOnInput: boolean;
3076
3077 /**
3078 * add a log line.
3079 */
3080 log(text: string): void;
3081
3082 /**
3083 * add a log line.
3084 */
3085 add(text: string): void;
3086 }
3087
3088 interface TableOptions extends BoxOptions {
3089 /**
3090 * array of array of strings representing rows (same as `data`).
3091 */
3092 rows?: string[][] | undefined;
3093
3094 /**
3095 * array of array of strings representing rows (same as `rows`).
3096 */
3097 data?: string[][] | undefined;
3098
3099 /**
3100 * spaces to attempt to pad on the sides of each cell. `2` by default: one space on each side (only useful if the width is shrunken).
3101 */
3102 pad?: number | undefined;
3103
3104 /**
3105 * do not draw inner cells.
3106 */
3107 noCellBorders?: boolean | undefined;
3108
3109 /**
3110 * fill cell borders with the adjacent background color.
3111 */
3112 fillCellBorders?: boolean | undefined;
3113 }
3114
3115 /**
3116 * A stylized table of text elements.
3117 */
3118 class TableElement extends BoxElement implements IHasOptions<TableOptions> {
3119 constructor(opts: TableOptions);
3120
3121 options: TableOptions;
3122
3123 /**
3124 * set rows in table. array of arrays of strings.
3125 */
3126 setData(rows: string[][]): void;
3127
3128 /**
3129 * set rows in table. array of arrays of strings.
3130 */
3131 setRows(rows: string[][]): void;
3132 }
3133
3134 interface TerminalOptions extends BoxOptions {
3135 /**
3136 * handler for input data.
3137 */
3138 handler?(userInput: Buffer): void;
3139
3140 /**
3141 * name of shell. $SHELL by default.
3142 */
3143 shell?: string | undefined;
3144
3145 /**
3146 * args for shell.
3147 */
3148 args?: any;
3149
3150 /**
3151 * can be line, underline, and block.
3152 */
3153 cursor?: "line" | "underline" | "block" | undefined;
3154
3155 terminal?: string | undefined;
3156
3157 /**
3158 * Object for process env.
3159 */
3160 env?: any;
3161 }
3162
3163 class TerminalElement extends BoxElement implements IHasOptions<TerminalOptions> {
3164 constructor(opts: TerminalOptions);
3165
3166 options: TerminalOptions;
3167
3168 /**
3169 * reference to the headless term.js terminal.
3170 */
3171 term: any;
3172
3173 /**
3174 * reference to the pty.js pseudo terminal.
3175 */
3176 pty: any;
3177
3178 /**
3179 * write data to the terminal.
3180 */
3181 write(data: string): void;
3182
3183 /**
3184 * nearly identical to `element.screenshot`, however, the specified region includes the terminal's
3185 * _entire_ scrollback, rather than just what is visible on the screen.
3186 */
3187 screenshot(xi?: number, xl?: number, yi?: number, yl?: number): string;
3188 }
3189
3190 interface ImageOptions extends BoxOptions {
3191 /**
3192 * path to image.
3193 */
3194 file: string;
3195
3196 /**
3197 * path to w3mimgdisplay. if a proper w3mimgdisplay path is not given, blessed will search the
3198 * entire disk for the binary.
3199 */
3200 type: "ansi" | "overlay" | "w3m";
3201 }
3202
3203 /**
3204 * Display an image in the terminal (jpeg, png, gif) using w3mimgdisplay. Requires w3m to be installed.
3205 * X11 required: works in xterm, urxvt, and possibly other terminals.
3206 */
3207 class ImageElement extends BoxElement implements IHasOptions<ImageOptions> {
3208 constructor(options?: ImageOptions);
3209
3210 options: ImageOptions;
3211 }
3212
3213 interface ANSIImageOptions extends BoxOptions {
3214 /**
3215 * URL or path to PNG/GIF file. Can also be a buffer.
3216 */
3217 file: string;
3218
3219 /**
3220 * Scale cellmap down (0-1.0) from its original pixel width/height (Default: 1.0).
3221 */
3222 scale: number;
3223
3224 /**
3225 * This differs from other element's width or height in that only one
3226 * of them is needed: blessed will maintain the aspect ratio of the image
3227 * as it scales down to the proper number of cells. NOTE: PNG/GIF's are
3228 * always automatically shrunken to size (based on scale) if a width or
3229 * height is not given.
3230 */
3231 width: number | string;
3232 height: number | string;
3233
3234 /**
3235 * Add various "density" ASCII characters over the rendering to give the
3236 * image more detail, similar to libcaca/libcucul (the library mplayer uses
3237 * to display videos in the terminal).
3238 */
3239 ascii: string;
3240
3241 /**
3242 * Whether to animate if the image is an APNG/animating GIF. If false, only
3243 * display the first frame or IDAT (Default: true).
3244 */
3245 animate: boolean;
3246
3247 /**
3248 * Set the speed of animation. Slower: 0.0-1.0. Faster: 1-1000. It cannot go
3249 * faster than 1 frame per millisecond, so 1000 is the fastest. (Default: 1.0)
3250 */
3251 speed: number;
3252
3253 /**
3254 * mem or cpu. If optimizing for memory, animation frames will be rendered to
3255 * bitmaps as the animation plays, using less memory. Optimizing for cpu will
3256 * precompile all bitmaps beforehand, which may be faster, but might also OOM
3257 * the process on large images. (Default: mem).
3258 */
3259 optimization: "mem" | "cpu";
3260 }
3261
3262 /**
3263 * Convert any .png file (or .gif, see below) to an ANSI image and display it as an element.
3264 */
3265 class ANSIImageElement extends BoxElement implements IHasOptions<ANSIImageOptions> {
3266 constructor(options?: ANSIImageOptions);
3267
3268 options: ANSIImageOptions;
3269
3270 /**
3271 * Image object from the png reader.
3272 */
3273 img: Types.TImage;
3274
3275 /**
3276 * set the image in the box to a new path.
3277 */
3278 setImage(img: string, callback: () => void): void;
3279
3280 /**
3281 * clear the current image.
3282 */
3283 clearImage(callback: () => void): void;
3284
3285 /**
3286 * Play animation if it has been paused or stopped.
3287 */
3288 play(): void;
3289
3290 /**
3291 * Pause animation.
3292 */
3293 pause(): void;
3294
3295 /**
3296 * Stop animation.
3297 */
3298 stop(): void;
3299 }
3300
3301 interface OverlayImageOptions extends BoxOptions {
3302 /**
3303 * Path to image.
3304 */
3305 file: string;
3306
3307 /**
3308 * Render the file as ANSI art instead of using w3m to overlay Internally uses the
3309 * ANSIImage element. See the ANSIImage element for more information/options. (Default: true).
3310 */
3311 ansi: boolean;
3312
3313 /**
3314 * Path to w3mimgdisplay. If a proper w3mimgdisplay path is not given, blessed will
3315 * search the entire disk for the binary.
3316 */
3317 w3m: string;
3318
3319 /**
3320 * Whether to search /usr, /bin, and /lib for w3mimgdisplay (Default: true).
3321 */
3322 search: string;
3323 }
3324
3325 /**
3326 * Convert any .png file (or .gif, see below) to an ANSI image and display it as an element.
3327 */
3328 class OverlayImageElement extends BoxElement implements IHasOptions<OverlayImageOptions> {
3329 constructor(options?: OverlayImageOptions);
3330
3331 options: OverlayImageOptions;
3332
3333 /**
3334 * set the image in the box to a new path.
3335 */
3336 setImage(img: string, callback: () => void): void;
3337
3338 /**
3339 * clear the current image.
3340 */
3341 clearImage(callback: () => void): void;
3342
3343 /**
3344 * get the size of an image file in pixels.
3345 */
3346 imageSize(img: string, callback: () => void): void;
3347
3348 /**
3349 * get the size of the terminal in pixels.
3350 */
3351 termSize(callback: () => void): void;
3352
3353 /**
3354 * get the pixel to cell ratio for the terminal.
3355 */
3356 getPixelRatio(callback: () => void): void;
3357 }
3358
3359 interface VideoOptions extends BoxOptions {
3360 /**
3361 * Video to play.
3362 */
3363 file: string;
3364
3365 /**
3366 * Start time in seconds.
3367 */
3368 start: number;
3369 }
3370
3371 class VideoElement extends BoxElement implements IHasOptions<VideoOptions> {
3372 constructor(options?: VideoOptions);
3373
3374 options: VideoOptions;
3375
3376 /**
3377 * The terminal element running mplayer or mpv.
3378 */
3379 tty: any;
3380 }
3381
3382 interface LayoutOptions extends ElementOptions {
3383 /**
3384 * A callback which is called right before the children are iterated over to be rendered. Should return an
3385 * iterator callback which is called on each child element: iterator(el, i).
3386 */
3387 renderer?(): void;
3388
3389 /**
3390 * Using the default renderer, it provides two layouts: inline, and grid. inline is the default and will render
3391 * akin to inline-block. grid will create an automatic grid based on element dimensions. The grid cells'
3392 * width and height are always determined by the largest children in the layout.
3393 */
3394 layout: "inline" | "inline-block" | "grid";
3395 }
3396
3397 class LayoutElement extends BlessedElement implements IHasOptions<LayoutOptions> {
3398 constructor(options?: LayoutOptions);
3399
3400 options: LayoutOptions;
3401
3402 /**
3403 * A callback which is called right before the children are iterated over to be rendered. Should return an
3404 * iterator callback which is called on each child element: iterator(el, i).
3405 */
3406 renderer(coords: PositionCoords): void;
3407
3408 /**
3409 * Check to see if a previous child element has been rendered and is visible on screen. This is only useful
3410 * for checking child elements that have already been attempted to be rendered! see the example below.
3411 */
3412 isRendered(el: BlessedElement): boolean;
3413
3414 /**
3415 * Get the last rendered and visible child element based on an index. This is useful for basing the position
3416 * of the current child element on the position of the last child element.
3417 */
3418 getLast(i: number): BlessedElement;
3419
3420 /**
3421 * Get the last rendered and visible child element coords based on an index. This is useful for basing the position
3422 * of the current child element on the position of the last child element. See the example below.
3423 */
3424 getLastCoords(i: number): PositionCoords;
3425 }
3426
3427 class Program {
3428 /**
3429 * Wrap the given text in terminal formatting codes corresponding to the given attribute
3430 * name. The `attr` string can be of the form `red fg` or `52 bg` where `52` is a 0-255
3431 * integer color number.
3432 */
3433 text(text: string, attr: string): string;
3434 }
3435}
3436
3437export namespace widget {
3438 class Terminal extends Widgets.TerminalElement {}
3439}
3440
3441export function screen(options?: Widgets.IScreenOptions): Widgets.Screen;
3442export function box(options?: Widgets.BoxOptions): Widgets.BoxElement;
3443export function text(options?: Widgets.TextOptions): Widgets.TextElement;
3444export function line(options?: Widgets.LineOptions): Widgets.LineElement;
3445export function scrollablebox(options?: Widgets.BoxOptions): Widgets.BoxElement;
3446export function scrollabletext(options?: Widgets.BoxOptions): Widgets.BoxElement;
3447export function bigtext(options?: Widgets.BigTextOptions): Widgets.BigTextElement;
3448export function list(options?: Widgets.ListOptions<Widgets.ListElementStyle>): Widgets.ListElement;
3449export function filemanager(options?: Widgets.FileManagerOptions): Widgets.FileManagerElement;
3450export function listtable(options?: Widgets.ListTableOptions): Widgets.ListTableElement;
3451export function listbar(options?: Widgets.ListbarOptions): Widgets.ListbarElement;
3452export function form<TFormData>(options?: Widgets.FormOptions): Widgets.FormElement<TFormData>;
3453export function input(options?: Widgets.InputOptions): Widgets.InputElement;
3454export function textarea(options?: Widgets.TextareaOptions): Widgets.TextareaElement;
3455export function textbox(options?: Widgets.TextboxOptions): Widgets.TextboxElement;
3456export function button(options?: Widgets.ButtonOptions): Widgets.ButtonElement;
3457export function checkbox(options?: Widgets.CheckboxOptions): Widgets.CheckboxElement;
3458export function radioset(options?: Widgets.RadioSetOptions): Widgets.RadioSetElement;
3459export function radiobutton(options?: Widgets.RadioButtonOptions): Widgets.RadioButtonElement;
3460export function table(options?: Widgets.TableOptions): Widgets.TableElement;
3461export function prompt(options?: Widgets.PromptOptions): Widgets.PromptElement;
3462export function question(options?: Widgets.QuestionOptions): Widgets.QuestionElement;
3463export function message(options?: Widgets.MessageOptions): Widgets.MessageElement;
3464export function loading(options?: Widgets.LoadingOptions): Widgets.LoadingElement;
3465export function log(options?: Widgets.LogOptions): Widgets.Log;
3466export function progressbar(options?: Widgets.ProgressBarOptions): Widgets.ProgressBarElement;
3467export function program(options?: Widgets.IScreenOptions): BlessedProgram;
3468export function terminal(options?: Widgets.TerminalOptions): Widgets.TerminalElement;
3469export function layout(options?: Widgets.LayoutOptions): Widgets.LayoutElement;
3470export function escape(text: string): string;
3471export function stripTags(text: string): string;
3472export function cleanTags(text: string): string;
3473export function generateTags(style: any, text: string): string;
3474export function parseTags(text: string, screen?: Widgets.Screen): string;
3475
3476export const colors: {
3477 match(hexColor: string): string;
3478};
3479
\No newline at end of file