📄 screen.c
字号:
if (row < screen->startHRow || row > screen->endHRow || (row == screen->startHRow && maxcol < screen->startHCol) || (row == screen->endHRow && col >= screen->endHCol)) { /* row does not intersect selection; don't hilite */ if (!force) { while (col <= maxcol && (attrs[col] & ~SHOWBOLD) == 0 && (chars[col] & ~040) == 0) col++; while (col <= maxcol && (attrs[maxcol] & ~SHOWBOLD) == 0 && (chars[maxcol] & ~040) == 0) maxcol--; } hilite = False; } else { /* row intersects selection; split into pieces of single type */ if (row == screen->startHRow && col < screen->startHCol) { ScrnRefresh(screen, row, col, 1, screen->startHCol - col, force); col = screen->startHCol; } if (row == screen->endHRow && maxcol >= screen->endHCol) { ScrnRefresh(screen, row, screen->endHCol, 1, maxcol - screen->endHCol + 1, force); maxcol = screen->endHCol - 1; } /* remaining piece should be hilited */ hilite = True; } if (col > maxcol) continue; flags = attrs[col]; fg = fgs[col]; bg = bgs[col]; fg_pix = (flags & FG_COLOR) ? screen->colors[fg] : screen->foreground; bg_pix = (flags & BG_COLOR) ? screen->colors[bg] : term->core.background_pixel; if ( (!hilite && (flags & INVERSE) != 0) || (hilite && (flags & INVERSE) == 0) ) { if (flags & SHOWBOLD) gc = screen->reverseboldGC; else gc = screen->reverseGC; XSetForeground(screen->display, gc, bg_pix); XSetBackground(screen->display, gc, fg_pix); } else { if (flags & SHOWBOLD) gc = screen->normalboldGC; else gc = screen->normalGC; XSetForeground(screen->display, gc, fg_pix); XSetBackground(screen->display, gc, bg_pix); } x = CursorX(screen, col); lastind = col; for (; col <= maxcol; col++) { if (attrs[col] != flags || (flags & FG_COLOR && fgs[col] != fg) || (flags & BG_COLOR && bgs[col] != bg)) { XDrawImageString(screen->display, TextWindow(screen), gc, x, y, (char *) &chars[lastind], n = col - lastind); if((flags & SHOWBOLD) && screen->enbolden) XDrawString(screen->display, TextWindow(screen), gc, x + 1, y, (char *) &chars[lastind], n); if(flags & UNDERLINE) XDrawLine(screen->display, TextWindow(screen), gc, x, y+1, x+n*FontWidth(screen), y+1); x += (col - lastind) * FontWidth(screen); lastind = col; flags = attrs[col]; fg = fgs[col]; bg = bgs[col]; fg_pix = (flags & FG_COLOR) ? screen->colors[fg] : screen->foreground; bg_pix = (flags & BG_COLOR) ? screen->colors[bg] : term->core.background_pixel; if ((!hilite && (flags & INVERSE) != 0) || (hilite && (flags & INVERSE) == 0) ) { if (flags & SHOWBOLD) gc = screen->reverseboldGC; else gc = screen->reverseGC; XSetForeground(screen->display, gc, bg_pix); XSetBackground(screen->display, gc, fg_pix); } else { if (flags & SHOWBOLD) gc = screen->normalboldGC; else gc = screen->normalGC; XSetForeground(screen->display, gc, fg_pix); XSetBackground(screen->display, gc, bg_pix); } } if(chars[col] == 0) chars[col] = ' '; } if ( (!hilite && (flags & INVERSE) != 0) || (hilite && (flags & INVERSE) == 0) ) { if (flags & SHOWBOLD) gc = screen->reverseboldGC; else gc = screen->reverseGC; XSetForeground(screen->display, gc, bg_pix); XSetBackground(screen->display, gc, fg_pix); } else { if (flags & SHOWBOLD) gc = screen->normalboldGC; else gc = screen->normalGC; XSetForeground(screen->display, gc, fg_pix); XSetBackground(screen->display, gc, bg_pix); } XDrawImageString(screen->display, TextWindow(screen), gc, x, y, (char *) &chars[lastind], n = col - lastind); if((flags & SHOWBOLD) && screen->enbolden) XDrawString(screen->display, TextWindow(screen), gc, x + 1, y, (char *) &chars[lastind], n); if(flags & UNDERLINE) XDrawLine(screen->display, TextWindow(screen), gc, x, y+1, x + n * FontWidth(screen), y+1); }}ClearBufRows (screen, first, last)/* Sets the rows first though last of the buffer of screen to spaces. Requires first <= last; first, last are rows of screen->buf. */register TScreen *screen;register int first, last;{ first *= 4; last = 4 * last + 1; while (first <= last) bzero (screen->buf [first++], (screen->max_col + 1));}/* Resizes screen: 1. If new window would have fractional characters, sets window size so as to discard fractional characters and returns -1. Minimum screen size is 1 X 1. Note that this causes another ExposeWindow event. 2. Enlarges screen->buf if necessary. New space is appended to the bottom and to the right 3. Reduces screen->buf if necessary. Old space is removed from the bottom and from the right 4. Cursor is positioned as closely to its former position as possible 5. Sets screen->max_row and screen->max_col to reflect new size 6. Maintains the inner border (and clears the border on the screen). 7. Clears origin mode and sets scrolling region to be entire screen. 8. Returns 0 */ScreenResize (screen, width, height, flags) register TScreen *screen; int width, height; unsigned *flags;{ int rows, cols; int border = 2 * screen->border; int move_down_by;#ifdef sun#ifdef TIOCSSIZE struct ttysize ts;#endif /* TIOCSSIZE */#else /* sun */#ifdef TIOCSWINSZ struct winsize ws;#endif /* TIOCSWINSZ */#endif /* sun */ Window tw = TextWindow (screen); /* clear the right and bottom internal border because of NorthWest gravity might have left junk on the right and bottom edges */ XClearArea (screen->display, tw, width - screen->border, 0, /* right edge */ screen->border, height, /* from top to bottom */ False); XClearArea (screen->display, tw, 0, height - screen->border, /* bottom */ width, screen->border, /* all across the bottom */ False); /* round so that it is unlikely the screen will change size on */ /* small mouse movements. */ rows = (height + FontHeight(screen) / 2 - border) / FontHeight(screen); cols = (width + FontWidth(screen) / 2 - border - screen->scrollbar) / FontWidth(screen); if (rows < 1) rows = 1; if (cols < 1) cols = 1; /* update buffers if the screen has changed size */ if (screen->max_row != rows - 1 || screen->max_col != cols - 1) { register int savelines = screen->scrollWidget ? screen->savelines : 0; int delta_rows = rows - (screen->max_row + 1); if(screen->cursor_state) HideCursor(); if ( screen->alternate && term->misc.resizeGravity == SouthWestGravity ) /* swap buffer pointers back to make all this hair work */ SwitchBufPtrs(screen); if (screen->altbuf) (void) Reallocate(&screen->altbuf, (Char **)&screen->abuf_address, rows, cols, screen->max_row + 1, screen->max_col + 1); move_down_by = Reallocate(&screen->allbuf, (Char **)&screen->sbuf_address, rows + savelines, cols, screen->max_row + 1 + savelines, screen->max_col + 1); screen->buf = &screen->allbuf[4 * savelines]; screen->max_row += delta_rows; screen->max_col = cols - 1; if (term->misc.resizeGravity == SouthWestGravity) { screen->savedlines -= move_down_by; if (screen->savedlines < 0) screen->savedlines = 0; if (screen->savedlines > screen->savelines) screen->savedlines = screen->savelines; if (screen->topline < -screen->savedlines) screen->topline = -screen->savedlines; screen->cur_row += move_down_by; screen->cursor_row += move_down_by; ScrollSelection(screen, move_down_by); if (screen->alternate) SwitchBufPtrs(screen); /* put the pointers back */ } /* adjust scrolling region */ screen->top_marg = 0; screen->bot_marg = screen->max_row; *flags &= ~ORIGIN; if (screen->cur_row > screen->max_row) screen->cur_row = screen->max_row; if (screen->cur_col > screen->max_col) screen->cur_col = screen->max_col; screen->fullVwin.height = height - border; screen->fullVwin.width = width - border - screen->scrollbar; } else if(FullHeight(screen) == height && FullWidth(screen) == width) return(0); /* nothing has changed at all */ if(screen->scrollWidget) ResizeScrollBar(screen->scrollWidget, -1, -1, height); screen->fullVwin.fullheight = height; screen->fullVwin.fullwidth = width; ResizeSelection (screen, rows, cols);#ifdef sun#ifdef TIOCSSIZE /* Set tty's idea of window size */ ts.ts_lines = rows; ts.ts_cols = cols; ioctl (screen->respond, TIOCSSIZE, &ts);#ifdef SIGWINCH if(screen->pid > 1) { int pgrp; if (ioctl (screen->respond, TIOCGPGRP, &pgrp) != -1) kill_process_group(pgrp, SIGWINCH); }#endif /* SIGWINCH */#endif /* TIOCSSIZE */#else /* sun */#ifdef TIOCSWINSZ /* Set tty's idea of window size */ ws.ws_row = rows; ws.ws_col = cols; ws.ws_xpixel = width; ws.ws_ypixel = height; ioctl (screen->respond, TIOCSWINSZ, (char *)&ws);#ifdef notdef /* change to SIGWINCH if this doesn't work for you */ if(screen->pid > 1) { int pgrp; if (ioctl (screen->respond, TIOCGPGRP, &pgrp) != -1) kill_process_group(pgrp, SIGWINCH); }#endif /* SIGWINCH */#endif /* TIOCSWINSZ */#endif /* sun */ return (0);}/* * Sets the attributes from the row, col, to row, col + length according to * mask and value. The bits in the attribute byte specified by the mask are * set to the corresponding bits in the value byte. If length would carry us * over the end of the line, it stops at the end of the line. */voidScrnSetAttributes(screen, row, col, mask, value, length)TScreen *screen;int row, col;unsigned mask, value;register int length; /* length of string */{ register Char *attrs; register int avail = screen->max_col - col + 1; if (length > avail) length = avail; if (length <= 0) return; attrs = screen->buf[4 * row + 1] + col; value &= mask; /* make sure we only change the bits allowed by mask*/ while(length-- > 0) { *attrs &= ~mask; /* clear the bits */ *attrs |= value; /* copy in the new values */ attrs++; }}/* * Gets the attributes from the row, col, to row, col + length into the * supplied array, which is assumed to be big enough. If length would carry us * over the end of the line, it stops at the end of the line. Returns * the number of bytes of attributes (<= length) */intScrnGetAttributes(screen, row, col, str, length)TScreen *screen;int row, col;Char *str;register int length; /* length of string */{ register Char *attrs; register int avail = screen->max_col - col + 1; int ret; if (length > avail) length = avail; if (length <= 0) return 0; ret = length; attrs = screen->buf[4 * row + 1] + col; while(length-- > 0) { *str++ = *attrs++; } return ret;}Boolnon_blank_line(sb, row, col, len)ScrnBuf sb;register int row, col, len;{ register int i; register Char *ptr = sb [4 * row]; for (i = col; i < len; i++) { if (ptr[i]) return True; } return False;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -