vt.c

来自「linux 内核源代码」· C语言 代码 · 共 2,565 行 · 第 1/5 页

C
2,565
字号
	gotoxy(vc, new_x, vc->vc_decom ? (vc->vc_top + new_y) : new_y);}void scrollback(struct vc_data *vc, int lines){	if (!lines)		lines = vc->vc_rows / 2;	scrolldelta(-lines);}void scrollfront(struct vc_data *vc, int lines){	if (!lines)		lines = vc->vc_rows / 2;	scrolldelta(lines);}static void lf(struct vc_data *vc){    	/* don't scroll if above bottom of scrolling region, or	 * if below scrolling region	 */    	if (vc->vc_y + 1 == vc->vc_bottom)		scrup(vc, vc->vc_top, vc->vc_bottom, 1);	else if (vc->vc_y < vc->vc_rows - 1) {	    	vc->vc_y++;		vc->vc_pos += vc->vc_size_row;	}	vc->vc_need_wrap = 0;	notify_write(vc, '\n');}static void ri(struct vc_data *vc){    	/* don't scroll if below top of scrolling region, or	 * if above scrolling region	 */	if (vc->vc_y == vc->vc_top)		scrdown(vc, vc->vc_top, vc->vc_bottom, 1);	else if (vc->vc_y > 0) {		vc->vc_y--;		vc->vc_pos -= vc->vc_size_row;	}	vc->vc_need_wrap = 0;}static inline void cr(struct vc_data *vc){	vc->vc_pos -= vc->vc_x << 1;	vc->vc_need_wrap = vc->vc_x = 0;	notify_write(vc, '\r');}static inline void bs(struct vc_data *vc){	if (vc->vc_x) {		vc->vc_pos -= 2;		vc->vc_x--;		vc->vc_need_wrap = 0;		notify_write(vc, '\b');	}}static inline void del(struct vc_data *vc){	/* ignored */}static void csi_J(struct vc_data *vc, int vpar){	unsigned int count;	unsigned short * start;	switch (vpar) {		case 0:	/* erase from cursor to end of display */			count = (vc->vc_scr_end - vc->vc_pos) >> 1;			start = (unsigned short *)vc->vc_pos;			if (DO_UPDATE(vc)) {				/* do in two stages */				vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,					      vc->vc_cols - vc->vc_x);				vc->vc_sw->con_clear(vc, vc->vc_y + 1, 0,					      vc->vc_rows - vc->vc_y - 1,					      vc->vc_cols);			}			break;		case 1:	/* erase from start to cursor */			count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;			start = (unsigned short *)vc->vc_origin;			if (DO_UPDATE(vc)) {				/* do in two stages */				vc->vc_sw->con_clear(vc, 0, 0, vc->vc_y,					      vc->vc_cols);				vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,					      vc->vc_x + 1);			}			break;		case 2: /* erase whole display */			count = vc->vc_cols * vc->vc_rows;			start = (unsigned short *)vc->vc_origin;			if (DO_UPDATE(vc))				vc->vc_sw->con_clear(vc, 0, 0,					      vc->vc_rows,					      vc->vc_cols);			break;		default:			return;	}	scr_memsetw(start, vc->vc_video_erase_char, 2 * count);	vc->vc_need_wrap = 0;}static void csi_K(struct vc_data *vc, int vpar){	unsigned int count;	unsigned short * start;	switch (vpar) {		case 0:	/* erase from cursor to end of line */			count = vc->vc_cols - vc->vc_x;			start = (unsigned short *)vc->vc_pos;			if (DO_UPDATE(vc))				vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,						     vc->vc_cols - vc->vc_x);			break;		case 1:	/* erase from start of line to cursor */			start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));			count = vc->vc_x + 1;			if (DO_UPDATE(vc))				vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,						     vc->vc_x + 1);			break;		case 2: /* erase whole line */			start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));			count = vc->vc_cols;			if (DO_UPDATE(vc))				vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,					      vc->vc_cols);			break;		default:			return;	}	scr_memsetw(start, vc->vc_video_erase_char, 2 * count);	vc->vc_need_wrap = 0;}static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */{					  /* not vt100? */	int count;	if (!vpar)		vpar++;	count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar;	scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);	if (DO_UPDATE(vc))		vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count);	vc->vc_need_wrap = 0;}static void default_attr(struct vc_data *vc){	vc->vc_intensity = 1;	vc->vc_italic = 0;	vc->vc_underline = 0;	vc->vc_reverse = 0;	vc->vc_blink = 0;	vc->vc_color = vc->vc_def_color;}/* console_sem is held */static void csi_m(struct vc_data *vc){	int i;	for (i = 0; i <= vc->vc_npar; i++)		switch (vc->vc_par[i]) {			case 0:	/* all attributes off */				default_attr(vc);				break;			case 1:				vc->vc_intensity = 2;				break;			case 2:				vc->vc_intensity = 0;				break;			case 3:				vc->vc_italic = 1;				break;			case 4:				vc->vc_underline = 1;				break;			case 5:				vc->vc_blink = 1;				break;			case 7:				vc->vc_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.				  */				vc->vc_translate = set_translate(vc->vc_charset == 0						? vc->vc_G0_charset						: vc->vc_G1_charset, vc);				vc->vc_disp_ctrl = 0;				vc->vc_toggle_meta = 0;				break;			case 11: /* ANSI X3.64-1979 (SCO-ish?)				  * Select first alternate font, lets				  * chars < 32 be displayed as ROM chars.				  */				vc->vc_translate = set_translate(IBMPC_MAP, vc);				vc->vc_disp_ctrl = 1;				vc->vc_toggle_meta = 0;				break;			case 12: /* ANSI X3.64-1979 (SCO-ish?)				  * Select second alternate font, toggle				  * high bit before displaying as ROM char.				  */				vc->vc_translate = set_translate(IBMPC_MAP, vc);				vc->vc_disp_ctrl = 1;				vc->vc_toggle_meta = 1;				break;			case 21:			case 22:				vc->vc_intensity = 1;				break;			case 23:				vc->vc_italic = 0;				break;			case 24:				vc->vc_underline = 0;				break;			case 25:				vc->vc_blink = 0;				break;			case 27:				vc->vc_reverse = 0;				break;			case 38: /* ANSI X3.64-1979 (SCO-ish?)				  * Enables underscore, white foreground				  * with white underscore (Linux - use				  * default foreground).				  */				vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0);				vc->vc_underline = 1;				break;			case 39: /* ANSI X3.64-1979 (SCO-ish?)				  * Disable underline option.				  * Reset colour to default? It did this				  * before...				  */				vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0);				vc->vc_underline = 0;				break;			case 49:				vc->vc_color = (vc->vc_def_color & 0xf0) | (vc->vc_color & 0x0f);				break;			default:				if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)					vc->vc_color = color_table[vc->vc_par[i] - 30]						| (vc->vc_color & 0xf0);				else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47)					vc->vc_color = (color_table[vc->vc_par[i] - 40] << 4)						| (vc->vc_color & 0x0f);				break;		}	update_attr(vc);}static void respond_string(const char *p, struct tty_struct *tty){	while (*p) {		tty_insert_flip_char(tty, *p, 0);		p++;	}	con_schedule_flip(tty);}static void cursor_report(struct vc_data *vc, struct tty_struct *tty){	char buf[40];	sprintf(buf, "\033[%d;%dR", vc->vc_y + (vc->vc_decom ? vc->vc_top + 1 : 1), vc->vc_x + 1);	respond_string(buf, tty);}static inline void status_report(struct tty_struct *tty){	respond_string("\033[0n", tty);	/* Terminal ok */}static inline void respond_ID(struct tty_struct * tty){	respond_string(VT102ID, tty);}void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry){	char buf[8];	sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),		(char)('!' + mry));	respond_string(buf, tty);}/* invoked via ioctl(TIOCLINUX) and through set_selection */int mouse_reporting(void){	return vc_cons[fg_console].d->vc_report_mouse;}/* console_sem is held */static void set_mode(struct vc_data *vc, int on_off){	int i;	for (i = 0; i <= vc->vc_npar; i++)		if (vc->vc_ques) {			switch(vc->vc_par[i]) {	/* DEC private modes set/reset */			case 1:			/* Cursor keys send ^[Ox/^[[x */				if (on_off)					set_kbd(vc, decckm);				else					clr_kbd(vc, decckm);				break;			case 3:	/* 80/132 mode switch unimplemented */				vc->vc_deccolm = on_off;#if 0				vc_resize(deccolm ? 132 : 80, vc->vc_rows);				/* this alone does not suffice; some user mode				   utility has to change the hardware regs */#endif				break;			case 5:			/* Inverted screen on/off */				if (vc->vc_decscnm != on_off) {					vc->vc_decscnm = on_off;					invert_screen(vc, 0, vc->vc_screenbuf_size, 0);					update_attr(vc);				}				break;			case 6:			/* Origin relative/absolute */				vc->vc_decom = on_off;				gotoxay(vc, 0, 0);				break;			case 7:			/* Autowrap on/off */				vc->vc_decawm = on_off;				break;			case 8:			/* Autorepeat on/off */				if (on_off)					set_kbd(vc, decarm);				else					clr_kbd(vc, decarm);				break;			case 9:				vc->vc_report_mouse = on_off ? 1 : 0;				break;			case 25:		/* Cursor on/off */				vc->vc_deccm = on_off;				break;			case 1000:				vc->vc_report_mouse = on_off ? 2 : 0;				break;			}		} else {			switch(vc->vc_par[i]) {	/* ANSI modes set/reset */			case 3:			/* Monitor (display ctrls) */				vc->vc_disp_ctrl = on_off;				break;			case 4:			/* Insert Mode on/off */				vc->vc_decim = on_off;				break;			case 20:		/* Lf, Enter == CrLf/Lf */				if (on_off)					set_kbd(vc, lnm);				else					clr_kbd(vc, lnm);				break;			}		}}/* console_sem is held */static void setterm_command(struct vc_data *vc){	switch(vc->vc_par[0]) {		case 1:	/* set color for underline mode */			if (vc->vc_can_do_color &&					vc->vc_par[1] < 16) {				vc->vc_ulcolor = color_table[vc->vc_par[1]];				if (vc->vc_underline)					update_attr(vc);			}			break;		case 2:	/* set color for half intensity mode */			if (vc->vc_can_do_color &&					vc->vc_par[1] < 16) {				vc->vc_halfcolor = color_table[vc->vc_par[1]];				if (vc->vc_intensity == 0)					update_attr(vc);			}			break;		case 8:	/* store colors as defaults */			vc->vc_def_color = vc->vc_attr;			if (vc->vc_hi_font_mask == 0x100)				vc->vc_def_color >>= 1;			default_attr(vc);			update_attr(vc);			break;		case 9:	/* set blanking interval */			blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ;			poke_blanked_console();			break;		case 10: /* set bell frequency in Hz */			if (vc->vc_npar >= 1)				vc->vc_bell_pitch = vc->vc_par[1];			else				vc->vc_bell_pitch = DEFAULT_BELL_PITCH;			break;		case 11: /* set bell duration in msec */			if (vc->vc_npar >= 1)				vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?					vc->vc_par[1] * HZ / 1000 : 0;			else				vc->vc_bell_duration = DEFAULT_BELL_DURATION;			break;		case 12: /* bring specified console to the front */			if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1))				set_console(vc->vc_par[1] - 1);			break;		case 13: /* unblank the screen */			poke_blanked_console();			break;		case 14: /* set vesa powerdown interval */			vesa_off_interval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ;			break;		case 15: /* activate the previous console */			set_console(last_console);			break;	}}/* console_sem is held */static void csi_at(struct vc_data *vc, unsigned int nr){	if (nr > vc->vc_cols - vc->vc_x)		nr = vc->vc_cols - vc->vc_x;	else if (!nr)		nr = 1;	insert_char(vc, nr);}/* console_sem is held */static void csi_L(struct vc_data *vc, unsigned int nr){	if (nr > vc->vc_rows - vc->vc_y)		nr = vc->vc_rows - vc->vc_y;	else if (!nr)		nr = 1;	scrdown(vc, vc->vc_y, vc->vc_bottom, nr);	vc->vc_need_wrap = 0;}/* console_sem is held */static void csi_P(struct vc_data *vc, unsigned int nr){	if (nr > vc->vc_cols - vc->vc_x)		nr = vc->vc_cols - vc->vc_x;	else if (!nr)		nr = 1;	delete_char(vc, nr);}/* console_sem is held */static void csi_M(struct vc_data *vc, unsigned int nr){	if (nr > vc->vc_rows - vc->vc_y)		nr = vc->vc_rows - vc->vc_y;	else if (!nr)		nr=1;	scrup(vc, vc->vc_y, vc->vc_bottom, nr);	vc->vc_need_wrap = 0;}/* console_sem is held (except via vc_init->reset_terminal */static void save_cur(struct vc_data *vc){	vc->vc_saved_x		= vc->vc_x;	vc->vc_saved_y		= vc->vc_y;	vc->vc_s_intensity	= vc->vc_intensity;	vc->vc_s_italic         = vc->vc_italic;	vc->vc_s_underline	= vc->vc_underline;	vc->vc_s_blink		= vc->vc_blink;	vc->vc_s_reverse	= vc->vc_reverse;	vc->vc_s_charset	= vc->vc_charset;	vc->vc_s_color		= vc->vc_color;	vc->vc_saved_G0		= vc->vc_G0_charset;	vc->vc_saved_G1		= vc->vc_G1_charset;}/* console_sem is held */static void restore_cur(struct vc_data *vc){	gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y);	vc->vc_intensity	= vc->vc_s_intensity;	vc->vc_italic		= vc->vc_s_italic;	vc->vc_underline	= vc->vc_s_underline;	vc->vc_blink		= vc->vc_s_blink;	vc->vc_reverse		= vc->vc_s_reverse;	vc->vc_charset		= vc->vc_s_charset;	vc->vc_color		= vc->vc_s_color;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?