rxvtlib_screen.c
来自「具有IDE功能的编辑器」· C语言 代码 · 共 2,128 行 · 第 1/5 页
C
2,128 行
#else /* drive with your eyes closed */ MAX_IT (o->screen.cur.row, 0); MAX_IT (o->screen.cur.col, 0);#endif}/* ------------------------------------------------------------------------- *//* * Swap between primary and secondary screens * XTERM_SEQ: Primary screen : ESC [ ? 4 7 h * XTERM_SEQ: Secondary screen: ESC [ ? 4 7 l *//* EXTPROTO */int rxvtlib_scr_change_screen (rxvtlib *o, int scrn){ int i, tmp;#if NSCREENS int offset; text_t *t0; rend_t *r0; short l0;#endif o->want_refresh = 1; D_SCREEN ((stderr, "scr_change_screen(%d)", scrn)); o->TermWin.view_start = 0; RESET_CHSTAT; if (o->current_screen == scrn) return o->current_screen; CHECK_SELECTION (2); /* check for boundary cross */ SWAP_IT (o->current_screen, scrn, tmp);#if NSCREENS offset = o->TermWin.saveLines; for (i = o->TermWin.nrow; i--;) { SWAP_IT (o->screen.text[i + offset], o->swap.text[i], t0); SWAP_IT (o->screen.tlen[i + offset], o->swap.tlen[i], l0); SWAP_IT (o->screen.rend[i + offset], o->swap.rend[i], r0); } SWAP_IT (o->screen.cur.row, o->swap.cur.row, l0); SWAP_IT (o->screen.cur.col, o->swap.cur.col, l0);# ifdef DEBUG_STRICT assert (o->screen.cur.row >= 0); assert (o->screen.cur.col >= 0); assert (o->screen.cur.row < o->TermWin.nrow); assert (o->screen.cur.col < o->TermWin.ncol);# else /* drive with your eyes closed */ MAX_IT (o->screen.cur.row, 0); MAX_IT (o->screen.cur.col, 0); MIN_IT (o->screen.cur.row, o->TermWin.nrow - 1); MIN_IT (o->screen.cur.col, o->TermWin.ncol - 1);# endif SWAP_IT (o->screen.charset, o->swap.charset, l0); SWAP_IT (o->screen.flags, o->swap.flags, tmp); o->screen.flags |= Screen_VisibleCursor; o->swap.flags |= Screen_VisibleCursor; if (rxvtlib_Gr_Displayed (o)) { rxvtlib_Gr_scroll (o, 0); rxvtlib_Gr_ChangeScreen (o); }#else# ifdef SCROLL_ON_NO_SECONDARY if (rxvtlib_Gr_Displayed (o)) rxvtlib_Gr_ClearScreen (o); if (o->current_screen == PRIMARY) { if (!rxvtlib_Gr_Displayed (o)) rxvtlib_scroll_text (o, 0, (o->TermWin.nrow - 1), o->TermWin.nrow, 0); for (i = o->TermWin.saveLines; i < o->TermWin.nrow + o->TermWin.saveLines; i++) if (o->screen.text[i] == NULL) { rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, i, DEFAULT_RSTYLE); o->screen.tlen[i] = 0; } }# endif#endif return scrn;}/* ------------------------------------------------------------------------- *//* * Change the colour for following text *//* EXTPROTO */void rxvtlib_scr_color (rxvtlib *o, unsigned int color, unsigned int Intensity){ if (color == restoreFG) color = Color_fg; else if (color == restoreBG) color = Color_bg; else { if (o->Xdepth <= 2) { /* Monochrome - ignore colour changes */ switch (Intensity) { case RS_Bold: color = Color_fg; break; case RS_Blink: color = Color_bg; break; } } else {#ifndef NO_BRIGHTCOLOR if ((o->rstyle & Intensity) && color >= minCOLOR && color <= maxCOLOR) color += (minBrightCOLOR - minCOLOR); else if (color >= minBrightCOLOR && color <= maxBrightCOLOR) { if (o->rstyle & Intensity) return; color -= (minBrightCOLOR - minCOLOR); }#endif } } switch (Intensity) { case RS_Bold: o->rstyle = SET_FGCOLOR (o->rstyle, color); break; case RS_Blink: o->rstyle = SET_BGCOLOR (o->rstyle, color); break; }}/* ------------------------------------------------------------------------- *//* * Change the rendition style for following text *//* EXTPROTO */void rxvtlib_scr_rendition (rxvtlib *o, int set, int style){ unsigned int color; rend_t font_attr; if (set) {/* A: Set style */ o->rstyle |= style; switch (style) { case RS_RVid: if (o->rvideo) o->rstyle &= ~RS_RVid; break;#ifndef NO_BRIGHTCOLOR case RS_Bold: color = GET_FGCOLOR (o->rstyle); rxvtlib_scr_color (o, (color == Color_fg ? GET_FGCOLOR (o->colorfgbg) : color), RS_Bold); break; case RS_Blink: color = GET_BGCOLOR (o->rstyle); rxvtlib_scr_color (o, (color == Color_bg ? GET_BGCOLOR (o->colorfgbg) : color), RS_Blink); break;#endif } } else {/* B: Unset style */ font_attr = o->rstyle & RS_fontMask; o->rstyle &= ~style; switch (style) { case ~RS_None: /* default fg/bg colours */ o->rstyle = DEFAULT_RSTYLE | font_attr; /* FALLTHROUGH */ case RS_RVid: if (o->rvideo) o->rstyle |= RS_RVid; break;#ifndef NO_BRIGHTCOLOR case RS_Bold: color = GET_FGCOLOR (o->rstyle); if (color >= minBrightCOLOR && color <= maxBrightCOLOR) { rxvtlib_scr_color (o, color, RS_Bold); if ((o->rstyle & RS_fgMask) == (o->colorfgbg & RS_fgMask)) rxvtlib_scr_color (o, restoreFG, RS_Bold); } break; case RS_Blink: color = GET_BGCOLOR (o->rstyle); if (color >= minBrightCOLOR && color <= maxBrightCOLOR) { rxvtlib_scr_color (o, color, RS_Blink); if ((o->rstyle & RS_bgMask) == (o->colorfgbg & RS_bgMask)) rxvtlib_scr_color (o, restoreBG, RS_Blink); } break;#endif } }}/* ------------------------------------------------------------------------- *//* * Scroll text between <row1> and <row2> inclusive, by <count> lines * count positive ==> scroll up * count negative ==> scroll down * spec == 0 for normal routines *//* INTPROTO */int rxvtlib_scroll_text (rxvtlib *o, int row1, int row2, int count, int spec){ int i, j; o->want_refresh = 1; D_SCREEN ( (stderr, "scroll_text(%d,%d,%d,%d): %s", row1, row2, count, spec, (o->current_screen == PRIMARY) ? "Primary" : "Secondary")); if (count == 0 || (row1 > row2)) return 0; if ((count > 0) && (row1 == 0) && (o->current_screen == PRIMARY)) { o->TermWin.nscrolled += count; MIN_IT (o->TermWin.nscrolled, o->TermWin.saveLines); } else if (!spec) row1 += o->TermWin.saveLines; row2 += o->TermWin.saveLines; if (o->selection.op && o->current_screen == o->selection.screen) { i = o->selection.beg.row + o->TermWin.saveLines; j = o->selection.end.row + o->TermWin.saveLines; if ((i < row1 && j > row1) || (i < row2 && j > row2) || (i - count < row1 && i >= row1) || (i - count > row2 && i <= row2) || (j - count < row1 && j >= row1) || (j - count > row2 && j <= row2)) { CLEAR_ALL_SELECTION; o->selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ } else if (j >= row1 && j <= row2) { /* move selected region too */ o->selection.beg.row -= count; o->selection.end.row -= count; o->selection.mark.row -= count; } } CHECK_SELECTION (0); /* _after_ TermWin.nscrolled update */ if (count > 0) {/* A: scroll up */ MIN_IT (count, row2 - row1 + 1);/* A1: Copy lines that will get clobbered by the rotation */ for (i = 0, j = row1; i < count; i++, j++) { o->buf_text[i] = o->screen.text[j]; o->buf_tlen[i] = o->screen.tlen[j]; o->buf_rend[i] = o->screen.rend[j]; }/* A2: Rotate lines */ for (j = row1; (j + count) <= row2; j++) { o->screen.text[j] = o->screen.text[j + count]; o->screen.tlen[j] = o->screen.tlen[j + count]; o->screen.rend[j] = o->screen.rend[j + count]; }/* A3: Resurrect lines */ for (i = 0; i < count; i++, j++) { o->screen.text[j] = o->buf_text[i]; o->screen.tlen[j] = o->buf_tlen[i]; o->screen.rend[j] = o->buf_rend[i]; } } else if (count < 0) {/* B: scroll down */ count = min (-count, row2 - row1 + 1);/* B1: Copy lines that will get clobbered by the rotation */ for (i = 0, j = row2; i < count; i++, j--) { o->buf_text[i] = o->screen.text[j]; o->buf_tlen[i] = o->screen.tlen[j]; o->buf_rend[i] = o->screen.rend[j]; }/* B2: Rotate lines */ for (j = row2; (j - count) >= row1; j--) { o->screen.text[j] = o->screen.text[j - count]; o->screen.tlen[j] = o->screen.tlen[j - count]; o->screen.rend[j] = o->screen.rend[j - count]; }/* B3: Resurrect lines */ for (i = 0, j = row1; i < count; i++, j++) { o->screen.text[j] = o->buf_text[i]; o->screen.tlen[j] = o->buf_tlen[i]; o->screen.rend[j] = o->buf_rend[i]; } count = -count; } if (rxvtlib_Gr_Displayed (o)) rxvtlib_Gr_scroll (o, count); return count;}/* ------------------------------------------------------------------------- *//* * A safe scroll text routine *//* EXTPROTO */void rxvtlib_scr_scroll_text (rxvtlib *o, int count){ int row, erow; if (count == 0) return; count = rxvtlib_scroll_text (o, o->screen.tscroll, o->screen.bscroll, count, 0);/* XXX: Ummm, no? care needed with [bt]scroll, yes? */ if (count > 0) { row = o->TermWin.nrow - count + o->TermWin.saveLines; erow = o->TermWin.nrow + o->TermWin.saveLines; } else { row = o->TermWin.saveLines; erow = o->TermWin.saveLines - count; } for (; row < erow; row++) if (o->screen.text[row] == NULL) rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, row, o->rstyle);}/* ------------------------------------------------------------------------- *//* * Add text given in <str> of length <len> to screen struct *//* EXTPROTO */void rxvtlib_scr_add_lines (rxvtlib *o, const unsigned char *str, int nlines, int len){ char c; int i, j, row, last_col, checksel, clearsel; text_t *stp; rend_t *srp; if (len <= 0) /* sanity */ return; o->want_refresh = 1; last_col = o->TermWin.ncol; D_SCREEN ((stderr, "scr_add_lines(*,%d,%d)", nlines, len)); ZERO_SCROLLBACK; if (nlines > 0) { nlines += (o->screen.cur.row - o->screen.bscroll); if ((nlines > 0) && (o->screen.tscroll == 0) && (o->screen.bscroll == (o->TermWin.nrow - 1))) { /* _at least_ this many lines need to be scrolled */ rxvtlib_scroll_text (o, o->screen.tscroll, o->screen.bscroll, nlines, 0); for (i = nlines, j = o->screen.bscroll + o->TermWin.saveLines; i--; j--) { rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, j, o->rstyle); o->screen.tlen[j] = 0; } o->screen.cur.row -= nlines; } }#ifdef DEBUG_STRICT assert (o->screen.cur.col < last_col); assert (o->screen.cur.row < o->TermWin.nrow); assert (o->screen.cur.row >= -o->TermWin.nscrolled);#else /* drive with your eyes closed */ MIN_IT (o->screen.cur.col, last_col - 1); MIN_IT (o->screen.cur.row, o->TermWin.nrow - 1); MAX_IT (o->screen.cur.row, -o->TermWin.nscrolled);#endif row = o->screen.cur.row + o->TermWin.saveLines; checksel = (o->selection.op && o->current_screen == o->selection.screen) ? 1 : 0; clearsel = 0; stp = o->screen.text[row]; srp = o->screen.rend[row];#ifdef MULTICHAR_SET if (o->lost_multi && o->screen.cur.col > 0 && ((srp[o->screen.cur.col - 1] & RS_multiMask) == RS_multi1) && *str != '\n' && *str != '\r' && *str != '\t') o->chstat = WBYTE;#endif for (i = 0; i < len;) { c = str[i++]; switch (c) { case '\t': rxvtlib_scr_tab (o, 1); continue; case '\n': if (o->screen.tlen[row] != -1) /* XXX: think about this */ MAX_IT (o->screen.tlen[row], o->screen.cur.col); o->screen.flags &= ~Screen_WrapNext; if (o->screen.cur.row == o->screen.bscroll) { rxvtlib_scroll_text (o, o->screen.tscroll, o->screen.bscroll, 1, 0); j = o->screen.bscroll + o->TermWin.saveLines; rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, j, o->rstyle); o->screen.tlen[j] = 0; } else if (o->screen.cur.row < (o->TermWin.nrow - 1)) row = (++o->screen.cur.row) + o->TermWin.saveLines; stp = o->screen.text[row]; /* _must_ refresh */ srp = o->screen.rend[row]; /* _must_ refresh */ RESET_CHSTAT; continue; case '\r': if (o->screen.tlen[row] != -1) /* XXX: think about this */ MAX_IT (o->screen.tlen[row], o->screen.cur.col); o->screen.flags &= ~Screen_WrapNext; o->screen.cur.col = 0; RESET_CHSTAT; continue; default:#ifdef MULTICHAR_SET o->rstyle &= ~RS_multiMask; if (o->chstat == WBYTE) { o->rstyle |= RS_multi2; /* multibyte 2nd byte */ o->chstat = SBYTE; if ((o->encoding_method == EUCJ) || (o->encoding_method == GB)) c |= 0x80; /* maybe overkill, but makes it selectable */ } else if (o->chstat == SBYTE) { if (o->multi_byte || (c & 0x80)) { /* multibyte 1st byte */ o->rstyle |= RS_multi1; o->chstat = WBYTE; if ((o->encoding_method == EUCJ) || (o->encoding_method == GB)) c |= 0x80; /* maybe overkill, but makes selectable */ } } else#endif if (c == 127) continue; /* yummmm..... */ break; } if (checksel && !ROWCOL_IS_BEFORE (o->screen.cur, o->selection.beg) && ROWCOL_IS_BEFORE (o->screen.cur, o->selection.end)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?