📄 refresh.c
字号:
/* * Copyright (c) 1981, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 7/20/93";#endif /* not lint */#include <curses.h>#include <string.h>static int curwin;static short ly, lx;static void domvcur __P((int, int, int, int));static int makech __P((WINDOW *, int));static void quickch __P((WINDOW *)); static void scrolln __P((WINDOW *, int, int, int, int, int));/* * wrefresh -- * Make the current screen look like "win" over the area coverd by * win. */intwrefresh(win) register WINDOW *win;{ register __LINE *wlp; register int retval; register short wy; int dnum; /* Initialize loop parameters. */ ly = curscr->cury; lx = curscr->curx; wy = 0; curwin = (win == curscr); if (!curwin) for (wy = 0; wy < win->maxy; wy++) { wlp = win->lines[wy]; if (wlp->flags & __ISDIRTY) wlp->hash = __hash((char *) wlp->line, win->maxx * __LDATASIZE); } if (win->flags & __CLEAROK || curscr->flags & __CLEAROK || curwin) { if ((win->flags & __FULLWIN) || curscr->flags & __CLEAROK) { tputs(CL, 0, __cputchar); ly = 0; lx = 0; if (!curwin) { curscr->flags &= ~__CLEAROK; curscr->cury = 0; curscr->curx = 0; werase(curscr); } __touchwin(win); } win->flags &= ~__CLEAROK; } if (!CA) { if (win->curx != 0) putchar('\n'); if (!curwin) werase(curscr); }#ifdef DEBUG __CTRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin); __CTRACE("wrefresh: \tfirstch\tlastch\n");#endif#ifndef NOQCH if ((win->flags & __FULLWIN) && !curwin) { /* * Invoke quickch() only if more than a quarter of the lines * in the window are dirty. */ for (wy = 0, dnum = 0; wy < win->maxy; wy++) if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) dnum++; if (!__noqch && dnum > (int) win->maxy / 4) quickch(win); }#endif#ifdef DEBUG{ int i, j; __CTRACE("#####################################\n"); for (i = 0; i < curscr->maxy; i++) { __CTRACE("C: %d:", i); __CTRACE(" 0x%x \n", curscr->lines[i]->hash); for (j = 0; j < curscr->maxx; j++) __CTRACE("%c", curscr->lines[i]->line[j].ch); __CTRACE("\n"); for (j = 0; j < curscr->maxx; j++) __CTRACE("%x", curscr->lines[i]->line[j].attr); __CTRACE("\n"); __CTRACE("W: %d:", i); __CTRACE(" 0x%x \n", win->lines[i]->hash); __CTRACE(" 0x%x ", win->lines[i]->flags); for (j = 0; j < win->maxx; j++) __CTRACE("%c", win->lines[i]->line[j].ch); __CTRACE("\n"); for (j = 0; j < win->maxx; j++) __CTRACE("%x", win->lines[i]->line[j].attr); __CTRACE("\n"); }}#endif /* DEBUG */ for (wy = 0; wy < win->maxy; wy++) {#ifdef DEBUG __CTRACE("%d\t%d\t%d\n", wy, *win->lines[wy]->firstchp, *win->lines[wy]->lastchp);#endif if (!curwin) curscr->lines[wy]->hash = win->lines[wy]->hash; if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) { if (makech(win, wy) == ERR) return (ERR); else { if (*win->lines[wy]->firstchp >= win->ch_off) *win->lines[wy]->firstchp = win->maxx + win->ch_off; if (*win->lines[wy]->lastchp < win->maxx + win->ch_off) *win->lines[wy]->lastchp = win->ch_off; if (*win->lines[wy]->lastchp < *win->lines[wy]->firstchp) {#ifdef DEBUG __CTRACE("wrefresh: line %d notdirty \n", wy);#endif win->lines[wy]->flags &= ~__ISDIRTY; } } }#ifdef DEBUG __CTRACE("\t%d\t%d\n", *win->lines[wy]->firstchp, *win->lines[wy]->lastchp);#endif } #ifdef DEBUG __CTRACE("refresh: ly=%d, lx=%d\n", ly, lx);#endif if (win == curscr) domvcur(ly, lx, win->cury, win->curx); else { if (win->flags & __LEAVEOK) { curscr->cury = ly; curscr->curx = lx; ly -= win->begy; lx -= win->begx; if (ly >= 0 && ly < win->maxy && lx >= 0 && lx < win->maxx) { win->cury = ly; win->curx = lx; } else win->cury = win->curx = 0; } else { domvcur(ly, lx, win->cury + win->begy, win->curx + win->begx); curscr->cury = win->cury + win->begy; curscr->curx = win->curx + win->begx; } } retval = OK; (void)fflush(stdout); return (retval);}/* * makech -- * Make a change on the screen. */static intmakech(win, wy) register WINDOW *win; int wy;{ static __LDATA blank = {' ', 0}; register int nlsp, clsp; /* Last space in lines. */ register int wx, lch, y; register __LDATA *nsp, *csp, *cp, *cep; u_int force; char *ce; /* Is the cursor still on the end of the last line? */ if (wy > 0 && win->lines[wy - 1]->flags & __ISPASTEOL) { domvcur(ly, lx, ly + 1, 0); ly++; lx = 0; } wx = *win->lines[wy]->firstchp - win->ch_off; if (wx < 0) wx = 0; else if (wx >= win->maxx) return (OK); lch = *win->lines[wy]->lastchp - win->ch_off; if (lch < 0) return (OK); else if (lch >= (int) win->maxx) lch = win->maxx - 1; y = wy + win->begy; if (curwin) csp = ␣ else csp = &curscr->lines[wy + win->begy]->line[wx + win->begx]; nsp = &win->lines[wy]->line[wx]; force = win->lines[wy]->flags & __FORCEPAINT; win->lines[wy]->flags &= ~__FORCEPAINT; if (CE && !curwin) { for (cp = &win->lines[wy]->line[win->maxx - 1]; cp->ch == ' ' && cp->attr == 0; cp--) if (cp <= win->lines[wy]->line) break; nlsp = cp - win->lines[wy]->line; } if (!curwin) ce = CE; else ce = NULL; if (force) { if (CM) tputs(tgoto(CM, lx, ly), 0, __cputchar); else { tputs(HO, 0, __cputchar); __mvcur(0, 0, ly, lx, 1); } } while (wx <= lch) { if (!force && memcmp(nsp, csp, sizeof(__LDATA)) == 0) { if (wx <= lch) { while (wx <= lch && memcmp(nsp, csp, sizeof(__LDATA)) == 0) { nsp++; if (!curwin) csp++; ++wx; } continue; } break; } domvcur(ly, lx, y, wx + win->begx);#ifdef DEBUG __CTRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d, force =%d\n", wx, ly, lx, y, wx + win->begx, force);#endif ly = y; lx = wx + win->begx; while ((force || memcmp(nsp, csp, sizeof(__LDATA)) != 0) && wx <= lch) { if (ce != NULL && win->maxx + win->begx == curscr->maxx && wx >= nlsp && nsp->ch == ' ') { /* Check for clear to end-of-line. */ cep = &curscr->lines[wy]->line[win->maxx - 1]; while (cep->ch == ' ' && cep->attr == 0) if (cep-- <= csp) break; clsp = cep - curscr->lines[wy]->line - win->begx * __LDATASIZE;#ifdef DEBUG __CTRACE("makech: clsp = %d, nlsp = %d\n", clsp, nlsp);#endif if ((clsp - nlsp >= strlen(CE) && clsp < win->maxx * __LDATASIZE) || wy == win->maxy - 1) {#ifdef DEBUG __CTRACE("makech: using CE\n");#endif tputs(CE, 0, __cputchar); lx = wx + win->begx; while (wx++ <= clsp) { csp->ch = ' '; csp->attr = 0; csp++; } return (OK); } ce = NULL; } /* Enter/exit standout mode as appropriate. */ if (SO && (nsp->attr & __STANDOUT) != (curscr->flags & __WSTANDOUT)) { if (nsp->attr & __STANDOUT) { tputs(SO, 0, __cputchar); curscr->flags |= __WSTANDOUT; } else { tputs(SE, 0, __cputchar); curscr->flags &= ~__WSTANDOUT; } } wx++; if (wx >= win->maxx && wy == win->maxy - 1 && !curwin) if (win->flags & __SCROLLOK) { if (curscr->flags & __WSTANDOUT && win->flags & __ENDLINE) if (!MS) { tputs(SE, 0, __cputchar); curscr->flags &= ~__WSTANDOUT; } if (!(win->flags & __SCROLLWIN)) { if (!curwin) { csp->attr = nsp->attr; putchar(csp->ch = nsp->ch); } else putchar(nsp->ch); } if (wx + win->begx < curscr->maxx) { domvcur(ly, wx + win->begx, win->begy + win->maxy - 1, win->begx + win->maxx - 1); } ly = win->begy + win->maxy - 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -