📄 console.c
字号:
if (currcons == fg_console) { attr = old >> 8; sw->con_putc(vc_cons[currcons].d, old & 0xff, oldy, oldx); attr = oldattr; } } if (offset == -1) p = NULL; else { p = screenpos(currcons, offset, 1); old = scr_readw(p); oldx = (offset >> 1) % cols; oldy = (offset >> 1) / cols; if (can_do_color) new = old ^ 0x7700; else new = old ^ 0x800; scr_writew(new, p); if (currcons == fg_console) { attr = new >> 8; sw->con_putc(vc_cons[currcons].d, new & 0xff, oldy, oldx); attr = oldattr; } }}/* used by selection */unsigned short screen_word(int currcons, int offset, int viewed){ return scr_readw(screenpos(currcons, offset, viewed));}/* used by selection - convert a screen word to a glyph number */int scrw2glyph(unsigned short scr_word){ return ( video_mode_512ch ) ? ((scr_word & 0x0800) >> 3) + (scr_word & 0x00ff) : scr_word & 0x00ff;}/* used by vcs - note the word offset */unsigned short *screen_pos(int currcons, int w_offset, int viewed){ return screenpos(currcons, 2 * w_offset, viewed);}void getconsxy(int currcons, char *p){ p[0] = x; p[1] = y;}void putconsxy(int currcons, char *p){ gotoxy(currcons, p[0], p[1]); set_cursor(currcons);}static void set_mode(int currcons, int on_off){ int i; for (i=0; i<=npar; i++) if (ques) switch(par[i]) { /* DEC private modes set/reset */ case 1: /* Cursor keys send ^[Ox/^[[x */ if (on_off) set_kbd(decckm); else clr_kbd(decckm); break; case 3: /* 80/132 mode switch unimplemented */ deccolm = on_off;#if 0 (void) vc_resize(rows, deccolm ? 132 : 80); /* this alone does not suffice; some user mode utility has to change the hardware regs */#endif break; case 5: /* Inverted screen on/off */ if (decscnm != on_off) { decscnm = on_off; invert_screen(currcons, 0, screenbuf_size, 0); update_attr(currcons); } break; case 6: /* Origin relative/absolute */ decom = on_off; gotoxay(currcons,0,0); break; case 7: /* Autowrap on/off */ decawm = on_off; break; case 8: /* Autorepeat on/off */ if (on_off) set_kbd(decarm); else clr_kbd(decarm); break; case 9: report_mouse = on_off ? 1 : 0; break; case 25: /* Cursor on/off */ deccm = on_off; set_cursor(currcons); break; case 1000: report_mouse = on_off ? 2 : 0; break; } else switch(par[i]) { /* ANSI modes set/reset */ case 3: /* Monitor (display ctrls) */ disp_ctrl = on_off; break; case 4: /* Insert Mode on/off */ decim = on_off; break; case 20: /* Lf, Enter == CrLf/Lf */ if (on_off) set_kbd(lnm); else clr_kbd(lnm); break; }}static void setterm_command(int currcons){ switch(par[0]) { case 1: /* set color for underline mode */ if (can_do_color && par[1] < 16) { ulcolor = color_table[par[1]]; if (underline) update_attr(currcons); } break; case 2: /* set color for half intensity mode */ if (can_do_color && par[1] < 16) { halfcolor = color_table[par[1]]; if (intensity == 0) update_attr(currcons); } break; case 8: /* store colors as defaults */ def_color = attr; default_attr(currcons); update_attr(currcons); break; case 9: /* set blanking interval */ blankinterval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ; poke_blanked_console(); break; case 10: /* set bell frequency in Hz */ if (npar >= 1) bell_pitch = par[1]; else bell_pitch = DEFAULT_BELL_PITCH; break; case 11: /* set bell duration in msec */ if (npar >= 1) bell_duration = (par[1] < 2000) ? par[1]*HZ/1000 : 0; else bell_duration = DEFAULT_BELL_DURATION; break; case 12: /* bring specified console to the front */ if (par[1] >= 1 && vc_cons_allocated(par[1]-1)) update_screen(par[1]-1); break; case 13: /* unblank the screen */ unblank_screen(); break; case 14: /* set vesa powerdown interval */ vesa_off_interval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ; break; }}static void insert_char(int currcons){ int i; unsigned short *p = pos; for (i = cols - x - 2; i >= 0; i--) p[i + 1] = p[i]; *pos = video_erase_char; need_wrap = 0; if (currcons != fg_console) return; /* Arno: * Move the remainder of the line (-1 character) one spot to the right */ sw->con_bmove(vc_cons[currcons].d,y,x,y,x+1,1,(cols-x-1)); /* * Print the erase char on the current position */ sw->con_putc(vc_cons[currcons].d,(video_erase_char & 0x00ff),y,x);}static void csi_at(int currcons, unsigned int nr){ int i; unsigned short *p; if (nr > cols - x) nr = cols - x; else if (!nr) nr = 1; p = pos + cols - x - nr; while (--p >= pos) p[nr] = *p; for (i = 0; i < nr; i++) *++p = video_erase_char; need_wrap = 0; if (currcons != fg_console) return; sw->con_bmove (vc_cons[currcons].d, y, x, y, x + nr, 1, cols - x - nr); while (nr--) sw->con_putc (vc_cons[currcons].d, video_erase_char & 0x00ff, y, x + nr);}static void csi_L(int currcons, unsigned int nr){ if (nr > rows) nr = rows; else if (!nr) nr = 1; scrdown (currcons, y, bottom, nr); need_wrap = 0;}static void csi_P(int currcons, unsigned int nr){ int i; unsigned short *p, *end; if (nr > cols - x) nr = cols - x; else if (!nr) nr = 1; p = pos; end = pos + cols - x - nr; while (p < end) *p = p[nr], p++; for (i = 0; i < nr; i++) *p++ = video_erase_char; need_wrap = 0; if (currcons != fg_console) return; sw->con_bmove (vc_cons[currcons].d, y, x + nr, y, x, 1, cols - x - nr); while (nr--) sw->con_putc (vc_cons[currcons].d, video_erase_char & 0x00ff, y, cols - 1 - nr);}static void csi_M(int currcons, unsigned int nr){ if (nr > rows) nr = rows; else if (!nr) nr=1; scrup (currcons, y, bottom, nr); need_wrap = 0;}static void save_cur(int currcons){ saved_x = x; saved_y = y; s_intensity = intensity; s_underline = underline; s_blink = blink; s_reverse = reverse; s_charset = charset; s_color = color; saved_G0 = G0_charset; saved_G1 = G1_charset;}static void restore_cur(int currcons){ gotoxy(currcons,saved_x,saved_y); intensity = s_intensity; underline = s_underline; blink = s_blink; reverse = s_reverse; charset = s_charset; color = s_color; G0_charset = saved_G0; G1_charset = saved_G1; translate = set_translate(charset ? G1_charset : G0_charset); update_attr(currcons); need_wrap = 0;}enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey, EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, ESpalette };static void reset_terminal(int currcons, int do_clear){ top = 0; bottom = rows; vc_state = ESnormal; ques = 0; translate = set_translate(LAT1_MAP); G0_charset = LAT1_MAP; G1_charset = GRAF_MAP; charset = 0; need_wrap = 0; report_mouse = 0; utf = 0; utf_count = 0; disp_ctrl = 0; toggle_meta = 0; decscnm = 0; decom = 0; decawm = 1; deccm = 1; decim = 0; set_kbd(decarm); clr_kbd(decckm); clr_kbd(kbdapplic); clr_kbd(lnm); kbd_table[currcons].lockstate = 0; kbd_table[currcons].slockstate = 0; kbd_table[currcons].ledmode = LED_SHOW_FLAGS; kbd_table[currcons].ledflagstate = kbd_table[currcons].default_ledflagstate; set_leds(); default_attr(currcons); update_attr(currcons); tab_stop[0] = 0x01010100; tab_stop[1] = tab_stop[2] = tab_stop[3] = tab_stop[4] = 0x01010101; bell_pitch = DEFAULT_BELL_PITCH; bell_duration = DEFAULT_BELL_DURATION; gotoxy(currcons,0,0); save_cur(currcons); if (do_clear) csi_J(currcons,2);}/* * Turn the Scroll-Lock LED on when the tty is stopped */static void con_stop(struct tty_struct *tty){ int console_num; if (!tty) return; console_num = MINOR(tty->device) - (tty->driver.minor_start); if (!vc_cons_allocated(console_num)) return; set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK); set_leds();}/* * Turn the Scroll-Lock LED off when the console is started */static void con_start(struct tty_struct *tty){ int console_num; if (!tty) return; console_num = MINOR(tty->device) - (tty->driver.minor_start); if (!vc_cons_allocated(console_num)) return; clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK); set_leds();}static int con_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count){ int c, tc, ok, n = 0; unsigned int currcons; struct vt_struct *vt = (struct vt_struct *)tty->driver_data; currcons = vt->vc_num; if (!vc_cons_allocated(currcons)) { /* could this happen? */ static int error = 0; if (!error) { error = 1; printk("con_write: tty %d not allocated\n", currcons+1); } return 0; } /* undraw cursor first */ if (currcons == fg_console) hide_cursor(currcons); /* clear the selection */ if (currcons == sel_cons) clear_selection(); disable_bh(CONSOLE_BH); while (count) { enable_bh(CONSOLE_BH); c = from_user ? get_user(buf) : *buf; buf++; n++; count--; disable_bh(CONSOLE_BH); if (utf) { /* Combine UTF-8 into Unicode */ /* Incomplete characters silently ignored */ if(c > 0x7f) { if (utf_count > 0 && (c & 0xc0) == 0x80) { utf_char = (utf_char << 6) | (c & 0x3f); utf_count--; if (utf_count == 0) tc = c = utf_char; else continue; } else { if ((c & 0xe0) == 0xc0) { utf_count = 1; utf_char = (c & 0x1f); } else if ((c & 0xf0) == 0xe0) { utf_count = 2; utf_char = (c & 0x0f); } else if ((c & 0xf8) == 0xf0) { utf_count = 3; utf_char = (c & 0x07); } else if ((c & 0xfc) == 0xf8) { utf_count = 4; utf_char = (c & 0x03); } else if ((c & 0xfe) == 0xfc) { utf_count = 5; utf_char = (c & 0x01); } else utf_count = 0; continue; } } else { tc = c; utf_count = 0; } } else { /* no utf */ 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 (vc_state == ESnormal && ok) { /* Now try to find out how to display it */ tc = conv_uni_to_pc(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(0xfffd); } else if ( tc == -3 ) { /* Bad hash table -- hope for the best */ tc = c; } if (tc & ~console_charmask) continue; /* Conversion failed */ if (need_wrap) { cr(currcons); lf(currcons); } #if 1 /* XXX */ /* DPC: 1994-04-12 * Speed up overstrike mode, using new putcs. * * P.S. I hate 8 spaces per tab! Use Emacs! */ /* Only use this for the foreground console, where we really draw the chars */ if (count > 2 && !decim && !utf && currcons == fg_console) { static char putcs_buf[256]; char *p = putcs_buf; int putcs_count = 1; ushort nextx = x + 1; *p++ = tc; *pos++ = tc | (attr << 8); if (nextx == cols) { sw->con_putc(vc_cons[currcons].d, *putcs_buf, y, x); pos--; need_wrap = decawm; continue; } /* TAB TAB TAB - Arghh!!!! */ while (count) { enable_bh(CONSOLE_BH); c = from_user ? get_user(buf) : *buf; disable_bh(CONSOLE_BH); tc = translate[toggle_meta ? (c|0x80) : c]; if (!tc || !(c >= 32 || !(((disp_ctrl ? CTRL_ALWAYS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -