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