rxvtlib_screen.c
来自「具有IDE功能的编辑器」· C语言 代码 · 共 2,128 行 · 第 1/5 页
C
2,128 行
checksel = 0; clearsel = 1; } if (o->screen.flags & Screen_WrapNext) { o->screen.tlen[row] = -1; 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 */ o->screen.cur.col = 0; o->screen.flags &= ~Screen_WrapNext; } if (o->screen.flags & Screen_Insert) rxvtlib_scr_insdel_chars (o, 1, INSERT);#ifdef MULTICHAR_SET if ((o->rstyle & RS_multiMask) == RS_multi1 && o->screen.cur.col > 0 && (srp[o->screen.cur.col - 1] & RS_multiMask) == RS_multi1) { stp[o->screen.cur.col - 1] = ' '; srp[o->screen.cur.col - 1] &= ~RS_multiMask; } else if ((o->rstyle & RS_multiMask) == RS_multi2 && o->screen.cur.col < (last_col - 1) && (srp[o->screen.cur.col + 1] & RS_multiMask) == RS_multi2) { stp[o->screen.cur.col + 1] = ' '; srp[o->screen.cur.col + 1] &= ~RS_multiMask; }#endif stp[o->screen.cur.col] = c; srp[o->screen.cur.col] = o->rstyle; if (o->screen.cur.col < (last_col - 1)) o->screen.cur.col++; else { o->screen.tlen[row] = last_col; if (o->screen.flags & Screen_Autowrap) o->screen.flags |= Screen_WrapNext; else o->screen.flags &= ~Screen_WrapNext; } } if (o->screen.tlen[row] != -1) /* XXX: think about this */ MAX_IT (o->screen.tlen[row], o->screen.cur.col);/* * If we wrote anywhere in the selected area, kill the selection * XXX: should we kill the mark too? Possibly, but maybe that * should be a similar check. */ if (clearsel) CLEAR_SELECTION;#ifdef DEBUG_STRICT assert (o->screen.cur.row >= 0);#else /* drive with your eyes closed */ MAX_IT (o->screen.cur.row, 0);#endif}/* ------------------------------------------------------------------------- *//* * Process Backspace. Move back the cursor back a position, wrap if have to * XTERM_SEQ: CTRL-H *//* EXTPROTO */void rxvtlib_scr_backspace (rxvtlib *o){ RESET_CHSTAT; o->want_refresh = 1; if (o->screen.cur.col == 0) { if (o->screen.cur.row > 0) {#ifdef SUPPORT_BROKEN_APPS_WHICH_RELY_ON_UNDEFINED_BW_BEHAVIOUR_AS_XTERM o->screen.flags &= ~Screen_WrapNext;#else o->screen.cur.col = o->TermWin.ncol - 1; o->screen.cur.row--;#endif } else o->screen.flags &= ~Screen_WrapNext; } else if (o->screen.flags & Screen_WrapNext) { o->screen.flags &= ~Screen_WrapNext; } else rxvtlib_scr_gotorc (o, 0, -1, RELATIVE);}/* ------------------------------------------------------------------------- *//* * Process Horizontal Tab * count: +ve = forward; -ve = backwards * XTERM_SEQ: CTRL-I *//* EXTPROTO */void rxvtlib_scr_tab (rxvtlib *o, int count){ int i, x; o->want_refresh = 1; RESET_CHSTAT; x = o->screen.cur.col; if (count == 0) return; else if (count > 0) { for (i = x + 1; i < o->TermWin.ncol; i++) { if (o->tabs[i]) { x = i; if (!--count) break; } } if (count) x = o->TermWin.ncol - 1; } else if (count < 0) { for (i = x - 1; i >= 0; i--) { if (o->tabs[i]) { x = i; if (!++count) break; } } if (count) x = 0; } if (x != o->screen.cur.col) rxvtlib_scr_gotorc (o, 0, x, R_RELATIVE);}/* ------------------------------------------------------------------------- *//* * Process DEC Back Index * XTERM_SEQ: ESC 6 * Move cursor left in row. If we're at the left boundary, shift everything * in that row right. Clear left column. */#ifndef NO_FRILLS/* EXTPROTO */void rxvtlib_scr_backindex (rxvtlib *o){ int i, row; text_t *t0; rend_t *r0; o->want_refresh = 1; if (o->screen.cur.col > 0) rxvtlib_scr_gotorc (o, 0, o->screen.cur.col - 1, R_RELATIVE); else { row = o->screen.cur.row + o->TermWin.saveLines; if (o->screen.tlen[row] == 0) return; /* um, yeah? */ else if (o->screen.tlen[row] < o->TermWin.ncol - 1) o->screen.tlen[row]++; t0 = o->screen.text[row]; r0 = o->screen.rend[row]; for (i = o->TermWin.ncol; i-- > 1;) { t0[i] = t0[i - 1]; r0[i] = r0[i - 1]; } t0[0] = ' '; r0[0] = DEFAULT_RSTYLE;/* TODO: Multi check on last character */ }}#endif/* ------------------------------------------------------------------------- *//* * Process DEC Forward Index * XTERM_SEQ: ESC 9 * Move cursor right in row. If we're at the right boundary, shift everything * in that row left. Clear right column. */#ifndef NO_FRILLS/* EXTPROTO */void rxvtlib_scr_forwardindex (rxvtlib *o){ int i, row; text_t *t0; rend_t *r0; o->want_refresh = 1; if (o->screen.cur.col < o->TermWin.ncol - 1) rxvtlib_scr_gotorc (o, 0, o->screen.cur.col + 1, R_RELATIVE); else { row = o->screen.cur.row + o->TermWin.saveLines; if (o->screen.tlen[row] == 0) return; /* um, yeah? */ else if (o->screen.tlen[row] > 0) o->screen.tlen[row]--; else o->screen.tlen[row] = o->TermWin.ncol - 1; t0 = o->screen.text[row]; r0 = o->screen.rend[row]; for (i = 0; i < o->TermWin.ncol - 2; i++) { t0[i] = t0[i + 1]; r0[i] = r0[i + 1]; } t0[i] = ' '; r0[i] = DEFAULT_RSTYLE;/* TODO: Multi check on first character */ }}#endif/* ------------------------------------------------------------------------- *//* * Goto Row/Column *//* EXTPROTO */void rxvtlib_scr_gotorc (rxvtlib *o, int row, int col, int relative){ o->want_refresh = 1; ZERO_SCROLLBACK; RESET_CHSTAT; if (rxvtlib_Gr_Displayed (o)) rxvtlib_Gr_scroll (o, 0); D_SCREEN ( (stderr, "scr_gotorc(r:%d,c:%d,%d): from (r:%d,c:%d)", row, col, relative, o->screen.cur.row, o->screen.cur.col)); o->screen.cur.col = ((relative & C_RELATIVE) ? (o->screen.cur.col + col) : col); MAX_IT (o->screen.cur.col, 0); MIN_IT (o->screen.cur.col, o->TermWin.ncol - 1); if (o->screen.flags & Screen_WrapNext) o->screen.flags &= ~Screen_WrapNext; if (relative & R_RELATIVE) { if (row > 0) { if (o->screen.cur.row <= o->screen.bscroll && (o->screen.cur.row + row) > o->screen.bscroll) o->screen.cur.row = o->screen.bscroll; else o->screen.cur.row += row; } else if (row < 0) { if (o->screen.cur.row >= o->screen.tscroll && (o->screen.cur.row + row) < o->screen.tscroll) o->screen.cur.row = o->screen.tscroll; else o->screen.cur.row += row; } } else { if (o->screen.flags & Screen_Relative) { /* relative origin mode */ o->screen.cur.row = row + o->screen.tscroll; MIN_IT (o->screen.cur.row, o->screen.bscroll); } else o->screen.cur.row = row; } MAX_IT (o->screen.cur.row, 0); MIN_IT (o->screen.cur.row, o->TermWin.nrow - 1);}/* ------------------------------------------------------------------------- *//* * direction should be UP or DN *//* EXTPROTO */void rxvtlib_scr_index (rxvtlib *o, int direction){ int dirn; o->want_refresh = 1; dirn = ((direction == UP) ? 1 : -1); D_SCREEN ((stderr, "scr_index(%d)", dirn)); ZERO_SCROLLBACK; RESET_CHSTAT; if (rxvtlib_Gr_Displayed (o)) rxvtlib_Gr_scroll (o, 0); if (o->screen.flags & Screen_WrapNext) { o->screen.flags &= ~Screen_WrapNext; } if ((o->screen.cur.row == o->screen.bscroll && direction == UP) || (o->screen.cur.row == o->screen.tscroll && direction == DN)) { rxvtlib_scroll_text (o, o->screen.tscroll, o->screen.bscroll, dirn, 0); if (direction == UP) dirn = o->screen.bscroll + o->TermWin.saveLines; else dirn = o->screen.tscroll + o->TermWin.saveLines; rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, dirn, o->rstyle); o->screen.tlen[dirn] = 0; } else o->screen.cur.row += dirn; MAX_IT (o->screen.cur.row, 0); MIN_IT (o->screen.cur.row, o->TermWin.nrow - 1); CHECK_SELECTION (0);}/* ------------------------------------------------------------------------- *//* * Erase part or whole of a line * XTERM_SEQ: Clear line to right: ESC [ 0 K * XTERM_SEQ: Clear line to left : ESC [ 1 K * XTERM_SEQ: Clear whole line : ESC [ 2 K *//* EXTPROTO */void rxvtlib_scr_erase_line (rxvtlib *o, int mode){ int row, col, num; o->want_refresh = 1; D_SCREEN ( (stderr, "scr_erase_line(%d) at screen row: %d", mode, o->screen.cur.row)); ZERO_SCROLLBACK; RESET_CHSTAT; if (rxvtlib_Gr_Displayed (o)) rxvtlib_Gr_scroll (o, 0); CHECK_SELECTION (1); if (o->screen.flags & Screen_WrapNext) o->screen.flags &= ~Screen_WrapNext; row = o->TermWin.saveLines + o->screen.cur.row; switch (mode) { case 0: /* erase to end of line */ col = o->screen.cur.col; num = o->TermWin.ncol - col; MIN_IT (o->screen.tlen[row], col); if (ROWCOL_IN_ROW_AT_OR_AFTER (o->selection.beg, o->screen.cur) || ROWCOL_IN_ROW_AT_OR_AFTER (o->selection.end, o->screen.cur)) CLEAR_SELECTION; break; case 1: /* erase to beginning of line */ col = 0; num = o->screen.cur.col + 1; if (ROWCOL_IN_ROW_AT_OR_BEFORE (o->selection.beg, o->screen.cur) || ROWCOL_IN_ROW_AT_OR_BEFORE (o->selection.end, o->screen.cur)) CLEAR_SELECTION; break; case 2: /* erase whole line */ col = 0; num = o->TermWin.ncol; o->screen.tlen[row] = 0; if (o->selection.beg.row <= o->screen.cur.row && o->selection.end.row >= o->screen.cur.row) CLEAR_SELECTION; break; default: return; } if (o->screen.text[row]) blank_line (&(o->screen.text[row][col]), &(o->screen.rend[row][col]), num, o->rstyle & ~RS_Uline); else rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, row, o->rstyle & ~RS_Uline);}/* ------------------------------------------------------------------------- *//* * Erase part of whole of the screen * XTERM_SEQ: Clear screen after cursor : ESC [ 0 J * XTERM_SEQ: Clear screen before cursor: ESC [ 1 J * XTERM_SEQ: Clear whole screen : ESC [ 2 J *//* EXTPROTO */void rxvtlib_scr_erase_screen (rxvtlib *o, int mode){ int row, num, row_offset; rend_t ren; long gcmask; XGCValues gcvalue; o->want_refresh = 1; D_SCREEN ( (stderr, "scr_erase_screen(%d) at screen row: %d", mode, o->screen.cur.row)); ZERO_SCROLLBACK; RESET_CHSTAT; row_offset = o->TermWin.saveLines; switch (mode) { case 0: /* erase to end of screen */ CHECK_SELECTION (1); rxvtlib_scr_erase_line (o, 0); row = o->screen.cur.row + 1; /* possible OOB */ num = o->TermWin.nrow - row; break; case 1: /* erase to beginning of screen */ CHECK_SELECTION (3); rxvtlib_scr_erase_line (o, 1); row = 0; /* possible OOB */ num = o->screen.cur.row; break; case 2: /* erase whole screen */ CHECK_SELECTION (3); rxvtlib_Gr_ClearScreen (o); row = 0; num = o->TermWin.nrow; break; default: return; } if (o->selection.op && o->current_screen == o->selection.screen && ((o->selection.beg.row >= row && o->selection.beg.row <= row + num) || (o->selection.end.row >= row && o->selection.end.row <= row + num))) CLEAR_SELECTION; if (row >= 0 && row < o->TermWin.nrow) { /* check OOB */ MIN_IT (num, (o->TermWin.nrow - row)); if (o->rstyle & (RS_RVid | RS_Uline)) ren = (rend_t) ~ RS_None; else if (GET_BGCOLOR (o->rstyle) == Color_bg) { ren = DEFAULT_RSTYLE; CLEAR_ROWS (row, num); } else { ren = (o->rstyle & (RS_fgMask | RS_bgMask)); gcvalue.foreground = o->PixColors[GET_BGCOLOR (ren)]; gcmask = GCForeground; XChangeGC (o->Xdisplay, o->TermWin.gc, gcmask, &gcvalue); ERASE_ROWS (row, num); gcvalue.foreground = o->PixColors[Color_fg]; XChangeGC (o->Xdisplay, o->TermWin.gc, gcmask, &gcvalue); } for (; num--; row++) { rxvtlib_blank_screen_mem (o, o->screen.text, o->screen.rend, row + row_offset, o->rstyle & ~RS_Uline); o->screen.tlen[row + row_offset] = 0; blank_line (o->drawn_text[row], o->drawn_rend[row], o->TermWin.ncol, ren); } }}/* ------------------------------------------------------------------------- *//* * Fill the screen with `E's * XTERM_SEQ: Screen Alignment Test: ESC # 8 */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?