📄 trm.c
字号:
* probably use _pos() to do the * moving around. */ if (cursor_left && (enter_insert_mode || insert_character)) { register int leftc, left_attrs, curr_attrs; /* Make sure that we can move */ if (SP->phys_irm == 1 && !move_insert_mode) { _insmode(0); _setmode(); } curr_attrs = SP->phys_gr; /* Find the character to the left of us. */ /* If we just wrote out the character, use that. */ if (beginning < (start-1)) { leftc = *(start - 2); left_attrs = curr_attrs; /* Otherwise, use the one passed in. */ } else { left_attrs = leftch & A_ATTRIBUTES; leftc = leftch & A_CHARTEXT; } if (leftc == '~' && tilde_glitch) leftc = '`'; /* rewrite the current char in the 79th column */ if ((leftc != c) || (left_attrs != curr_attrs)) { if (curr_attrs && !move_standout_mode) { _hlmode(0); _sethl(); } tputs(cursor_left, 1, _outch); /* Place us back in the proper hilite. */ if (SP->phys_gr != curr_attrs) { _hlmode(curr_attrs); _sethl(); } _outch((chtype) c); } /* Move again to column 79. */ if (curr_attrs && !move_standout_mode) { _hlmode(0); _sethl(); } tputs(cursor_left, 1, _outch); SP->phys_x--; /* Restore the highlighting. */ if (left_attrs != SP->phys_gr) { _hlmode(left_attrs); _sethl(); } /* Restore the 79th character. */ if (enter_insert_mode) { if (SP->phys_irm == 0) { tputs(enter_insert_mode, 1, _outch); _outch((chtype) leftc); if (insert_padding) tputs(insert_padding, 1, _outch); tputs(exit_insert_mode, 1, _outch); } else { _outch((chtype) leftc); if (insert_padding) tputs(insert_padding, 1, _outch); } } else { tputs(insert_character, 1, _outch); _outch((chtype) leftc); } } else { /* could not output char */ didntdobotright = 1; SP->phys_x--; break; } } else { /* not on bottom right corner */ SP->phys_x = 0; SP->phys_y++; _outch((chtype) c); } } else { /* No auto right margin */ _outch((chtype) c); SP->phys_x = columns-1; } } else /* not on right margin */ _outch((chtype) c); /* Only 1 line can be affected by insert char here */ if(SP->phys_irm == 1 && insert_padding) tputs(insert_padding, 1, _outch); } if (eat_newline_glitch && SP->phys_x == 0) { /* * This handles both C100 and VT100, which are * different. We do not output carriage_return * and cursor_down because it might confuse a * terminal that is looking for return and linefeed. */ _outch('\r'); _outch('\n'); } /* restore the scrolling region */ if (savebm != SP->phys_bot_mgn) { _window(savetm, savebm, 0, columns-1); _setwind(); } if (clrhlflag) { /* Auto margin counts as motion on an HP */ _hlmode(0); _sethl(); }}/* * Output n blanks, or the equivalent. This is done to erase text, and * also to insert blanks. The semantics of this call do not define where * it leaves the cursor - it might be where it was before, or it might * be at the end of the blanks. We will, of course, leave SP->phys_x * properly updated. */_blanks (n){#ifdef DEBUG if(outf) fprintf(outf, "_blanks(%d).\n", n);#endif if (n == 0) return; _setmode (); _sethl (); if (SP->virt_irm==1 && parm_ich) { if (n == 1 && insert_character) tputs(insert_character, 1, _outch); else if (parm_ich) tputs(tparm(parm_ich, n), n, _outch); return; } if (erase_chars && SP->phys_irm != 1 && n > 5) { tputs(tparm(erase_chars, n), n, _outch); return; } if (repeat_char && SP->phys_irm != 1 && n > 5) { tputs(tparm(repeat_char, ' ', n), n, _outch); SP->phys_x += n; return; } while (--n >= 0) { if (SP->phys_irm == 1 && insert_character) tputs (insert_character, columns - SP->phys_x, _outch); if (++SP->phys_x >= columns && auto_right_margin) { if (SP->phys_y >= lines-1) { /* * We attempted to put something in the last * position of the last line. Since this will * cause a scroll (we only get here if the * terminal has auto_right_margin) we refuse * to put it out. */ SP->phys_x--; return; } SP->phys_x = 0; SP->phys_y++; } _outch (' '); if (SP->phys_irm == 1 && insert_padding) tputs (insert_padding, 1, _outch); }}_clrline(ln, p, olen)int ln;register chtype *p;register int olen;{ register int firstnonblank;#ifdef DEBUG if (outf) fprintf(outf, "_clrline(ln=%d,p=%x,olen=%d).\n", ln, p, olen);#endif /* DEBUG */ for (firstnonblank = 0; firstnonblank < olen; firstnonblank++, p++) if (*p != ' ') break; if ((magic_cookie_glitch >= 0) && (firstnonblank > 0) && (*p&A_ATTRIBUTES)) firstnonblank -= magic_cookie_glitch; /* Avoid an extra _pos if possible. */ /* Warning: This makes assumptions about how _clreol() */ /* works. If that changes, this may have to change also. */ if (!clr_eol && delete_line && insert_line) _pos(ln, 0); else _pos(ln, firstnonblank); _clreol();}/* * Perform clear to beginning of line. This routine is used * within insdelchar.c. Return where the first nonblank charcter is. * Note that (firstnonblank > firstdiff) for this to be useful. */int_clrbol(firstnonblank, firstdiff, ln, ob)int firstnonblank, firstdiff, ln;chtype *ob;{ register int cost_blanks, cost_clrbol, cost_ichdch, cost_erase;#ifdef DEBUG if (outf) fprintf(outf, "_clrbol(firstnonblank=%d,firstdiff=%d,ln=%d,ob=%x). ", firstnonblank, firstdiff, ln, ob);#endif /* DEBUG */ if ((magic_cookie_glitch > 0) && (ob[firstnonblank]&A_ATTRIBUTES)) firstnonblank -= magic_cookie_glitch; /* cost to overwrite with blanks */ cost_blanks = firstnonblank - firstdiff; if (cost_blanks <= 4) { /* arbitrary cutoff to save CPU */#ifdef DEBUG if (outf) fprintf(outf, "too close to bother, returning firstdiff.\n");#endif /* DEBUG */ return firstdiff; } /* cost of clr_bol + cost to write blank */ if (clr_bol && cursor_right) cost_clrbol = _cost(Clr_bol) + (SP->phys_irm || SP->phys_gr) ? _cost(Cursor_right) : 1; else cost_clrbol = INFINITY; /* cost to delete n chars, then insert n blanks */ if (parm_dch && parm_ich) cost_ichdch = _cost(dcfixed) + _cost(dcvar) * cost_blanks + _cost(icfixed) + (_cost(icvar) * cost_blanks); else cost_ichdch = INFINITY; /* cost to erase chars */ if (erase_chars) cost_erase = _cost(Erase_chars); else cost_erase = INFINITY; if (cost_clrbol < cost_blanks && cost_clrbol < cost_ichdch && cost_clrbol < cost_erase) {#ifdef DEBUG if (outf) fprintf(outf, "use clr_bol, return firstnonblank.\n");#endif /* DEBUG */ _pos(ln, firstnonblank-1); /* * There are two types of clr_bol: inclusive and * exclusive. We assume that it is inclusive, which * is the ANSI standard. * If it were inclusive, then the blank will be * blanked twice. */ tputs(clr_bol, 1, _outch); if (SP->phys_irm || SP->phys_gr) tputs(cursor_right, 1, _outch); else _outch(' '); SP->phys_x++; return firstnonblank; } else if (cost_ichdch < cost_blanks && cost_ichdch < cost_erase) {#ifdef DEBUG if (outf) fprintf(outf, "use i/d, return firstnonblank.\n");#endif /* DEBUG */ _pos(ln, firstdiff); _delchars(cost_blanks); _insmode(1); _blanks(cost_blanks); _insmode(0); _setmode(); return firstnonblank; } else if (cost_erase < cost_blanks) {#ifdef DEBUG if (outf) fprintf (outf, "using erase_chars, return firstnonblank.\n");#endif /* DEBUG */ _pos(ln, firstdiff); tputs(tparm(erase_chars, firstnonblank - firstdiff), 1, _outch); return firstnonblank; }#ifdef DEBUG if (outf) fprintf(outf, "not cost effective, returning firstdiff.\n");#endif /* DEBUG */ return firstdiff;}_clreol(){ register int col; register struct line *cb;#ifdef DEBUG if(outf) fprintf(outf, "_clreol().\n");#endif if (!move_standout_mode) _clearhl (); if (clr_eol) { tputs (clr_eol, columns-SP->phys_x, _outch); } else if (delete_line && insert_line && SP->phys_x == 0) { _dellines (1); _inslines (1); } else { /* * Should consider using delete/insert line here, too, * if the part that would have to be redrawn is short, * or if we have to get rid of some cemented highlights. * This might win on the DTC 382 or the Teleray 1061. */ cb = SP->cur_body[SP->phys_y+1]; for (col=SP->phys_x; col<cb->length; col++) if (cb->body[col] != ' ') { _pos(SP->phys_y, col); _blanks(1); } /* * Could save and restore SP->curptr position, but since we * keep track of what _blanks does to it, it turns out * that this is wasted. Not backspacing over the stuff * cleared out is a real win on a super dumb terminal. */ }}/* * Insert n blank characters. */_inschars(n){#ifdef DEBUG if(outf) fprintf(outf, "_inschars(%d).\n", n);#endif if (enter_insert_mode && SP->phys_irm == 0) { tputs(enter_insert_mode, 1, _outch); SP->phys_irm = 1; } if (parm_ich && n > 1) tputs(tparm(parm_ich, n), n, _outch); else if (insert_character) while (--n >= 0) tputs(insert_character, 1, _outch);}/* * Delete n characters. */_delchars (n){#ifdef DEBUG if(outf) fprintf(outf, "_delchars(%d).\n", n);#endif if (enter_delete_mode) { if (strcmp(enter_delete_mode, enter_insert_mode) == 0) { if (SP->phys_irm == 0) { tputs(enter_delete_mode,1,_outch); SP->phys_irm = 1; } } else { if (SP->phys_irm == 1) { tputs(exit_insert_mode,1,_outch); SP->phys_irm = 0; } tputs(enter_delete_mode,1,_outch); } } if (parm_dch && (n > 1 || !delete_character)) tputs(tparm(parm_dch, n), 1, _outch); else while (--n >= 0) { /* Only one line can be affected by our delete char */ tputs(delete_character, 1, _outch); } if (exit_delete_mode) { if (strcmp(exit_delete_mode, exit_insert_mode) == 0) SP->phys_irm = 0; else tputs(exit_delete_mode, 1, _outch); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -