5 import { IInputHandler, ITerminal } from './Interfaces';
6 import { C0 } from './EscapeSequences';
7 import { CHARSETS } from './Charsets';
10 * The terminal's standard implementation of IInputHandler, this handles all
11 * input from the Parser.
13 * Refer to http://invisible-island.net/xterm/ctlseqs/ctlseqs.html to understand
14 * each function's header comment.
16 export class InputHandler implements IInputHandler {
17 // TODO: We want to type _terminal when it's pulled into TS
18 constructor(private _terminal: any) { }
20 public addChar(char: string, code: number): void {
22 // calculate print space
23 // expensive call, therefore we save width in line buffer
24 const ch_width = wcwidth(code);
26 if (this._terminal.charset && this._terminal.charset[char]) {
27 char = this._terminal.charset[char];
30 let row = this._terminal.y + this._terminal.ybase;
32 // insert combining char in last cell
33 // FIXME: needs handling after cursor jumps
34 if (!ch_width && this._terminal.x) {
36 if (this._terminal.lines.get(row)[this._terminal.x - 1]) {
37 if (!this._terminal.lines.get(row)[this._terminal.x - 1][2]) {
39 // found empty cell after fullwidth, need to go 2 cells back
40 if (this._terminal.lines.get(row)[this._terminal.x - 2])
41 this._terminal.lines.get(row)[this._terminal.x - 2][1] += char;
44 this._terminal.lines.get(row)[this._terminal.x - 1][1] += char;
46 this._terminal.updateRange(this._terminal.y);
51 // goto next line if ch would overflow
52 // TODO: needs a global min terminal width of 2
53 if (this._terminal.x + ch_width - 1 >= this._terminal.cols) {
55 if (this._terminal.wraparoundMode) {
58 if (this._terminal.y > this._terminal.scrollBottom) {
60 this._terminal.scroll();
63 if (ch_width === 2) // FIXME: check for xterm behavior
67 row = this._terminal.y + this._terminal.ybase;
69 // insert mode: move characters to right
70 if (this._terminal.insertMode) {
71 // do this twice for a fullwidth char
72 for (let moves = 0; moves < ch_width; ++moves) {
73 // remove last cell, if it's width is 0
74 // we have to adjust the second last cell as well
75 const removed = this._terminal.lines.get(this._terminal.y + this._terminal.ybase).pop();
77 && this._terminal.lines.get(row)[this._terminal.cols - 2]
78 && this._terminal.lines.get(row)[this._terminal.cols - 2][2] === 2)
79 this._terminal.lines.get(row)[this._terminal.cols - 2] = [this._terminal.curAttr, ' ', 1];
81 // insert empty cell at cursor
82 this._terminal.lines.get(row).splice(this._terminal.x, 0, [this._terminal.curAttr, ' ', 1]);
86 this._terminal.lines.get(row)[this._terminal.x] = [this._terminal.curAttr, char, ch_width];
88 this._terminal.updateRange(this._terminal.y);
90 // fullwidth char - set next cell width to zero and advance cursor
92 this._terminal.lines.get(row)[this._terminal.x] = [this._terminal.curAttr, '', 0];
102 public bell(): void {
103 if (!this._terminal.visualBell) {
106 this._terminal.element.style.borderColor = 'white';
107 setTimeout(() => this._terminal.element.style.borderColor = '', 10);
108 if (this._terminal.popOnBell) {
109 this._terminal.focus();
115 * Line Feed or New Line (NL). (LF is Ctrl-J).
117 public lineFeed(): void {
118 if (this._terminal.convertEol) {
119 this._terminal.x = 0;
122 if (this._terminal.y > this._terminal.scrollBottom) {
124 this._terminal.scroll();
126 // If the end of the line is hit, prevent this action from wrapping around to the next line.
127 if (this._terminal.x >= this._terminal.cols) {
134 * Carriage Return (Ctrl-M).
136 public carriageReturn(): void {
137 this._terminal.x = 0;
142 * Backspace (Ctrl-H).
144 public backspace(): void {
145 if (this._terminal.x > 0) {
152 * Horizontal Tab (HT) (Ctrl-I).
155 this._terminal.x = this._terminal.nextStop();
160 * Shift Out (Ctrl-N) -> Switch to Alternate Character Set. This invokes the
163 public shiftOut(): void {
164 this._terminal.setgLevel(1);
169 * Shift In (Ctrl-O) -> Switch to Standard Character Set. This invokes the G0
170 * character set (the default).
172 public shiftIn(): void {
173 this._terminal.setgLevel(0);
178 * Insert Ps (Blank) Character(s) (default = 1) (ICH).
180 public insertChars(params: number[]): void {
181 let param, row, j, ch;
184 if (param < 1) param = 1;
186 row = this._terminal.y + this._terminal.ybase;
187 j = this._terminal.x;
188 ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
190 while (param-- && j < this._terminal.cols) {
191 this._terminal.lines.get(row).splice(j++, 0, ch);
192 this._terminal.lines.get(row).pop();
198 * Cursor Up Ps Times (default = 1) (CUU).
200 public cursorUp(params: number[]): void {
201 let param = params[0];
205 this._terminal.y -= param;
206 if (this._terminal.y < 0) {
207 this._terminal.y = 0;
213 * Cursor Down Ps Times (default = 1) (CUD).
215 public cursorDown(params: number[]) {
216 let param = params[0];
220 this._terminal.y += param;
221 if (this._terminal.y >= this._terminal.rows) {
222 this._terminal.y = this._terminal.rows - 1;
224 // If the end of the line is hit, prevent this action from wrapping around to the next line.
225 if (this._terminal.x >= this._terminal.cols) {
232 * Cursor Forward Ps Times (default = 1) (CUF).
234 public cursorForward(params: number[]) {
235 let param = params[0];
239 this._terminal.x += param;
240 if (this._terminal.x >= this._terminal.cols) {
241 this._terminal.x = this._terminal.cols - 1;
247 * Cursor Backward Ps Times (default = 1) (CUB).
249 public cursorBackward(params: number[]) {
250 let param = params[0];
254 // If the end of the line is hit, prevent this action from wrapping around to the next line.
255 if (this._terminal.x >= this._terminal.cols) {
258 this._terminal.x -= param;
259 if (this._terminal.x < 0) {
260 this._terminal.x = 0;
266 * Cursor Next Line Ps Times (default = 1) (CNL).
269 public cursorNextLine(params: number[]): void {
270 let param = params[0];
274 this._terminal.y += param;
275 if (this._terminal.y >= this._terminal.rows) {
276 this._terminal.y = this._terminal.rows - 1;
278 this._terminal.x = 0;
284 * Cursor Preceding Line Ps Times (default = 1) (CNL).
287 public cursorPrecedingLine(params: number[]): void {
288 let param = params[0];
292 this._terminal.y -= param;
293 if (this._terminal.y < 0) {
294 this._terminal.y = 0;
296 this._terminal.x = 0;
302 * Cursor Character Absolute [column] (default = [row,1]) (CHA).
304 public cursorCharAbsolute(params: number[]): void {
305 let param = params[0];
309 this._terminal.x = param - 1;
314 * Cursor Position [row;column] (default = [1,1]) (CUP).
316 public cursorPosition(params: number[]): void {
321 if (params.length >= 2) {
329 } else if (row >= this._terminal.rows) {
330 row = this._terminal.rows - 1;
335 } else if (col >= this._terminal.cols) {
336 col = this._terminal.cols - 1;
339 this._terminal.x = col;
340 this._terminal.y = row;
345 * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
347 public cursorForwardTab(params: number[]): void {
348 let param = params[0] || 1;
350 this._terminal.x = this._terminal.nextStop();
355 * CSI Ps J Erase in Display (ED).
356 * Ps = 0 -> Erase Below (default).
357 * Ps = 1 -> Erase Above.
358 * Ps = 2 -> Erase All.
359 * Ps = 3 -> Erase Saved Lines (xterm).
361 * Erase in Display (DECSED).
362 * Ps = 0 -> Selective Erase Below (default).
363 * Ps = 1 -> Selective Erase Above.
364 * Ps = 2 -> Selective Erase All.
366 public eraseInDisplay(params: number[]): void {
370 this._terminal.eraseRight(this._terminal.x, this._terminal.y);
371 j = this._terminal.y + 1;
372 for (; j < this._terminal.rows; j++) {
373 this._terminal.eraseLine(j);
377 this._terminal.eraseLeft(this._terminal.x, this._terminal.y);
378 j = this._terminal.y;
380 this._terminal.eraseLine(j);
384 j = this._terminal.rows;
385 while (j--) this._terminal.eraseLine(j);
394 * CSI Ps K Erase in Line (EL).
395 * Ps = 0 -> Erase to Right (default).
396 * Ps = 1 -> Erase to Left.
397 * Ps = 2 -> Erase All.
399 * Erase in Line (DECSEL).
400 * Ps = 0 -> Selective Erase to Right (default).
401 * Ps = 1 -> Selective Erase to Left.
402 * Ps = 2 -> Selective Erase All.
404 public eraseInLine(params: number[]): void {
407 this._terminal.eraseRight(this._terminal.x, this._terminal.y);
410 this._terminal.eraseLeft(this._terminal.x, this._terminal.y);
413 this._terminal.eraseLine(this._terminal.y);
420 * Insert Ps Line(s) (default = 1) (IL).
422 public insertLines(params: number[]): void {
429 row = this._terminal.y + this._terminal.ybase;
431 j = this._terminal.rows - 1 - this._terminal.scrollBottom;
432 j = this._terminal.rows - 1 + this._terminal.ybase - j + 1;
435 if (this._terminal.lines.length === this._terminal.lines.maxLength) {
436 // Trim the start of lines to make room for the new line
437 this._terminal.lines.trimStart(1);
438 this._terminal.ybase--;
439 this._terminal.ydisp--;
443 // test: echo -e '\e[44m\e[1L\e[0m'
444 // blankLine(true) - xterm/linux behavior
445 this._terminal.lines.splice(row, 0, this._terminal.blankLine(true));
446 this._terminal.lines.splice(j, 1);
450 this._terminal.updateRange(this._terminal.y);
451 this._terminal.updateRange(this._terminal.scrollBottom);
456 * Delete Ps Line(s) (default = 1) (DL).
458 public deleteLines(params: number[]): void {
465 row = this._terminal.y + this._terminal.ybase;
467 j = this._terminal.rows - 1 - this._terminal.scrollBottom;
468 j = this._terminal.rows - 1 + this._terminal.ybase - j;
471 if (this._terminal.lines.length === this._terminal.lines.maxLength) {
472 // Trim the start of lines to make room for the new line
473 this._terminal.lines.trimStart(1);
474 this._terminal.ybase -= 1;
475 this._terminal.ydisp -= 1;
477 // test: echo -e '\e[44m\e[1M\e[0m'
478 // blankLine(true) - xterm/linux behavior
479 this._terminal.lines.splice(j + 1, 0, this._terminal.blankLine(true));
480 this._terminal.lines.splice(row, 1);
484 this._terminal.updateRange(this._terminal.y);
485 this._terminal.updateRange(this._terminal.scrollBottom);
490 * Delete Ps Character(s) (default = 1) (DCH).
492 public deleteChars(params: number[]): void {
500 row = this._terminal.y + this._terminal.ybase;
501 ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
504 this._terminal.lines.get(row).splice(this._terminal.x, 1);
505 this._terminal.lines.get(row).push(ch);
510 * CSI Ps S Scroll up Ps lines (default = 1) (SU).
512 public scrollUp(params: number[]): void {
513 let param = params[0] || 1;
515 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 1);
516 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 0, this._terminal.blankLine());
519 this._terminal.updateRange(this._terminal.scrollTop);
520 this._terminal.updateRange(this._terminal.scrollBottom);
524 * CSI Ps T Scroll down Ps lines (default = 1) (SD).
526 public scrollDown(params: number[]): void {
527 let param = params[0] || 1;
529 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 1);
530 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 0, this._terminal.blankLine());
533 this._terminal.updateRange(this._terminal.scrollTop);
534 this._terminal.updateRange(this._terminal.scrollBottom);
539 * Erase Ps Character(s) (default = 1) (ECH).
541 public eraseChars(params: number[]): void {
542 let param, row, j, ch;
549 row = this._terminal.y + this._terminal.ybase;
550 j = this._terminal.x;
551 ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
553 while (param-- && j < this._terminal.cols) {
554 this._terminal.lines.get(row)[j++] = ch;
559 * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
561 public cursorBackwardTab(params: number[]): void {
562 let param = params[0] || 1;
564 this._terminal.x = this._terminal.prevStop();
569 * CSI Pm ` Character Position Absolute
570 * [column] (default = [row,1]) (HPA).
572 public charPosAbsolute(params: number[]): void {
573 let param = params[0];
577 this._terminal.x = param - 1;
578 if (this._terminal.x >= this._terminal.cols) {
579 this._terminal.x = this._terminal.cols - 1;
584 * CSI Pm a Character Position Relative
585 * [columns] (default = [row,col+1]) (HPR)
588 public HPositionRelative(params: number[]): void {
589 let param = params[0];
593 this._terminal.x += param;
594 if (this._terminal.x >= this._terminal.cols) {
595 this._terminal.x = this._terminal.cols - 1;
600 * CSI Ps b Repeat the preceding graphic character Ps times (REP).
602 public repeatPrecedingCharacter(params: number[]): void {
603 let param = params[0] || 1
604 , line = this._terminal.lines.get(this._terminal.ybase + this._terminal.y)
605 , ch = line[this._terminal.x - 1] || [this._terminal.defAttr, ' ', 1];
608 line[this._terminal.x++] = ch;
613 * CSI Ps c Send Device Attributes (Primary DA).
614 * Ps = 0 or omitted -> request attributes from terminal. The
615 * response depends on the decTerminalID resource setting.
616 * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
617 * -> CSI ? 1 ; 0 c (``VT101 with No Options'')
618 * -> CSI ? 6 c (``VT102'')
619 * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
620 * The VT100-style response parameters do not mean anything by
621 * themselves. VT220 parameters do, telling the host what fea-
622 * tures the terminal supports:
623 * Ps = 1 -> 132-columns.
625 * Ps = 6 -> Selective erase.
626 * Ps = 8 -> User-defined keys.
627 * Ps = 9 -> National replacement character sets.
628 * Ps = 1 5 -> Technical characters.
629 * Ps = 2 2 -> ANSI color, e.g., VT525.
630 * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
632 * Send Device Attributes (Secondary DA).
633 * Ps = 0 or omitted -> request the terminal's identification
634 * code. The response depends on the decTerminalID resource set-
635 * ting. It should apply only to VT220 and up, but xterm extends
637 * -> CSI > Pp ; Pv ; Pc c
638 * where Pp denotes the terminal type
639 * Pp = 0 -> ``VT100''.
640 * Pp = 1 -> ``VT220''.
641 * and Pv is the firmware version (for xterm, this was originally
642 * the XFree86 patch number, starting with 95). In a DEC termi-
643 * nal, Pc indicates the ROM cartridge registration number and is
646 * xterm/charproc.c - line 2012, for more information.
647 * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
649 public sendDeviceAttributes(params: number[]): void {
654 if (!this._terminal.prefix) {
655 if (this._terminal.is('xterm') || this._terminal.is('rxvt-unicode') || this._terminal.is('screen')) {
656 this._terminal.send(C0.ESC + '[?1;2c');
657 } else if (this._terminal.is('linux')) {
658 this._terminal.send(C0.ESC + '[?6c');
660 } else if (this._terminal.prefix === '>') {
663 // out around ~370 times (?).
664 if (this._terminal.is('xterm')) {
665 this._terminal.send(C0.ESC + '[>0;276;0c');
666 } else if (this._terminal.is('rxvt-unicode')) {
667 this._terminal.send(C0.ESC + '[>85;95;0c');
668 } else if (this._terminal.is('linux')) {
669 // not supported by linux console.
670 // linux console echoes parameters.
671 this._terminal.send(params[0] + 'c');
672 } else if (this._terminal.is('screen')) {
673 this._terminal.send(C0.ESC + '[>83;40003;0c');
679 * CSI Pm d Vertical Position Absolute (VPA)
680 * [row] (default = [1,column])
682 public linePosAbsolute(params: number[]): void {
683 let param = params[0];
687 this._terminal.y = param - 1;
688 if (this._terminal.y >= this._terminal.rows) {
689 this._terminal.y = this._terminal.rows - 1;
694 * CSI Pm e Vertical Position Relative (VPR)
695 * [rows] (default = [row+1,column])
698 public VPositionRelative(params: number[]): void {
699 let param = params[0];
703 this._terminal.y += param;
704 if (this._terminal.y >= this._terminal.rows) {
705 this._terminal.y = this._terminal.rows - 1;
707 // If the end of the line is hit, prevent this action from wrapping around to the next line.
708 if (this._terminal.x >= this._terminal.cols) {
715 * Horizontal and Vertical Position [row;column] (default =
718 public HVPosition(params: number[]): void {
719 if (params[0] < 1) params[0] = 1;
720 if (params[1] < 1) params[1] = 1;
722 this._terminal.y = params[0] - 1;
723 if (this._terminal.y >= this._terminal.rows) {
724 this._terminal.y = this._terminal.rows - 1;
727 this._terminal.x = params[1] - 1;
728 if (this._terminal.x >= this._terminal.cols) {
729 this._terminal.x = this._terminal.cols - 1;
734 * CSI Ps g Tab Clear (TBC).
735 * Ps = 0 -> Clear Current Column (default).
736 * Ps = 3 -> Clear All.
738 * Ps = 2 -> Clear Stops on Line.
739 * http://vt100.net/annarbor/aaa-ug/section6.html
741 public tabClear(params: number[]): void {
742 let param = params[0];
744 delete this._terminal.tabs[this._terminal.x];
745 } else if (param === 3) {
746 this._terminal.tabs = {};
751 * CSI Pm h Set Mode (SM).
752 * Ps = 2 -> Keyboard Action Mode (AM).
753 * Ps = 4 -> Insert Mode (IRM).
754 * Ps = 1 2 -> Send/receive (SRM).
755 * Ps = 2 0 -> Automatic Newline (LNM).
757 * DEC Private Mode Set (DECSET).
758 * Ps = 1 -> Application Cursor Keys (DECCKM).
759 * Ps = 2 -> Designate USASCII for character sets G0-G3
760 * (DECANM), and set VT100 mode.
761 * Ps = 3 -> 132 Column Mode (DECCOLM).
762 * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
763 * Ps = 5 -> Reverse Video (DECSCNM).
764 * Ps = 6 -> Origin Mode (DECOM).
765 * Ps = 7 -> Wraparound Mode (DECAWM).
766 * Ps = 8 -> Auto-repeat Keys (DECARM).
767 * Ps = 9 -> Send Mouse X & Y on button press. See the sec-
768 * tion Mouse Tracking.
769 * Ps = 1 0 -> Show toolbar (rxvt).
770 * Ps = 1 2 -> Start Blinking Cursor (att610).
771 * Ps = 1 8 -> Print form feed (DECPFF).
772 * Ps = 1 9 -> Set print extent to full screen (DECPEX).
773 * Ps = 2 5 -> Show Cursor (DECTCEM).
774 * Ps = 3 0 -> Show scrollbar (rxvt).
775 * Ps = 3 5 -> Enable font-shifting functions (rxvt).
776 * Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
777 * Ps = 4 0 -> Allow 80 -> 132 Mode.
778 * Ps = 4 1 -> more(1) fix (see curses resource).
779 * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
781 * Ps = 4 4 -> Turn On Margin Bell.
782 * Ps = 4 5 -> Reverse-wraparound Mode.
783 * Ps = 4 6 -> Start Logging. This is normally disabled by a
784 * compile-time option.
785 * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
786 * abled by the titeInhibit resource).
787 * Ps = 6 6 -> Application keypad (DECNKM).
788 * Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
789 * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
790 * release. See the section Mouse Tracking.
791 * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
792 * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
793 * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
794 * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
795 * Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
796 * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
797 * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
798 * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
799 * (enables the eightBitInput resource).
800 * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
801 * Lock keys. (This enables the numLock resource).
802 * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
803 * enables the metaSendsEscape resource).
804 * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
806 * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
807 * enables the altSendsEscape resource).
808 * Ps = 1 0 4 0 -> Keep selection even if not highlighted.
809 * (This enables the keepSelection resource).
810 * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
811 * the selectToClipboard resource).
812 * Ps = 1 0 4 2 -> Enable Urgency window manager hint when
813 * Control-G is received. (This enables the bellIsUrgent
815 * Ps = 1 0 4 3 -> Enable raising of the window when Control-G
816 * is received. (enables the popOnBell resource).
817 * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
818 * disabled by the titeInhibit resource).
819 * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
820 * abled by the titeInhibit resource).
821 * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
822 * Screen Buffer, clearing it first. (This may be disabled by
823 * the titeInhibit resource). This combines the effects of the 1
824 * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
825 * applications rather than the 4 7 mode.
826 * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
827 * Ps = 1 0 5 1 -> Set Sun function-key mode.
828 * Ps = 1 0 5 2 -> Set HP function-key mode.
829 * Ps = 1 0 5 3 -> Set SCO function-key mode.
830 * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
831 * Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
832 * Ps = 2 0 0 4 -> Set bracketed paste mode.
834 * http: *vt100.net/docs/vt220-rm/chapter4.html
836 public setMode(params: number[]): void {
837 if (params.length > 1) {
838 for (let i = 0; i < params.length; i++) {
839 this._terminal.setMode(params[i]);
845 if (!this._terminal.prefix) {
848 this._terminal.insertMode = true;
851 // this._terminal.convertEol = true;
854 } else if (this._terminal.prefix === '?') {
857 this._terminal.applicationCursor = true;
860 this._terminal.setgCharset(0, CHARSETS.US);
861 this._terminal.setgCharset(1, CHARSETS.US);
862 this._terminal.setgCharset(2, CHARSETS.US);
863 this._terminal.setgCharset(3, CHARSETS.US);
864 // set VT100 mode here
866 case 3: // 132 col mode
867 this._terminal.savedCols = this._terminal.cols;
868 this._terminal.resize(132, this._terminal.rows);
871 this._terminal.originMode = true;
874 this._terminal.wraparoundMode = true;
877 // this.cursorBlink = true;
880 this._terminal.log('Serial port requested application keypad.');
881 this._terminal.applicationKeypad = true;
882 this._terminal.viewport.syncScrollArea();
885 // no release, no motion, no wheel, no modifiers.
886 case 1000: // vt200 mouse
888 // no modifiers, except control on the wheel.
889 case 1002: // button event mouse
890 case 1003: // any event mouse
891 // any event - sends motion events,
892 // even if there is no button held down.
894 // TODO: Why are params[0] compares nested within a switch for params[0]?
896 this._terminal.x10Mouse = params[0] === 9;
897 this._terminal.vt200Mouse = params[0] === 1000;
898 this._terminal.normalMouse = params[0] > 1000;
899 this._terminal.mouseEvents = true;
900 this._terminal.element.style.cursor = 'default';
901 this._terminal.log('Binding to mouse events.');
903 case 1004: // send focusin/focusout events
906 this._terminal.sendFocus = true;
908 case 1005: // utf8 ext mode mouse
909 this._terminal.utfMouse = true;
910 // for wide terminals
911 // simply encodes large values as utf8 characters
913 case 1006: // sgr ext mode mouse
914 this._terminal.sgrMouse = true;
915 // for wide terminals
916 // does not add 32 to fields
918 // release: ^[[<b;x;ym
920 case 1015: // urxvt ext mode mouse
921 this._terminal.urxvtMouse = true;
922 // for wide terminals
923 // numbers for fields
927 case 25: // show cursor
928 this._terminal.cursorHidden = false;
930 case 1049: // alt screen buffer cursor
931 // this._terminal.saveCursor();
933 case 47: // alt screen buffer
934 case 1047: // alt screen buffer
935 if (!this._terminal.normal) {
937 lines: this._terminal.lines,
938 ybase: this._terminal.ybase,
939 ydisp: this._terminal.ydisp,
942 scrollTop: this._terminal.scrollTop,
943 scrollBottom: this._terminal.scrollBottom,
944 tabs: this._terminal.tabs
945 // XXX save charset(s) here?
946 // charset: this._terminal.charset,
947 // glevel: this._terminal.glevel,
948 // charsets: this._terminal.charsets
950 this._terminal.reset();
951 this._terminal.viewport.syncScrollArea();
952 this._terminal.normal = normal;
953 this._terminal.showCursor();
961 * CSI Pm l Reset Mode (RM).
962 * Ps = 2 -> Keyboard Action Mode (AM).
963 * Ps = 4 -> Replace Mode (IRM).
964 * Ps = 1 2 -> Send/receive (SRM).
965 * Ps = 2 0 -> Normal Linefeed (LNM).
967 * DEC Private Mode Reset (DECRST).
968 * Ps = 1 -> Normal Cursor Keys (DECCKM).
969 * Ps = 2 -> Designate VT52 mode (DECANM).
970 * Ps = 3 -> 80 Column Mode (DECCOLM).
971 * Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
972 * Ps = 5 -> Normal Video (DECSCNM).
973 * Ps = 6 -> Normal Cursor Mode (DECOM).
974 * Ps = 7 -> No Wraparound Mode (DECAWM).
975 * Ps = 8 -> No Auto-repeat Keys (DECARM).
976 * Ps = 9 -> Don't send Mouse X & Y on button press.
977 * Ps = 1 0 -> Hide toolbar (rxvt).
978 * Ps = 1 2 -> Stop Blinking Cursor (att610).
979 * Ps = 1 8 -> Don't print form feed (DECPFF).
980 * Ps = 1 9 -> Limit print to scrolling region (DECPEX).
981 * Ps = 2 5 -> Hide Cursor (DECTCEM).
982 * Ps = 3 0 -> Don't show scrollbar (rxvt).
983 * Ps = 3 5 -> Disable font-shifting functions (rxvt).
984 * Ps = 4 0 -> Disallow 80 -> 132 Mode.
985 * Ps = 4 1 -> No more(1) fix (see curses resource).
986 * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
988 * Ps = 4 4 -> Turn Off Margin Bell.
989 * Ps = 4 5 -> No Reverse-wraparound Mode.
990 * Ps = 4 6 -> Stop Logging. (This is normally disabled by a
991 * compile-time option).
992 * Ps = 4 7 -> Use Normal Screen Buffer.
993 * Ps = 6 6 -> Numeric keypad (DECNKM).
994 * Ps = 6 7 -> Backarrow key sends delete (DECBKM).
995 * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
996 * release. See the section Mouse Tracking.
997 * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
998 * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
999 * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
1000 * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
1001 * Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
1002 * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
1004 * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
1005 * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
1006 * the eightBitInput resource).
1007 * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
1008 * Lock keys. (This disables the numLock resource).
1009 * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
1010 * (This disables the metaSendsEscape resource).
1011 * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
1013 * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
1014 * (This disables the altSendsEscape resource).
1015 * Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
1016 * (This disables the keepSelection resource).
1017 * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
1018 * the selectToClipboard resource).
1019 * Ps = 1 0 4 2 -> Disable Urgency window manager hint when
1020 * Control-G is received. (This disables the bellIsUrgent
1022 * Ps = 1 0 4 3 -> Disable raising of the window when Control-
1023 * G is received. (This disables the popOnBell resource).
1024 * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
1025 * first if in the Alternate Screen. (This may be disabled by
1026 * the titeInhibit resource).
1027 * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
1028 * disabled by the titeInhibit resource).
1029 * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
1030 * as in DECRC. (This may be disabled by the titeInhibit
1031 * resource). This combines the effects of the 1 0 4 7 and 1 0
1032 * 4 8 modes. Use this with terminfo-based applications rather
1033 * than the 4 7 mode.
1034 * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
1035 * Ps = 1 0 5 1 -> Reset Sun function-key mode.
1036 * Ps = 1 0 5 2 -> Reset HP function-key mode.
1037 * Ps = 1 0 5 3 -> Reset SCO function-key mode.
1038 * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
1039 * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
1040 * Ps = 2 0 0 4 -> Reset bracketed paste mode.
1042 public resetMode(params: number[]): void {
1043 if (params.length > 1) {
1044 for (let i = 0; i < params.length; i++) {
1045 this._terminal.resetMode(params[i]);
1051 if (!this._terminal.prefix) {
1052 switch (params[0]) {
1054 this._terminal.insertMode = false;
1057 // this._terminal.convertEol = false;
1060 } else if (this._terminal.prefix === '?') {
1061 switch (params[0]) {
1063 this._terminal.applicationCursor = false;
1066 if (this._terminal.cols === 132 && this._terminal.savedCols) {
1067 this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
1069 delete this._terminal.savedCols;
1072 this._terminal.originMode = false;
1075 this._terminal.wraparoundMode = false;
1078 // this.cursorBlink = false;
1081 this._terminal.log('Switching back to normal keypad.');
1082 this._terminal.applicationKeypad = false;
1083 this._terminal.viewport.syncScrollArea();
1085 case 9: // X10 Mouse
1086 case 1000: // vt200 mouse
1087 case 1002: // button event mouse
1088 case 1003: // any event mouse
1089 this._terminal.x10Mouse = false;
1090 this._terminal.vt200Mouse = false;
1091 this._terminal.normalMouse = false;
1092 this._terminal.mouseEvents = false;
1093 this._terminal.element.style.cursor = '';
1095 case 1004: // send focusin/focusout events
1096 this._terminal.sendFocus = false;
1098 case 1005: // utf8 ext mode mouse
1099 this._terminal.utfMouse = false;
1101 case 1006: // sgr ext mode mouse
1102 this._terminal.sgrMouse = false;
1104 case 1015: // urxvt ext mode mouse
1105 this._terminal.urxvtMouse = false;
1107 case 25: // hide cursor
1108 this._terminal.cursorHidden = true;
1110 case 1049: // alt screen buffer cursor
1112 case 47: // normal screen buffer
1113 case 1047: // normal screen buffer - clearing it first
1114 if (this._terminal.normal) {
1115 this._terminal.lines = this._terminal.normal.lines;
1116 this._terminal.ybase = this._terminal.normal.ybase;
1117 this._terminal.ydisp = this._terminal.normal.ydisp;
1118 this._terminal.x = this._terminal.normal.x;
1119 this._terminal.y = this._terminal.normal.y;
1120 this._terminal.scrollTop = this._terminal.normal.scrollTop;
1121 this._terminal.scrollBottom = this._terminal.normal.scrollBottom;
1122 this._terminal.tabs = this._terminal.normal.tabs;
1123 this._terminal.normal = null;
1124 // if (params === 1049) {
1125 // this.x = this.savedX;
1126 // this.y = this.savedY;
1128 this._terminal.queueRefresh(0, this._terminal.rows - 1);
1129 this._terminal.viewport.syncScrollArea();
1130 this._terminal.showCursor();
1138 * CSI Pm m Character Attributes (SGR).
1139 * Ps = 0 -> Normal (default).
1141 * Ps = 4 -> Underlined.
1142 * Ps = 5 -> Blink (appears as Bold).
1143 * Ps = 7 -> Inverse.
1144 * Ps = 8 -> Invisible, i.e., hidden (VT300).
1145 * Ps = 2 2 -> Normal (neither bold nor faint).
1146 * Ps = 2 4 -> Not underlined.
1147 * Ps = 2 5 -> Steady (not blinking).
1148 * Ps = 2 7 -> Positive (not inverse).
1149 * Ps = 2 8 -> Visible, i.e., not hidden (VT300).
1150 * Ps = 3 0 -> Set foreground color to Black.
1151 * Ps = 3 1 -> Set foreground color to Red.
1152 * Ps = 3 2 -> Set foreground color to Green.
1153 * Ps = 3 3 -> Set foreground color to Yellow.
1154 * Ps = 3 4 -> Set foreground color to Blue.
1155 * Ps = 3 5 -> Set foreground color to Magenta.
1156 * Ps = 3 6 -> Set foreground color to Cyan.
1157 * Ps = 3 7 -> Set foreground color to White.
1158 * Ps = 3 9 -> Set foreground color to default (original).
1159 * Ps = 4 0 -> Set background color to Black.
1160 * Ps = 4 1 -> Set background color to Red.
1161 * Ps = 4 2 -> Set background color to Green.
1162 * Ps = 4 3 -> Set background color to Yellow.
1163 * Ps = 4 4 -> Set background color to Blue.
1164 * Ps = 4 5 -> Set background color to Magenta.
1165 * Ps = 4 6 -> Set background color to Cyan.
1166 * Ps = 4 7 -> Set background color to White.
1167 * Ps = 4 9 -> Set background color to default (original).
1169 * If 16-color support is compiled, the following apply. Assume
1170 * that xterm's resources are set so that the ISO color codes are
1171 * the first 8 of a set of 16. Then the aixterm colors are the
1172 * bright versions of the ISO colors:
1173 * Ps = 9 0 -> Set foreground color to Black.
1174 * Ps = 9 1 -> Set foreground color to Red.
1175 * Ps = 9 2 -> Set foreground color to Green.
1176 * Ps = 9 3 -> Set foreground color to Yellow.
1177 * Ps = 9 4 -> Set foreground color to Blue.
1178 * Ps = 9 5 -> Set foreground color to Magenta.
1179 * Ps = 9 6 -> Set foreground color to Cyan.
1180 * Ps = 9 7 -> Set foreground color to White.
1181 * Ps = 1 0 0 -> Set background color to Black.
1182 * Ps = 1 0 1 -> Set background color to Red.
1183 * Ps = 1 0 2 -> Set background color to Green.
1184 * Ps = 1 0 3 -> Set background color to Yellow.
1185 * Ps = 1 0 4 -> Set background color to Blue.
1186 * Ps = 1 0 5 -> Set background color to Magenta.
1187 * Ps = 1 0 6 -> Set background color to Cyan.
1188 * Ps = 1 0 7 -> Set background color to White.
1190 * If xterm is compiled with the 16-color support disabled, it
1191 * supports the following, from rxvt:
1192 * Ps = 1 0 0 -> Set foreground and background color to
1195 * If 88- or 256-color support is compiled, the following apply.
1196 * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
1198 * Ps = 4 8 ; 5 ; Ps -> Set background color to the second
1201 public charAttributes(params: number[]): void {
1202 // Optimize a single SGR0.
1203 if (params.length === 1 && params[0] === 0) {
1204 this._terminal.curAttr = this._terminal.defAttr;
1208 let l = params.length
1210 , flags = this._terminal.curAttr >> 18
1211 , fg = (this._terminal.curAttr >> 9) & 0x1ff
1212 , bg = this._terminal.curAttr & 0x1ff
1215 for (; i < l; i++) {
1217 if (p >= 30 && p <= 37) {
1220 } else if (p >= 40 && p <= 47) {
1223 } else if (p >= 90 && p <= 97) {
1227 } else if (p >= 100 && p <= 107) {
1231 } else if (p === 0) {
1233 flags = this._terminal.defAttr >> 18;
1234 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1235 bg = this._terminal.defAttr & 0x1ff;
1239 } else if (p === 1) {
1242 } else if (p === 4) {
1245 } else if (p === 5) {
1248 } else if (p === 7) {
1249 // inverse and positive
1250 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
1252 } else if (p === 8) {
1255 } else if (p === 22) {
1258 } else if (p === 24) {
1261 } else if (p === 25) {
1264 } else if (p === 27) {
1267 } else if (p === 28) {
1270 } else if (p === 39) {
1272 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1273 } else if (p === 49) {
1275 bg = this._terminal.defAttr & 0x1ff;
1276 } else if (p === 38) {
1278 if (params[i + 1] === 2) {
1280 fg = this._terminal.matchColor(
1282 params[i + 1] & 0xff,
1283 params[i + 2] & 0xff);
1284 if (fg === -1) fg = 0x1ff;
1286 } else if (params[i + 1] === 5) {
1288 p = params[i] & 0xff;
1291 } else if (p === 48) {
1293 if (params[i + 1] === 2) {
1295 bg = this._terminal.matchColor(
1297 params[i + 1] & 0xff,
1298 params[i + 2] & 0xff);
1299 if (bg === -1) bg = 0x1ff;
1301 } else if (params[i + 1] === 5) {
1303 p = params[i] & 0xff;
1306 } else if (p === 100) {
1308 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1309 bg = this._terminal.defAttr & 0x1ff;
1311 this._terminal.error('Unknown SGR attribute: %d.', p);
1315 this._terminal.curAttr = (flags << 18) | (fg << 9) | bg;
1319 * CSI Ps n Device Status Report (DSR).
1320 * Ps = 5 -> Status Report. Result (``OK'') is
1322 * Ps = 6 -> Report Cursor Position (CPR) [row;column].
1326 * Device Status Report (DSR, DEC-specific).
1327 * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
1328 * ? r ; c R (assumes page is zero).
1329 * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
1330 * or CSI ? 1 1 n (not ready).
1331 * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
1332 * or CSI ? 2 1 n (locked).
1333 * Ps = 2 6 -> Report Keyboard status as
1334 * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
1335 * The last two parameters apply to VT400 & up, and denote key-
1336 * board ready and LK01 respectively.
1337 * Ps = 5 3 -> Report Locator status as
1338 * CSI ? 5 3 n Locator available, if compiled-in, or
1339 * CSI ? 5 0 n No Locator, if not.
1341 public deviceStatus(params: number[]): void {
1342 if (!this._terminal.prefix) {
1343 switch (params[0]) {
1346 this._terminal.send(C0.ESC + '[0n');
1350 this._terminal.send(C0.ESC + '['
1351 + (this._terminal.y + 1)
1353 + (this._terminal.x + 1)
1357 } else if (this._terminal.prefix === '?') {
1358 // modern xterm doesnt seem to
1359 // respond to any of these except ?6, 6, and 5
1360 switch (params[0]) {
1363 this._terminal.send(C0.ESC + '[?'
1364 + (this._terminal.y + 1)
1366 + (this._terminal.x + 1)
1371 // this.send(C0.ESC + '[?11n');
1374 // dont support user defined keys
1375 // this.send(C0.ESC + '[?21n');
1378 // north american keyboard
1379 // this.send(C0.ESC + '[?27;1;0;0n');
1382 // no dec locator/mouse
1383 // this.send(C0.ESC + '[?50n');
1390 * CSI ! p Soft terminal reset (DECSTR).
1391 * http://vt100.net/docs/vt220-rm/table4-10.html
1393 public softReset(params: number[]): void {
1394 this._terminal.cursorHidden = false;
1395 this._terminal.insertMode = false;
1396 this._terminal.originMode = false;
1397 this._terminal.wraparoundMode = false; // autowrap
1398 this._terminal.applicationKeypad = false; // ?
1399 this._terminal.viewport.syncScrollArea();
1400 this._terminal.applicationCursor = false;
1401 this._terminal.scrollTop = 0;
1402 this._terminal.scrollBottom = this._terminal.rows - 1;
1403 this._terminal.curAttr = this._terminal.defAttr;
1404 this._terminal.x = this._terminal.y = 0; // ?
1405 this._terminal.charset = null;
1406 this._terminal.glevel = 0; // ??
1407 this._terminal.charsets = [null]; // ??
1411 * CSI Ps SP q Set cursor style (DECSCUSR, VT520).
1412 * Ps = 0 -> blinking block.
1413 * Ps = 1 -> blinking block (default).
1414 * Ps = 2 -> steady block.
1415 * Ps = 3 -> blinking underline.
1416 * Ps = 4 -> steady underline.
1417 * Ps = 5 -> blinking bar (xterm).
1418 * Ps = 6 -> steady bar (xterm).
1420 public setCursorStyle(params?: number[]): void {
1421 const param = params[0] < 1 ? 1 : params[0];
1425 this._terminal.setOption('cursorStyle', 'block');
1429 this._terminal.setOption('cursorStyle', 'underline');
1433 this._terminal.setOption('cursorStyle', 'bar');
1436 const isBlinking = param % 2 === 1;
1437 this._terminal.setOption('cursorBlink', isBlinking);
1442 * Set Scrolling Region [top;bottom] (default = full size of win-
1446 public setScrollRegion(params: number[]): void {
1447 if (this._terminal.prefix) return;
1448 this._terminal.scrollTop = (params[0] || 1) - 1;
1449 this._terminal.scrollBottom = (params[1] || this._terminal.rows) - 1;
1450 this._terminal.x = 0;
1451 this._terminal.y = 0;
1457 * Save cursor (ANSI.SYS).
1459 public saveCursor(params: number[]): void {
1460 this._terminal.savedX = this._terminal.x;
1461 this._terminal.savedY = this._terminal.y;
1467 * Restore cursor (ANSI.SYS).
1469 public restoreCursor(params: number[]): void {
1470 this._terminal.x = this._terminal.savedX || 0;
1471 this._terminal.y = this._terminal.savedY || 0;
1475 const wcwidth = (function(opts) {
1476 // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
1477 // combining characters
1479 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1480 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1481 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1482 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1483 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1484 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1485 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1486 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1487 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1488 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1489 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1490 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1491 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1492 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1493 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1494 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1495 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1496 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1497 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1498 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1499 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1500 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1501 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1502 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1503 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1504 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1505 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1506 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1507 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1508 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1509 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1510 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1511 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1512 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1513 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1514 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1515 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1516 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1517 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1518 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1519 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1520 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1521 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1522 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1523 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1524 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1525 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1529 function bisearch(ucs) {
1531 let max = COMBINING.length - 1;
1533 if (ucs < COMBINING[0][0] || ucs > COMBINING[max][1])
1535 while (max >= min) {
1536 mid = Math.floor((min + max) / 2);
1537 if (ucs > COMBINING[mid][1])
1539 else if (ucs < COMBINING[mid][0])
1546 function wcwidth(ucs) {
1547 // test for 8-bit control characters
1550 if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
1551 return opts.control;
1552 // binary search in table of non-spacing characters
1555 // if we arrive here, ucs is not a combining or C0/C1 control character
1561 function isWide(ucs) {
1564 ucs <= 0x115f || // Hangul Jamo init. consonants
1567 (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs !== 0x303f) || // CJK..Yi
1568 (ucs >= 0xac00 && ucs <= 0xd7a3) || // Hangul Syllables
1569 (ucs >= 0xf900 && ucs <= 0xfaff) || // CJK Compat Ideographs
1570 (ucs >= 0xfe10 && ucs <= 0xfe19) || // Vertical forms
1571 (ucs >= 0xfe30 && ucs <= 0xfe6f) || // CJK Compat Forms
1572 (ucs >= 0xff00 && ucs <= 0xff60) || // Fullwidth Forms
1573 (ucs >= 0xffe0 && ucs <= 0xffe6) ||
1574 (ucs >= 0x20000 && ucs <= 0x2fffd) ||
1575 (ucs >= 0x30000 && ucs <= 0x3fffd)));
1578 })({nul: 0, control: 0}); // configurable options