⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tty_update.c

📁 ncurses-5.4 需要的就来下把 一定会有用的哦
💻 C
📖 第 1 页 / 共 4 页
字号:
	while (count) {	    PutAttrChar(CHREF(*line));	    line++;	    count--;	}    } else if (enter_insert_mode && exit_insert_mode) {	TPUTS_TRACE("enter_insert_mode");	putp(enter_insert_mode);	while (count) {	    PutAttrChar(CHREF(*line));	    if (insert_padding) {		TPUTS_TRACE("insert_padding");		putp(insert_padding);	    }	    line++;	    count--;	}	TPUTS_TRACE("exit_insert_mode");	putp(exit_insert_mode);    } else {	while (count) {	    TPUTS_TRACE("insert_character");	    putp(insert_character);	    PutAttrChar(CHREF(*line));	    if (insert_padding) {		TPUTS_TRACE("insert_padding");		putp(insert_padding);	    }	    line++;	    count--;	}    }    position_check(SP->_cursrow, SP->_curscol, "InsStr");}/***	DelChar(count)****	Delete count characters at current position***/static voidDelChar(int count){    int n;    TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%d,%d)", count,		      newscr->_cury, newscr->_curx));    if (parm_dch) {	TPUTS_TRACE("parm_dch");	tputs(tparm(parm_dch, count), count, _nc_outch);    } else {	for (n = 0; n < count; n++) {	    TPUTS_TRACE("delete_character");	    putp(delete_character);	}    }}/* * Physical-scrolling support * * This code was adapted from Keith Bostic's hardware scrolling * support for 4.4BSD curses.  I (esr) translated it to use terminfo * capabilities, narrowed the call interface slightly, and cleaned * up some convoluted tests.  I also added support for the memory_above * memory_below, and non_dest_scroll_region capabilities. * * For this code to work, we must have either * change_scroll_region and scroll forward/reverse commands, or * insert and delete line capabilities. * When the scrolling region has been set, the cursor has to * be at the last line of the region to make the scroll up * happen, or on the first line of region to scroll down. * * This code makes one aesthetic decision in the opposite way from * BSD curses.  BSD curses preferred pairs of il/dl operations * over scrolls, allegedly because il/dl looked faster.  We, on * the other hand, prefer scrolls because (a) they're just as fast * on many terminals and (b) using them avoids bouncing an * unchanged bottom section of the screen up and down, which is * visually nasty. * * (lav): added more cases, used dl/il when bot==maxy and in csr case. * * I used assumption that capabilities il/il1/dl/dl1 work inside * changed scroll region not shifting screen contents outside of it. * If there are any terminals behaving different way, it would be * necessary to add some conditions to scroll_csr_forward/backward. *//* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */static intscroll_csr_forward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank){    int i;    if (n == 1 && scroll_forward && top == miny && bot == maxy) {	GoTo(bot, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("scroll_forward");	putp(scroll_forward);    } else if (n == 1 && delete_line && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("delete_line");	putp(delete_line);    } else if (parm_index && top == miny && bot == maxy) {	GoTo(bot, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("parm_index");	tputs(tparm(parm_index, n, 0), n, _nc_outch);    } else if (parm_delete_line && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("parm_delete_line");	tputs(tparm(parm_delete_line, n, 0), n, _nc_outch);    } else if (scroll_forward && top == miny && bot == maxy) {	GoTo(bot, 0);	UpdateAttrs(AttrOf(blank));	for (i = 0; i < n; i++) {	    TPUTS_TRACE("scroll_forward");	    putp(scroll_forward);	}    } else if (delete_line && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	for (i = 0; i < n; i++) {	    TPUTS_TRACE("delete_line");	    putp(delete_line);	}    } else	return ERR;#if NCURSES_EXT_FUNCS    if (FILL_BCE()) {	int j;	for (i = 0; i < n; i++) {	    GoTo(bot - i, 0);	    for (j = 0; j < screen_columns; j++)		PutChar(CHREF(blank));	}    }#endif    return OK;}/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure *//* n > 0 */static intscroll_csr_backward(int n, int top, int bot, int miny, int maxy,		    NCURSES_CH_T blank){    int i;    if (n == 1 && scroll_reverse && top == miny && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("scroll_reverse");	putp(scroll_reverse);    } else if (n == 1 && insert_line && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("insert_line");	putp(insert_line);    } else if (parm_rindex && top == miny && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("parm_rindex");	tputs(tparm(parm_rindex, n, 0), n, _nc_outch);    } else if (parm_insert_line && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	TPUTS_TRACE("parm_insert_line");	tputs(tparm(parm_insert_line, n, 0), n, _nc_outch);    } else if (scroll_reverse && top == miny && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	for (i = 0; i < n; i++) {	    TPUTS_TRACE("scroll_reverse");	    putp(scroll_reverse);	}    } else if (insert_line && bot == maxy) {	GoTo(top, 0);	UpdateAttrs(AttrOf(blank));	for (i = 0; i < n; i++) {	    TPUTS_TRACE("insert_line");	    putp(insert_line);	}    } else	return ERR;#if NCURSES_EXT_FUNCS    if (FILL_BCE()) {	int j;	for (i = 0; i < n; i++) {	    GoTo(top + i, 0);	    for (j = 0; j < screen_columns; j++)		PutChar(CHREF(blank));	}    }#endif    return OK;}/* scroll by using delete_line at del and insert_line at ins *//* n > 0 */static intscroll_idl(int n, int del, int ins, NCURSES_CH_T blank){    int i;    if (!((parm_delete_line || delete_line) && (parm_insert_line || insert_line)))	return ERR;    GoTo(del, 0);    UpdateAttrs(AttrOf(blank));    if (n == 1 && delete_line) {	TPUTS_TRACE("delete_line");	putp(delete_line);    } else if (parm_delete_line) {	TPUTS_TRACE("parm_delete_line");	tputs(tparm(parm_delete_line, n, 0), n, _nc_outch);    } else {			/* if (delete_line) */	for (i = 0; i < n; i++) {	    TPUTS_TRACE("delete_line");	    putp(delete_line);	}    }    GoTo(ins, 0);    UpdateAttrs(AttrOf(blank));    if (n == 1 && insert_line) {	TPUTS_TRACE("insert_line");	putp(insert_line);    } else if (parm_insert_line) {	TPUTS_TRACE("parm_insert_line");	tputs(tparm(parm_insert_line, n, 0), n, _nc_outch);    } else {			/* if (insert_line) */	for (i = 0; i < n; i++) {	    TPUTS_TRACE("insert_line");	    putp(insert_line);	}    }    return OK;}/* * Note:  some terminals require the cursor to be within the scrolling margins * before setting them.  Generally, the cursor must be at the appropriate end * of the scrolling margins when issuing an indexing operation (it is not * apparent whether it must also be at the left margin; we do this just to be * safe).  To make the related cursor movement a little faster, we use the * save/restore cursor capabilities if the terminal has them. */NCURSES_EXPORT(int)_nc_scrolln(int n, int top, int bot, int maxy)/* scroll region from top to bot by n lines */{    NCURSES_CH_T blank = ClrBlank(stdscr);    int i;    bool cursor_saved = FALSE;    int res;    TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy));#if USE_XMC_SUPPORT    /*     * If we scroll, we might remove a cookie.     */    if (magic_cookie_glitch > 0) {	return (ERR);    }#endif    if (n > 0) {		/* scroll up (forward) */	/*	 * Explicitly clear if stuff pushed off top of region might	 * be saved by the terminal.	 */	res = scroll_csr_forward(n, top, bot, 0, maxy, blank);	if (res == ERR && change_scroll_region) {	    if ((((n == 1 && scroll_forward) || parm_index)		 && (SP->_cursrow == bot || SP->_cursrow == bot - 1))		&& save_cursor && restore_cursor) {		cursor_saved = TRUE;		TPUTS_TRACE("save_cursor");		putp(save_cursor);	    }	    TPUTS_TRACE("change_scroll_region");	    putp(tparm(change_scroll_region, top, bot));	    if (cursor_saved) {		TPUTS_TRACE("restore_cursor");		putp(restore_cursor);	    } else {		SP->_cursrow = SP->_curscol = -1;	    }	    res = scroll_csr_forward(n, top, bot, top, bot, blank);	    TPUTS_TRACE("change_scroll_region");	    putp(tparm(change_scroll_region, 0, maxy));	    SP->_cursrow = SP->_curscol = -1;	}	if (res == ERR && _nc_idlok)	    res = scroll_idl(n, top, bot - n + 1, blank);	/*	 * Clear the newly shifted-in text.	 */	if (res != ERR	    && (non_dest_scroll_region || (memory_below && bot == maxy))) {	    NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);	    if (bot == maxy && clr_eos) {		GoTo(bot - n + 1, 0);		ClrToEOS(blank2);	    } else {		for (i = 0; i < n; i++) {		    GoTo(bot - i, 0);		    ClrToEOL(blank2, FALSE);		}	    }	}    } else {			/* (n < 0) - scroll down (backward) */	res = scroll_csr_backward(-n, top, bot, 0, maxy, blank);	if (res == ERR && change_scroll_region) {	    if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top - 1)		&& save_cursor && restore_cursor) {		cursor_saved = TRUE;		TPUTS_TRACE("save_cursor");		putp(save_cursor);	    }	    TPUTS_TRACE("change_scroll_region");	    putp(tparm(change_scroll_region, top, bot));	    if (cursor_saved) {		TPUTS_TRACE("restore_cursor");		putp(restore_cursor);	    } else {		SP->_cursrow = SP->_curscol = -1;	    }	    res = scroll_csr_backward(-n, top, bot, top, bot, blank);	    TPUTS_TRACE("change_scroll_region");	    putp(tparm(change_scroll_region, 0, maxy));	    SP->_cursrow = SP->_curscol = -1;	}	if (res == ERR && _nc_idlok)	    res = scroll_idl(-n, bot + n + 1, top, blank);	/*	 * Clear the newly shifted-in text.	 */	if (res != ERR	    && (non_dest_scroll_region || (memory_above && top == 0))) {	    NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);	    for (i = 0; i < -n; i++) {		GoTo(i + top, 0);		ClrToEOL(blank2, FALSE);	    }	}    }    if (res == ERR)	return (ERR);    _nc_scroll_window(curscr, n, top, bot, blank);    /* shift hash values too - they can be reused */    _nc_scroll_oldhash(n, top, bot);    return (OK);}NCURSES_EXPORT(void)_nc_screen_resume(void){    /* make sure terminal is in a sane known state */    SP->_current_attr = A_NORMAL;    newscr->_clear = TRUE;    /* reset color pairs and definitions */    if (SP->_coloron || SP->_color_defs)	_nc_reset_colors();    /* restore user-defined colors, if any */    if (SP->_color_defs < 0) {	int n;	SP->_color_defs = -(SP->_color_defs);	for (n = 0; n < SP->_color_defs; ++n) {	    if (SP->_color_table[n].init) {		init_color(n,			   SP->_color_table[n].r,			   SP->_color_table[n].g,			   SP->_color_table[n].b);	    }	}    }    if (exit_attribute_mode)	putp(exit_attribute_mode);    else {	/* turn off attributes */	if (exit_alt_charset_mode)	    putp(exit_alt_charset_mode);	if (exit_standout_mode)	    putp(exit_standout_mode);	if (exit_underline_mode)	    putp(exit_underline_mode);    }    if (exit_insert_mode)	putp(exit_insert_mode);    if (enter_am_mode && exit_am_mode)	putp(auto_right_margin ? enter_am_mode : exit_am_mode);}NCURSES_EXPORT(void)_nc_screen_init(void){    _nc_screen_resume();}/* wrap up screen handling */NCURSES_EXPORT(void)_nc_screen_wrap(void){    UpdateAttrs(A_NORMAL);#if NCURSES_EXT_FUNCS    if (SP->_coloron	&& !SP->_default_color) {	NCURSES_CH_T blank = NewChar(BLANK_TEXT);	SP->_default_color = TRUE;	_nc_do_color(-1, 0, FALSE, _nc_outch);	SP->_default_color = FALSE;	mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0);	ClrToEOL(blank, TRUE);    }#endif    if (SP->_color_defs) {	_nc_reset_colors();    }}#if USE_XMC_SUPPORTNCURSES_EXPORT(void)_nc_do_xmc_glitch(attr_t previous){    attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr);    while (chg != 0) {	if (chg & 1) {	    SP->_curscol += magic_cookie_glitch;	    if (SP->_curscol >= SP->_columns)		wrap_cursor();	    TR(TRACE_UPDATE, ("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol));	}	chg >>= 1;    }}#endif /* USE_XMC_SUPPORT */

⌨️ 快捷键说明

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