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