📄 vt100.c
字号:
break; } break; case 'c': /* Identify Terminal Type */ if (vt_type == VT100) { v_termout("\033[?1;2c", 0); break; } v_termout("\033[?c", 0); break; case 'x': /* Request terminal parameters. */ /* Always answers 19200-8N1 no options. */ sprintf(temp, "\033[%c;1;1;120;120;1;0x", escparms[0] == 1 ? '3' : '2'); v_termout(temp, 0); break; case 's': /* Save attributes and cursor position */ savex = vt_win->curx; savey = vt_win->cury; saveattr = vt_win->attr; savecol = vt_win->color;#if TRANSLATE savecharset = vt_charset; savetrans[0] = vt_trans[0]; savetrans[1] = vt_trans[1];#endif break; case 'u': /* Restore them */#if TRANSLATE vt_charset = savecharset; vt_trans[0] = savetrans[0]; vt_trans[1] = savetrans[1];#endif break; vt_win->color = savecol; /* HACK should use wsetfgcol etc */ wsetattr(vt_win, saveattr); wlocate(vt_win, savex, savey); break; case 'h': ansi_mode(1); break; case 'l': ansi_mode(0); break; case 'H': case 'f': /* Set cursor position */ if ((y = escparms[0]) == 0) y = 1; if ((x = escparms[1]) == 0) x = 1; if (vt_om) y += newy1; wlocate(vt_win, x - 1, y - 1); break; case 'g': /* Clear tab stop(s) */ if (escparms[0] == 0) { x = vt_win->curx; if (x > 159) x = 159; vt_tabs[x / 32] &= ~(1 << x % 32); } if (escparms[0] == 3) for(x = 0; x < 5; x++) vt_tabs[x] = 0; break; case 'm': /* Set attributes */#if OLD /* Without argument, esc-parms[0] is 0 */ if (ptr < 0) ptr = 0;#endif attr = wgetattr((vt_win)); for (f = 0; f <= ptr; f++) { if (escparms[f] >= 30 && escparms[f] <= 37) wsetfgcol(vt_win, escparms[f] - 30); if (escparms[f] >= 40 && escparms[f] <= 47) wsetbgcol(vt_win, escparms[f] - 40); switch (escparms[f]) { case 0: attr = XA_NORMAL; wsetfgcol(vt_win, vt_fg); wsetbgcol(vt_win, vt_bg); break; case 4: attr |= XA_UNDERLINE; break; case 7: attr |= XA_REVERSE; break; case 1: attr |= XA_BOLD; break; case 5: attr |= XA_BLINK; break; case 22: /* Bold off */ attr &= ~XA_BOLD; break; case 24: /* Not underlined */ attr &=~XA_UNDERLINE; break; case 25: /* Not blinking */ attr &= ~XA_BLINK; break; case 27: /* Not reverse */ attr &= ~XA_REVERSE; break; case 39: /* Default fg color */ wsetfgcol(vt_win, vt_fg); break; case 49: /* Default bg color */ wsetbgcol(vt_win, vt_bg); break; } } wsetattr(vt_win, attr); break; case 'L': /* Insert lines */ if ((x = escparms[0]) == 0) x = 1; for (f = 0; f < x; f++) winsline(vt_win); break; case 'M': /* Delete lines */ if ((x = escparms[0]) == 0) x = 1; for (f = 0; f < x; f++) wdelline(vt_win); break; case 'P': /* Delete Characters */ if ((x = escparms[0]) == 0) x = 1; for (f = 0; f < x; f++) wdelchar(vt_win); break; case '@': /* Insert Characters */ if ((x = escparms[0]) == 0) x = 1; for (f = 0; f < x; f++) winschar(vt_win); break; case 'r': /* Set scroll region */ if ((newy1 = escparms[0]) == 0) newy1 = 1; if ((newy2 = escparms[1]) == 0) newy2 = vt_win->ys; newy1-- ; newy2--; if (newy1 < 0) newy1 = 0; if (newy2 < 0) newy2 = 0; if (newy1 >= vt_win->ys) newy1 = vt_win->ys - 1; if (newy2 >= vt_win->ys) newy2 = vt_win->ys - 1; if (newy1 >= newy2) { newy1 = 0; newy2 = vt_win->ys - 1; } wsetregion(vt_win, newy1, newy2); wlocate(vt_win, 0, newy1); break; case 'i': /* Printing */ case 'y': /* Self test modes */ default: /* IGNORED */ break; } /* Ok, our escape sequence is all done */ esc_s = 0;#if OLD ptr = -2;#else ptr = 0; memset(escparms, 0, sizeof(escparms));#endif return;}/* ESC [? ... [hl] seen. */static void dec_mode(int on_off){ int i; for (i = 0; i <= ptr; i++) { switch (escparms[i]) { case 1: /* Cursor keys in cursor/appl mode */ vt_cursor = on_off ? APPL : NORMAL; if (vt_keyb) (*vt_keyb)(vt_keypad, vt_cursor); break; case 6: /* Origin mode. */ vt_om = on_off; wlocate(vt_win, 0, newy1); break; case 7: /* Auto wrap */ vt_win->wrap = on_off; break; case 25: /* Cursor on/off */ wcursor(vt_win, on_off ? CNORMAL : CNONE); break; case 67: /* Backspace key sends. (FIXME: vt420) */ /* setbackspace(on_off ? 8 : 127); */ break; default: /* Mostly set up functions */ /* IGNORED */ break; } }}/* * ESC [ ? ... seen. */static void state3(int c){ /* See if a number follows */ if (c >= '0' && c <= '9') {#if OLD if (ptr < 0) ptr = 0;#endif escparms[ptr] = 10*escparms[ptr] + c - '0'; return; }#if OLD /* ESC [ ? number seen */ if (ptr < 0) { esc_s = 0; return; }#endif switch (c) { case 'h': dec_mode(1); break; case 'l': dec_mode(0); break; case 'i': /* Printing */ case 'n': /* Request printer status */ default: /* IGNORED */ break; } esc_s = 0;#if OLD ptr = -2;#else ptr = 0; memset(escparms, 0, sizeof(escparms));#endif return;}/* * ESC ( Seen. */static void state4(int c){ /* Switch Character Sets. */#if !TRANSLATE /* IGNORED */ (void)c;#else switch (c) { case 'A': case 'B': vt_trans[0] = vt_map[0]; break; case '0': case 'O': vt_trans[0] = vt_map[1]; break; }#endif esc_s = 0;}/* * ESC ) Seen. */static void state5(int c){ /* Switch Character Sets. */#if !TRANSLATE /* IGNORED */ (void)c;#else switch (c) { case 'A': case 'B': vt_trans[1] = vt_map[0]; break; case 'O': case '0': vt_trans[1] = vt_map[1]; break; }#endif esc_s = 0;}/* * ESC # Seen. */static void state6(int c){ int x, y; /* Double height, double width and selftests. */ switch (c) { case '8': /* Selftest: fill screen with E's */ vt_win->doscroll = 0; vt_win->direct = 0; wlocate(vt_win, 0, 0); for (y = 0; y < vt_win->ys; y++) { wlocate(vt_win, 0, y); for (x = 0; x < vt_win->xs; x++) wputc(vt_win, 'E'); } wlocate(vt_win, 0, 0); vt_win->doscroll = 1; wredraw(vt_win, 1); break; default: /* IGNORED */ break; } esc_s = 0;}/* * ESC P Seen. */static void state7(int c){ /* * Device dependant control strings. The Minix virtual console package * uses these sequences. We can only turn cursor on or off, because * that's the only one supported in termcap. The rest is ignored. */ static char buf[17]; static int pos = 0; static int state = 0; if (c == ESC) { state = 1; return; } if (state == 1) { buf[pos] = 0; pos = 0; state = 0; esc_s = 0; if (c != '\\') return; /* Process string here! */ if (!strcmp(buf, "cursor.on")) wcursor(vt_win, CNORMAL); if (!strcmp(buf, "cursor.off")) wcursor(vt_win, CNONE); if (!strcmp(buf, "linewrap.on")) { vt_wrap = -1; vt_win->wrap = 1; } if (!strcmp(buf, "linewrap.off")) { vt_wrap = -1; vt_win->wrap = 0; } return; } if (pos > 15) return; buf[pos++] = c;}void vt_out(int ch){ int f; unsigned char c; int go_on = 0; wchar_t wc; if (!ch) return;#if OLD if (ptr == -2) { /* Initialize */ ptr = -1; for (f = 0; f < 8; f++) escparms[f] = 0; }#endif c = (unsigned char)ch; if (vt_docap == 2) /* Literal. */ fputc(c, vt_capfp); /* Process <31 chars first, even in an escape sequence. */ switch (c) { case 5: /* AnswerBack for vt100's */ if (vt_type != VT100) { go_on = 1; break; } v_termout(P_ANSWERBACK, 0); break; case '\r': /* Carriage return */ wputc(vt_win, c); if (vt_addlf) { wputc(vt_win, '\n'); if (vt_docap == 1) fputc('\n', vt_capfp); } break; case '\t': /* Non - destructive TAB */ /* Find next tab stop. */ for (f = vt_win->curx + 1; f < 160; f++) if (vt_tabs[f / 32] & (1 << f % 32)) break; if (f >= vt_win->xs) f = vt_win->xs - 1; wlocate(vt_win, f, vt_win->cury); if (vt_docap == 1) fputc(c, vt_capfp); break; case 013: /* Old Minix: CTRL-K = up */ wlocate(vt_win, vt_win->curx, vt_win->cury - 1); break; case '\f': /* Form feed: clear screen. */ winclr(vt_win); wlocate(vt_win, 0, 0); break;#if !TRANSLATE case 14: case 15: /* Change character set. Not supported. */ break;#else case 14: vt_charset = 1; break; case 15: vt_charset = 0; break;#endif case 24: case 26: /* Cancel escape sequence. */ esc_s = 0; break; case ESC: /* Begin escape sequence */ esc_s = 1; break; case 128+ESC: /* Begin ESC [ sequence. */ esc_s = 2; break; case '\n': case '\b': case 7: /* Bell */ wputc(vt_win, c); if (vt_docap == 1) fputc(c, vt_capfp); break; default: go_on = 1; break; } if (!go_on) return; /* Now see which state we are in. */ switch (esc_s) { case 0: /* Normal character */ if (vt_docap == 1) fputc(P_CONVCAP[0] == 'Y' ? vt_inmap[c] : c, vt_capfp); c = vt_inmap[c]; /* conversion 04.09.97 / jl */#if TRANSLATE if (vt_type == VT100 && vt_asis == 0) c = vt_trans[vt_charset][c];#endif /* FIXME: This is wrong, but making it right would require * removing all the 8-bit mapping features. Assuming the locale * is 8-bit, the character should not be changed by mapping to * wchar and back; if the locale is multibyte, there is no hope * of getting it right anyway. */ one_mbtowc (&wc, &c, 1); /* returns 1 */ if (vt_insert) winschar2(vt_win, wc, 1); else wputc(vt_win, wc); break; case 1: /* ESC seen */ state1(c); break; case 2: /* ESC [ ... seen */ state2(c); break; case 3: state3(c); break; case 4: state4(c); break; case 5: state5(c); break; case 6: state6(c); break; case 7: state7(c); break; } /* Flush output to capture file so that all output is visible there * immediately. Causes a write syscall for every call though. */ if (vt_capfp) fflush(vt_capfp);}/* Translate keycode to escape sequence. */void vt_send(int c){ char s[3]; int f; int len = 1; /* Special key? */ if (c < 256) { /* Translate backspace key? */ if (c == K_ERA) c = vt_bs; s[0] = vt_outmap[c]; /* conversion 04.09.97 / jl */ s[1] = 0; /* CR/LF mode? */ if (c == '\r' && vt_crlf) { s[1] = '\n'; s[2] = 0; len = 2; } v_termout(s, len); if (vt_nl_delay > 0 && c == '\r') usleep(1000 * vt_nl_delay); return; } /* Look up code in translation table. */ for (f = 0; vt_keys[f].code; f++) if (vt_keys[f].code == c) break; if (vt_keys[f].code == 0) return; /* Now send appropriate escape code. */ v_termout("\033", 0); if (vt_type == VT100) { if (vt_cursor == NORMAL) v_termout(vt_keys[f].vt100_st, 0); else v_termout(vt_keys[f].vt100_app, 0); } else v_termout(vt_keys[f].ansi, 0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -