--- console-2.2.14.c 2000/03/08 01:42:00 1.1 +++ console-2.2.14.c 2000/03/14 16:53:03 1.17 @@ -66,6 +66,11 @@ * * Resurrected character buffers in videoram plus lots of other trickery * by Martin Mares , July 1998 + * + * ECMA-35 (ISO 2022), ECMA-48 (ISO 6429) and missing DEC VT-series functions + * by Dominik Kubla , February 1999 + * Adapted for 2.2.12 and changes conditionalized according to VTE_VERSION + * by Eric S. Raymond , March 2000. */ #include @@ -139,8 +144,8 @@ unsigned int cols, int do_clear); static void blank_screen(void); static void gotoxy(int currcons, int new_x, int new_y); -static void save_cur(int currcons); -static void reset_terminal(int currcons, int do_clear); +static void vte_decsc(int currcons); +static void vte_ris(int currcons, int do_clear); static void con_flush_chars(struct tty_struct *tty); static void set_vesa_blanking(unsigned long arg); static void set_cursor(int currcons); @@ -224,7 +229,7 @@ unsigned short *d, *s; if (t+nr >= b) - nr = b - t - 1; + nr = b - t; if (b > video_num_lines || t >= b || nr < 1) return; if (IS_VISIBLE && sw->con_scroll(vc_cons[currcons].d, t, b, SM_UP, nr)) @@ -242,7 +247,7 @@ unsigned int step; if (t+nr >= b) - nr = b - t - 1; + nr = b - t; if (b > video_num_lines || t >= b || nr < 1) return; if (IS_VISIBLE && sw->con_scroll(vc_cons[currcons].d, t, b, SM_DOWN, nr)) @@ -355,7 +360,7 @@ static void update_attr(int currcons) { attr = build_attr(currcons, color, intensity, blink, underline, reverse ^ decscnm); - video_erase_char = (build_attr(currcons, color, 1, 0, 0, decscnm) << 8) | ' '; + video_erase_char = (build_attr(currcons, color, intensity, 0, 0, decscnm) << 8) | ' '; } /* Note: inverting the screen twice should revert to the original state */ @@ -735,11 +740,11 @@ screenbuf_size = ss; set_origin(currcons); - /* do part of a reset_terminal() */ + /* do part of a vte_ris() */ top = 0; bottom = video_num_lines; gotoxy(currcons, x, y); - save_cur(currcons); + vte_decsc(currcons); if (console_table[currcons]) { struct winsize ws, *cws = &console_table[currcons]->winsize; @@ -774,7 +779,13 @@ /* * VT102 emulator + * + * VTE_VERSION selects the version of the emulation + * + * 20x is bug-fixes only (for the 2.3.x series). + * 21x improves VT100 and ECMA-48 conformance. */ +#define VTE_VERSION 210 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x) #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x) @@ -791,6 +802,18 @@ #define VT100ID "\033[?1;2c" #define VT102ID "\033[?6c" +/* + * ISO 6429 has its colors well defined: + * + * 0: black + * 1: red + * 2: yellow + * 3: green + * 4: blue + * 5: magenta + * 6: cyan + * 7: white + */ unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, 8,12,10,14, 9,13,11,15 }; @@ -859,11 +882,15 @@ scrolldelta(lines); } -static void lf(int currcons) +/* + * LINE FEED (LF) + */ +static void vte_lf(int currcons) { - /* don't scroll if above bottom of scrolling region, or - * if below scrolling region - */ + /* + * Don't scroll if below top of scrolling region, or if above + * scrolling region. + */ if (y+1 == bottom) scrup(currcons,top,bottom,1); else if (y < video_num_lines-1) { @@ -873,11 +900,15 @@ need_wrap = 0; } -static void ri(int currcons) +/* + * REVERSE LINE FEED (RI) + */ +static void vte_ri(int currcons) { - /* don't scroll if below top of scrolling region, or - * if above scrolling region - */ + /* + * Don't scroll if below top of scrolling region, or if above + * scrolling region. + */ if (y == top) scrdown(currcons,top,bottom,1); else if (y > 0) { @@ -887,13 +918,19 @@ need_wrap = 0; } -static inline void cr(int currcons) +/* + * CARRIAGE RETURN (CR) + */ +static inline void vte_cr(int currcons) { pos -= x<<1; need_wrap = x = 0; } -static inline void bs(int currcons) +/* + * BACK SPACE (BS) + */ +static inline void vte_bs(int currcons) { if (x) { pos -= 2; @@ -902,12 +939,64 @@ } } -static inline void del(int currcons) +#if VTE_VERSION >= 210 +/* + * CURSOR LINE TABULATION (CVT) + * + * NOTE: + * In accordance with our interpretation of VT as LF we will treat CVT as + * (par[0] * LF). Not very creative, but at least consequent. + */ +static void vte_cvt(int currcons, int vpar) +{ + int i; + + for (i = 0; i < vpar; i++) { + vte_lf(currcons); + } +} + +/* + * CURSOR BACKWARD TABULATION (CBT) + */ +static void vte_cbt(int currcons, int vpar) { - /* ignored */ + int i; + + for (i = 0; i < vpar; i++) { + pos -= (x << 1); + while (x > 0) { + x--; + if (tab_stop[x >> 5] & (1 << (x & 31))) + break; + } + pos += (x << 1); + } } -static void csi_J(int currcons, int vpar) +/* + * CURSOR FORWARD TABULATION (CHT) + */ +static void vte_cht(int currcons, int vpar) +{ + int i; + + for (i = 0; i < vpar; i++) { + pos -= (x << 1); + while (x < video_num_columns - 1) { + x++; + if (tab_stop[x >> 5] & (1 << (x & 31))) + break; + } + pos += (x << 1); + } +} +#endif /* VTE_VERSION >= 210 */ + +/* + * ERASE IN PAGE (ED) + */ +static void vte_ed(int currcons, int vpar) { unsigned int count; unsigned short * start; @@ -951,7 +1040,10 @@ need_wrap = 0; } -static void csi_K(int currcons, int vpar) +/* + * ERASE IN LINE (EL) + */ +static void vte_el(int currcons, int vpar) { unsigned int count; unsigned short * start; @@ -985,7 +1077,12 @@ need_wrap = 0; } -static void csi_X(int currcons, int vpar) /* erase the following vpar positions */ +/* + * Erase character (ECH) + * + * NOTE: This function is not available in DEC VT1xx terminals. + */ +static void vte_ech(int currcons, int vpar) /* erase the following vpar positions */ { /* not vt100? */ int count; @@ -1008,7 +1105,12 @@ color = def_color; } -static void csi_m(int currcons) +/* + * SELECT GRAPHIC RENDITION (SGR) + * + * NOTE: The DEC vt1xx series only implemented attribute values 0,1,4,5 and 7. + */ +static void vte_sgr(int currcons) { int i; @@ -1017,78 +1119,65 @@ case 0: /* all attributes off */ default_attr(currcons); break; - case 1: + case 1: /* bold or increased intensity */ intensity = 2; break; - case 2: + case 2: /* faint or decreased intensity */ intensity = 0; break; - case 4: + case 4: /* singly underlined. */ underline = 1; break; - case 5: + case 5: /* slowly blinking (< 2.5 Hz) */ +#if VTE_VERSION >= 210 + case 6: /* rapidly blinking (>= 2.5 Hz) */ +#endif /* VTE_VERSION >= 210 */ blink = 1; break; - case 7: + case 7: /* negative image */ reverse = 1; break; - case 10: /* ANSI X3.64-1979 (SCO-ish?) - * Select primary font, don't display - * control chars if defined, don't set - * bit 8 on output. - */ + case 10: /* primary (default) font */ translate = set_translate(charset == 0 ? G0_charset : G1_charset,currcons); disp_ctrl = 0; toggle_meta = 0; break; - case 11: /* ANSI X3.64-1979 (SCO-ish?) - * Select first alternate font, lets - * chars < 32 be displayed as ROM chars. - */ + case 11: /* first alternative font */ translate = set_translate(IBMPC_MAP,currcons); disp_ctrl = 1; toggle_meta = 0; break; - case 12: /* ANSI X3.64-1979 (SCO-ish?) - * Select second alternate font, toggle - * high bit before displaying as ROM char. - */ + case 12: /* second alternative font */ translate = set_translate(IBMPC_MAP,currcons); disp_ctrl = 1; toggle_meta = 1; break; - case 21: - case 22: +#if VTE_VERSION < 199 + case 21: /* normal intensity */ +#endif /* VTE_VERSION < 199 */ + case 22: /* normal intensity */ intensity = 1; break; - case 24: + case 24: /* not underlined (neither singly nor doubly) */ underline = 0; break; - case 25: + case 25: /* steady (not blinking) */ blink = 0; break; - case 27: + case 27: /* positive image */ reverse = 0; break; - case 38: /* ANSI X3.64-1979 (SCO-ish?) - * Enables underscore, white foreground - * with white underscore (Linux - use - * default foreground). - */ + case 38: /* foreground color (ISO 8613-6/ITU T.416) */ color = (def_color & 0x0f) | background; underline = 1; break; - case 39: /* ANSI X3.64-1979 (SCO-ish?) - * Disable underline option. - * Reset colour to default? It did this - * before... - */ + case 39: /* default display color */ color = (def_color & 0x0f) | background; underline = 0; break; - case 49: + case 49: /* default background color */ color = (def_color & 0xf0) | foreground; break; default: @@ -1112,24 +1201,74 @@ con_schedule_flip(tty); } -static void cursor_report(int currcons, struct tty_struct * tty) +#if VTE_VERSION >= 210 +/* + * Fake a DEC DSR for non-implemented features + */ +static void vte_fake_dec_dsr(struct tty_struct *tty, char *reply) +{ + char buf[40]; + sprintf(buf, "\033[?%sn", reply); + respond_string(buf, tty); +} +#endif /* VTE_VERSION >= 210 */ + +/* + * CURSOR POSITION REPORT (CPR) + * DEC EXTENDED CURSOR POSITION REPORT (DECXCPR) + */ +static void vte_cpr(int currcons, struct tty_struct *tty, int ext) { char buf[40]; - sprintf(buf, "\033[%d;%dR", y + (decom ? top+1 : 1), x+1); +#if VTE_VERSION >= 210 + if (ext) { + /* + * NOTE: + * Since we don't implement any form of page memory, we will + * always return the cursor position in page 1. + */ + sprintf(buf, "\033[?%d;%d;1R", y + (decom ? top + 1 : 1), x+1); + } else +#endif /* VTE_VERSION >= 210 */ + sprintf(buf, "\033[%d;%dR", y + (decom ? top + 1 : 1), x+1); respond_string(buf, tty); } -static inline void status_report(struct tty_struct * tty) +/* + * DEVICE STATUS REPORT (DSR) + */ +static inline void vte_dsr(struct tty_struct * tty) { respond_string("\033[0n", tty); /* Terminal ok */ } -static inline void respond_ID(struct tty_struct * tty) +/* + * DEVICE ATTRIBUTE (DA) + */ +static inline void vte_da(struct tty_struct * tty) { respond_string(VT102ID, tty); } +#if VTE_VERSION >= 210 +/* + * DEC REPORT TERMINAL PARAMETERS (DECREPTPARM) + * + * NOTE: This function is only available on DEV VT1xx terminals. + * + * XXX Fixme! Report should reflect actual parameters instead of being hard + * coded. -dbk + */ +static void vte_decreptparm(int currcons, struct tty_struct *tty) +{ + char buf[40]; + + sprintf(buf, "\033[%d;1;1;120;120;1;0x", par[0] + 2); + respond_string(buf, tty); +} +#endif /* VTE_VERSION >= 210 */ + void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry) { char buf[8]; @@ -1147,6 +1286,10 @@ return report_mouse; } +/* + * Set mode (SM / DECSM) + * Reset mode (RM / DECRM) + */ static void set_mode(int currcons, int on_off) { int i; @@ -1279,7 +1422,12 @@ need_wrap = 0; } -static void csi_at(int currcons, unsigned int nr) +/* + * Insert character (ICH) + * + * NOTE: This function is not available in DEC VT1xx terminals. + */ +static void vte_ich(int currcons, unsigned int nr) { if (nr > video_num_columns - x) nr = video_num_columns - x; @@ -1288,7 +1436,10 @@ insert_char(currcons, nr); } -static void csi_L(int currcons, unsigned int nr) +/* + * Insert line (IL) + */ +static void vte_il(int currcons, unsigned int nr) { if (nr > video_num_lines - y) nr = video_num_lines - y; @@ -1297,7 +1448,10 @@ insert_line(currcons, nr); } -static void csi_P(int currcons, unsigned int nr) +/* + * Delete character (DCH) + */ +static void vte_dch(int currcons, unsigned int nr) { if (nr > video_num_columns - x) nr = video_num_columns - x; @@ -1306,7 +1460,10 @@ delete_char(currcons, nr); } -static void csi_M(int currcons, unsigned int nr) +/* + * Delete line (DL) + */ +static void vte_dl(int currcons, unsigned int nr) { if (nr > video_num_lines - y) nr = video_num_lines - y; @@ -1315,7 +1472,18 @@ delete_line(currcons, nr); } -static void save_cur(int currcons) +/* + * Save cursor (DECSC) + * + * This saves the following states: + * - cursor position + * - graphic rendition + * - character set shift state + * - state of wrap flag + * - state of origin mode + * - state of selective erase (not implemented) + */ +static void vte_decsc(int currcons) { saved_x = x; saved_y = y; @@ -1329,7 +1497,10 @@ saved_G1 = G1_charset; } -static void restore_cur(int currcons) +/* + * Restore cursor (DECRC) + */ +static void vte_decrc(int currcons) { gotoxy(currcons,saved_x,saved_y); intensity = s_intensity; @@ -1345,15 +1516,29 @@ need_wrap = 0; } -enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey, - EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, +enum { ESinit, ESesc, EScsi, ESgetpars, ESgotpars, ESfunckey, + ESscf, ESgzd4, ESg1d4, ESdocs, ESignore, ESosc, ESpalette }; -static void reset_terminal(int currcons, int do_clear) +/* + * Reset to initial state (RIS) + * + * On DEC terminals this causes the following: + * - all set-up parameters are replaced by power-up defaults + * - all communications lines are disconnected (should we send SIGHUP?) + * - all user-defined keys are cleared (not implemented) + * - the screen is cleared + * - cursor is place to upper-left corner + * - SGR state is set to normal + * - selective erase attribute write state is set to "non-selective erase" + * (not implemented) + * - all character sets are set to default (not implemented) + */ +static void vte_ris(int currcons, int do_clear) { top = 0; bottom = video_num_lines; - vc_state = ESnormal; + vc_state = ESinit; ques = 0; translate = set_translate(LAT1_MAP,currcons); G0_charset = LAT1_MAP; @@ -1399,9 +1584,47 @@ bell_duration = DEFAULT_BELL_DURATION; gotoxy(currcons,0,0); - save_cur(currcons); + vte_decsc(currcons); if (do_clear) - csi_J(currcons,2); + vte_ed(currcons,2); +} + +/* + * TABULATION CLEAR (TBC) + * + * NOTE: + * In case of parameters 0 and 2 the number of lines affected depends on the + * setting of the Tabulation Stop Mode (TSM). Since we don't implement TSM, + * this is silently ignored. + * + * Parameters 1 and 4 are similiar to 0 and 3, but affect only line tabulation + * stops, which are not implemented. + * + * Parameter 2 may only be interpreted, when we implement a tabulation stop map + * per display line. + */ +static void vte_tbc(int currcons, int vpar) +{ + + switch (vpar) { + case 0: + /* + * The character tabulation stop at the active + * presentation position is cleared. + */ + tab_stop[x >> 5] &= ~(1 << (x & 31)); + return; + case 3: + /* + * All character tabulation stops are cleared. + */ + case 5: + /* + * All tabulation stops are cleared. + */ + tab_stop[0] = tab_stop[1] = tab_stop[2] = tab_stop[3] = + tab_stop[4] = 0; + } } static void do_con_trol(struct tty_struct *tty, unsigned int currcons, int c) @@ -1411,16 +1634,21 @@ * of an escape sequence. */ switch (c) { - case 0: + case 0x00: /* NUL - Null */ + return; +#if 0 + case 0x05: /* ENQ - Enquiry */ + /* XXX Fixme! should implement answerback */ return; - case 7: +#endif + case 0x07: /* BEL - Bell */ if (bell_duration) kd_mksound(bell_pitch, bell_duration); return; - case 8: - bs(currcons); + case 0x08: /* BS - Backspace */ + vte_bs(currcons); return; - case 9: + case 0x09: /* HT - Character tabulation */ pos -= (x << 1); while (x < video_num_columns - 1) { x++; @@ -1429,103 +1657,167 @@ } pos += (x << 1); return; - case 10: case 11: case 12: - lf(currcons); + case 0x0a: /* LF - Line feed */ + case 0x0b: /* VT - Line tabulation */ + /* + * Since line tabulation is not implemented in the DEC VT + * series (except VT131 ?), the DEC VT series treats any + * VT as LF. + */ + case 0x0c: /* FF - Form feed */ + /* + * DEC VT series processes FF as LF. + */ + vte_lf(currcons); if (!is_kbd(lnm)) return; - case 13: - cr(currcons); + case 0x0d: /* CR - Carriage return */ + vte_cr(currcons); return; - case 14: + case 0x0e: /* SO - Shift out / LS1 - Locking shift 1 */ charset = 1; translate = set_translate(G1_charset,currcons); disp_ctrl = 1; return; - case 15: + case 0x0f: /* SI - Shift in / LS0 - Locking shift 0 */ charset = 0; translate = set_translate(G0_charset,currcons); disp_ctrl = 0; return; - case 24: case 26: - vc_state = ESnormal; + case 0x18: /* CAN - Cancel */ + case 0x1a: /* SUB - Substitute */ + /* + * NOTE: + * On a DEC VT series terminal the reception of SUB will not + * only end the current ESC, CSI or DCS sequence but also + * display the error character, the mirrored (not upside-down!) + * question mark. Not (yet) implemented. + */ + vc_state = ESinit; return; - case 27: + case 0x1b: /* ESC - Escape */ vc_state = ESesc; return; - case 127: - del(currcons); + case 0x7f: /* DEL - Delete */ + /* + * This character is ignored, unless a 96-set has been mapped, + * but this is not supported at the moment. + */ return; - case 128+27: - vc_state = ESsquare; + /* + * C1 control functions (8-bit mode). + * + * XXX Fixme! Should only be interpreted if 8-bit controls are enabled. + * XXX Fixme! Should have all C1 controls implemented (acc. to ECMA). + */ +#if VTE_VERSION >= 210 + case 0x84: /* IND - Line feed (DEC, dropped by ECMA/ISO) */ + vte_lf(currcons); + return; + case 0x85: /* NEL - Next line */ + vte_lf(currcons); + vte_cr(currcons); + return; + case 0x88: /* HTS - Character tabulation set */ + tab_stop[x >> 5] |= (1 << (x & 31)); + return; + case 0x8d: /* RI - Reverse line feed */ + vte_ri(currcons); + return; +#endif /* VTE_VERSION >= 210 */ + case 0x9b: /* CSI - Control sequence introducer */ + vc_state = EScsi; return; } + switch(vc_state) { case ESesc: - vc_state = ESnormal; + vc_state = ESinit; switch (c) { - case '[': - vc_state = ESsquare; + case '#': /* SCF - Single control functions */ + vc_state = ESscf; return; - case ']': - vc_state = ESnonstd; + case '%': /* DOCS - Designate other coding system */ + vc_state = ESdocs; return; - case '%': - vc_state = ESpercent; + case '(': /* GZD4 - G0-designate 94-set */ + vc_state = ESgzd4; return; - case 'E': - cr(currcons); - lf(currcons); + case ')': /* G1D4 - G1-designate 94-set */ + vc_state = ESg1d4; return; - case 'M': - ri(currcons); + + /* ===== Private control functions ===== */ + + case '7': /* DECSC - Save cursor */ + vte_decsc(currcons); return; - case 'D': - lf(currcons); + case '8': /* DECRC - Restore cursor */ + vte_decrc(currcons); return; - case 'H': - tab_stop[x >> 5] |= (1 << (x & 31)); + case '=': /* DECKPAM - Keypad application mode */ + set_kbd(kbdapplic); return; - case 'Z': - respond_ID(tty); + case '>': /* DECKPNM - Keypad numeric mode */ + clr_kbd(kbdapplic); return; - case '7': - save_cur(currcons); + + /* ===== C1 control functions ===== */ + + case 'D': /* IND - Line feed (DEC, but not ISO 6429) */ + vte_lf(currcons); return; - case '8': - restore_cur(currcons); + case 'E': /* NEL - Next line */ + vte_cr(currcons); + vte_lf(currcons); return; - case '(': - vc_state = ESsetG0; + case 'H': /* HTS - Character tabulation set */ + tab_stop[x >> 5] |= (1 << (x & 31)); return; - case ')': - vc_state = ESsetG1; + case 'M': /* RI - Reverse line feed */ + vte_ri(currcons); return; - case '#': - vc_state = EShash; + case 'Z': /* DECID - Identify terminal */ + /* XXX Fixme! This collides with ISO 6429! */ + vte_da(tty); return; - case 'c': - reset_terminal(currcons,1); + case '[': /* CSI - Contro sequence introducer */ + vc_state = EScsi; return; - case '>': /* Numeric keypad */ - clr_kbd(kbdapplic); + case ']': /* OSC - Operating system command */ + /* XXX Fixme! Wrong sequence and sequence format! */ + vc_state = ESosc; return; - case '=': /* Appl. keypad */ - set_kbd(kbdapplic); + + /* ===== Single control functions ===== */ + + case 'c': /* RIS - Reset to initial state */ + vte_ris(currcons,1); return; } return; - case ESnonstd: - if (c=='P') { /* palette escape sequence */ - for (npar=0; npar='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) { @@ -1539,12 +1831,12 @@ palette[i] = 16*par[j++]; palette[i] += par[j]; set_palette(currcons); - vc_state = ESnormal; + vc_state = ESinit; } } else - vc_state = ESnormal; + vc_state = ESinit; return; - case ESsquare: + case EScsi: for(npar = 0 ; npar < NPAR ; npar++) par[npar] = 0; npar = 0; @@ -1566,15 +1858,20 @@ return; } else vc_state=ESgotpars; case ESgotpars: - vc_state = ESnormal; + vc_state = ESinit; switch(c) { - case 'h': + case 'h': /* SM - Set mode / DECSM - Set mode */ set_mode(currcons,1); return; - case 'l': + case 'l': /* RM - Reset mode / DECRM - Reset mode */ set_mode(currcons,0); return; case 'c': + /* + * XXX Fixme! Need to use final byte reserved for + * private sequences instead of flag designating + * private parameters! + */ if (ques) { if (par[0]) cursor_type = par[0] | (par[1]<<8) | (par[2]<<16); @@ -1584,6 +1881,11 @@ } break; case 'm': + /* + * XXX Fixme! Need to use final byte reserved for + * private sequences instead of flag designating + * private parameters! + */ if (ques) { clear_selection(); if (par[0]) @@ -1594,12 +1896,36 @@ } break; case 'n': - if (!ques) { - if (par[0] == 5) - status_report(tty); - else if (par[0] == 6) - cursor_report(currcons,tty); - } +#if VTE_VERSION >= 210 + if (ques) { + switch (par[0]) { + case 6: /* DECXCPR - Extended CPR */ + vte_cpr(currcons, tty, 1); + break; + case 15: /* DEC printer status */ + vte_fake_dec_dsr(tty, "13"); + break; + case 25: /* DEC UDK status */ + vte_fake_dec_dsr(tty, "21"); + break; + case 26: /* DEC keyboard status */ + vte_fake_dec_dsr(tty, "27;1;0;1"); + break; + case 75: /* DEC data integrity */ + vte_fake_dec_dsr(tty, "70"); + break; + } + } else +#endif /* VTE_VERSION >= 210 */ + switch (par[0]) { + case 5: /* DSR - Device status report */ + vte_dsr(tty); + break; + case 6: /* CPR - Cursor position report */ + vte_cpr(currcons, tty, 0); + break; + } + ques = 0; return; } if (ques) { @@ -1607,83 +1933,128 @@ return; } switch(c) { - case 'G': case '`': - if (par[0]) par[0]--; - gotoxy(currcons,par[0],y); + case '@': /* ICH - Insert character */ + vte_ich(currcons,par[0]); return; - case 'A': + case 'A': /* CUU - Cursor up */ +#if VTE_VERSION >= 210 + case 'k': /* VPB - Line position backward */ +#endif /* VTE_VERSION >= 210 */ if (!par[0]) par[0]++; gotoxy(currcons,x,y-par[0]); return; - case 'B': case 'e': + case 'B': /* CUD - Cursor down */ + case 'e': /* VPR - Line position forward */ if (!par[0]) par[0]++; gotoxy(currcons,x,y+par[0]); return; - case 'C': case 'a': + case 'C': /* CUF - Cursor right */ + case 'a': /* HPR - Character position forward */ if (!par[0]) par[0]++; gotoxy(currcons,x+par[0],y); return; - case 'D': + case 'D': /* CUB - Cursor left */ +#if VTE_VERSION >= 210 + case 'j': /* HPB - Character position backward */ +#endif /* VTE_VERSION >= 210 */ if (!par[0]) par[0]++; gotoxy(currcons,x-par[0],y); return; - case 'E': + case 'E': /* CNL - Cursor next line */ if (!par[0]) par[0]++; gotoxy(currcons,0,y+par[0]); return; - case 'F': + case 'F': /* CPL - Cursor preceeding line */ if (!par[0]) par[0]++; gotoxy(currcons,0,y-par[0]); return; - case 'd': + case 'G': /* CHA - Cursor character absolute */ + case '`': /* HPA - Character position absolute */ if (par[0]) par[0]--; - gotoxay(currcons,x,par[0]); + gotoxy(currcons,par[0],y); return; - case 'H': case 'f': + case 'H': /* CUP - Cursor position */ + case 'f': /* HVP - Horizontal and vertical position */ if (par[0]) par[0]--; if (par[1]) par[1]--; gotoxay(currcons,par[1],par[0]); return; - case 'J': - csi_J(currcons,par[0]); +#if VTE_VERSION >= 210 + case 'I': /* CHT - Cursor forward tabulation */ + if (!par[0]) par[0]++; + vte_cht(currcons,par[0]); return; - case 'K': - csi_K(currcons,par[0]); +#endif /* VTE_VERSION >= 210 */ + case 'J': /* ED - Erase in page */ + vte_ed(currcons,par[0]); return; - case 'L': - csi_L(currcons,par[0]); + case 'K': /* EL - Erase in line */ + vte_el(currcons,par[0]); return; - case 'M': - csi_M(currcons,par[0]); + case 'L': /* IL - Insert line */ + vte_il(currcons,par[0]); return; - case 'P': - csi_P(currcons,par[0]); + case 'M': /* DL - Delete line */ + vte_dl(currcons,par[0]); return; - case 'c': + case 'P': /* DCH - Delete character */ + vte_dch(currcons,par[0]); + return; +#if VTE_VERSION >= 210 + case 'W': /* CTC - Cursor tabulation control */ + switch (par[0]) { + case 0: /* Set character tab stop at current position */ + tab_stop[x >> 5] |= (1 << (x & 31)); + return; + case 2: /* Clear character tab stop at curr. position */ + vte_tbc(currcons, 0); + return; + case 5: /* All character tab stops are cleared. */ + vte_tbc(currcons, 5); + return; + } + return; +#endif /* VTE_VERSION >= 210 */ + case 'X': /* ECH - Erase character */ + vte_ech(currcons, par[0]); + return; +#if VTE_VERSION >= 210 + case 'Y': /* CVT - Cursor line tabulation */ if (!par[0]) - respond_ID(tty); + par[0]++; + vte_cvt(currcons, par[0]); return; - case 'g': + case 'Z': /* CBT - Cursor backward tabulation */ + vte_cbt(currcons, par[0]); + return; +#endif /* VTE_VERSION >= 210 */ + case ']': /* setterm functions */ + /* XXX Fixme! This collides with ISO 6429! */ + setterm_command(currcons); + return; + case 'c': /* DA - Device attribute */ if (!par[0]) - tab_stop[x >> 5] &= ~(1 << (x & 31)); - else if (par[0] == 3) { - tab_stop[0] = - tab_stop[1] = - tab_stop[2] = - tab_stop[3] = - tab_stop[4] = 0; - } + vte_da(tty); return; - case 'm': - csi_m(currcons); + case 'd': /* VPA - Line position absolute */ + if (par[0]) par[0]--; + gotoxay(currcons,x,par[0]); + return; + case 'g': /* TBC - Tabulation clear */ + vte_tbc(currcons, par[0]); return; - case 'q': /* DECLL - but only 3 leds */ - /* map 0,1,2,3 to 0,1,2,4 */ + case 'm': /* SGR - Select graphic rendition */ + vte_sgr(currcons); + return; + + /* ===== Private control sequences ===== */ + + case 'q': /* DECLL - Load LEDs */ if (par[0] < 4) setledstate(kbd_table + currcons, (par[0] < 3) ? par[0] : 4); return; - case 'r': + case 'r': /* DECSTBM - Set top and bottom margin */ if (!par[0]) par[0]++; if (!par[1]) @@ -1696,25 +2067,23 @@ gotoxay(currcons,0,0); } return; - case 's': - save_cur(currcons); - return; - case 'u': - restore_cur(currcons); +#if VTE_VERSION < 199 + case 's': /* DECSC - Save cursor */ + vte_decsc(currcons); return; - case 'X': - csi_X(currcons, par[0]); + case 'u': /* DECRC - Restore cursor */ + vte_decrc(currcons); return; - case '@': - csi_at(currcons,par[0]); - return; - case ']': /* setterm functions */ - setterm_command(currcons); +#endif /* VTE_VERSION < 199 */ +#if VTE_VERSION >= 210 + case 'x': /* DECREQTPARM - Request terminal parameters */ + vte_decreptparm(currcons, tty); return; +#endif /* VTE_VERSION >= 210 */ } return; - case ESpercent: - vc_state = ESnormal; + case ESdocs: + vc_state = ESinit; switch (c) { case '@': /* defined in ISO 2022 */ utf = 0; @@ -1726,21 +2095,21 @@ } return; case ESfunckey: - vc_state = ESnormal; + vc_state = ESinit; return; - case EShash: - vc_state = ESnormal; + case ESscf: + vc_state = ESinit; if (c == '8') { /* DEC screen alignment test. kludge :-) */ video_erase_char = (video_erase_char & 0xff00) | 'E'; - csi_J(currcons, 2); + vte_ed(currcons, 2); video_erase_char = (video_erase_char & 0xff00) | ' '; do_update_region(currcons, origin, screenbuf_size/2); } return; - case ESsetG0: + case ESgzd4: if (c == '0') G0_charset = GRAF_MAP; else if (c == 'B') @@ -1751,9 +2120,9 @@ G0_charset = USER_MAP; if (charset == 0) translate = set_translate(G0_charset,currcons); - vc_state = ESnormal; + vc_state = ESinit; return; - case ESsetG1: + case ESg1d4: if (c == '0') G1_charset = GRAF_MAP; else if (c == 'B') @@ -1764,10 +2133,10 @@ G1_charset = USER_MAP; if (charset == 1) translate = set_translate(G1_charset,currcons); - vc_state = ESnormal; + vc_state = ESinit; return; default: - vc_state = ESnormal; + vc_state = ESinit; } } @@ -1861,47 +2230,47 @@ tc = translate[toggle_meta ? (c|0x80) : c]; } - /* If the original code was a control character we - * only allow a glyph to be displayed if the code is - * not normally used (such as for cursor movement) or - * if the disp_ctrl mode has been explicitly enabled. - * Certain characters (as given by the CTRL_ALWAYS - * bitmap) are always displayed as control characters, - * as the console would be pretty useless without - * them; to display an arbitrary font position use the - * direct-to-font zone in UTF-8 mode. - */ - ok = tc && (c >= 32 || - (!utf && !(((disp_ctrl ? CTRL_ALWAYS - : CTRL_ACTION) >> c) & 1))) - && (c != 127 || disp_ctrl) + /* If the original code was a control character we + * only allow a glyph to be displayed if the code is + * not normally used (such as for cursor movement) or + * if the disp_ctrl mode has been explicitly enabled. + * Certain characters (as given by the CTRL_ALWAYS + * bitmap) are always displayed as control characters, + * as the console would be pretty useless without + * them; to display an arbitrary font position use the + * direct-to-font zone in UTF-8 mode. + */ + ok = tc && (c >= 32 || + (!utf && !(((disp_ctrl ? CTRL_ALWAYS + : CTRL_ACTION) >> c) & 1))) + && (c != 127 || disp_ctrl) && (c != 128+27); - if (vc_state == ESnormal && ok) { + if (vc_state == ESinit && ok) { /* Now try to find out how to display it */ tc = conv_uni_to_pc(vc_cons[currcons].d, tc); if ( tc == -4 ) { - /* If we got -4 (not found) then see if we have - defined a replacement character (U+FFFD) */ - tc = conv_uni_to_pc(vc_cons[currcons].d, 0xfffd); + /* If we got -4 (not found) then see if we have + defined a replacement character (U+FFFD) */ + tc = conv_uni_to_pc(vc_cons[currcons].d, 0xfffd); /* One reason for the -4 can be that we just did a clear_unimap(); try at least to show something. */ if (tc == -4) tc = c; - } else if ( tc == -3 ) { - /* Bad hash table -- hope for the best */ - tc = c; - } + } else if ( tc == -3 ) { + /* Bad hash table -- hope for the best */ + tc = c; + } if (tc & ~charmask) - continue; /* Conversion failed */ + continue; /* Conversion failed */ if (need_wrap || decim) FLUSH if (need_wrap) { - cr(currcons); - lf(currcons); + vte_cr(currcons); + vte_lf(currcons); } if (decim) insert_char(currcons, 1); @@ -2026,14 +2395,14 @@ cnt = 0; } if (c == 8) { /* backspace */ - bs(currcons); + vte_bs(currcons); start = (ushort *)pos; myx = x; continue; } if (c != 13) - lf(currcons); - cr(currcons); + vte_lf(currcons); + vte_cr(currcons); start = (ushort *)pos; myx = x; if (c == 10 || c == 13) @@ -2274,7 +2643,7 @@ ulcolor = 0x0f; /* bold white */ halfcolor = 0x08; /* grey */ vt_cons[currcons]->paste_wait = 0; - reset_terminal(currcons, do_clear); + vte_ris(currcons, do_clear); } /* @@ -2363,7 +2732,7 @@ set_origin(currcons); save_screen(currcons); gotoxy(currcons,x,y); - csi_J(currcons, 0); + vte_ed(currcons, 0); update_screen(fg_console); printk("Console: %s %s %dx%d", can_do_color ? "colour" : "mono",