📄 mvcur.c
字号:
/* some tabs plus some lefts */ nleft = tabcol - newcol; c1 = ntabs*_cost(Tab) + nleft*_cost(Cursor_left); } c0 = (newcol - oldcol) * _cost(Cursor_right); if (parm_right_cursor) c2 = _cost(Parm_right_cursor); else c2 = INFINITY; if (column_address) c3 = _cost(Column_address); else c3 = INFINITY; #ifdef DEBUG if(outf) fprintf(outf, "_loc_right(%d, %d, %d), chars %d, ri %d, RI %d, ch %d\n", oldcol, newcol, domotion, c0, c1, c2, c3);#endif /* Decide and maybe do them */ if (c3 <= c1 && c3 <= c2 && c3 <= c0) { /* cheapest to use column absolute cursor addressing */#ifdef DEBUG if(outf) fprintf(outf, "chose column absolute cursor addressing\n");#endif if (domotion) tputs(tparm(column_address, newcol), 1, _outch); return c3; } else if (c2 <= c1 && c2 <= c0) { /* cheapest to use column relative motion */#ifdef DEBUG if(outf) fprintf(outf, "chose column relative motion\n");#endif if (domotion) tputs(tparm(parm_right_cursor, newcol-oldcol), 1, _outch); return c2; } else { /* cheapest to use several right commands */#ifdef DEBUG if(outf) fprintf(outf, "chose rights: ntabs %d, tabcol %d, nleft %d, nright %d\n", ntabs, tabcol, nleft, nright);#endif if (domotion) if (c1 < c0) { for (i=0; i<ntabs; i++) tputs(tab, 1, _outch); if (tabcol < newcol) { /* some tabs plus some rights */ for (i=0; i<nright; i++) {#ifdef DEBUG if (outf && SP->cur_body[row+1]) fprintf(outf, "nd1, row %d col %d+%d=%d, char '%c'\n", row, tabcol, i, tabcol+i, SP->cur_body[row+1]->body[tabcol+i]);#endif rp = SP->cur_body[row+1]; if (cursor_right && (!notinsmode || rp && SP->phys_gr != (rp->body[tabcol+i] & A_ATTRIBUTES))) /* dont know */ tputs(cursor_right,1,_outch); else if (rp && rp->length > tabcol+i) /* Note we assume dumb terminals without cursor_right don't have * standout either, otherwise we should go into right standout * mode here and in the essentially similar code below. */ _outch(rp->body[tabcol+i]&A_CHARTEXT); else /* off edge */ _outch(' '); } } else { /* some tabs plus some lefts */ for (i=0; i<nleft; i++) tputs(cursor_left,1,_outch); } } else { for (i=oldcol; i<newcol; i++) {#ifdef DEBUG if (outf && SP->cur_body[row+1]) fprintf(outf, "nd2, row %d col %d, char '%c'\n", row, i, SP->cur_body[row+1]->body[i]);#endif rp = SP->cur_body[row+1]; if (cursor_right && (!notinsmode || rp && SP->phys_gr != (rp->body[i] & A_ATTRIBUTES))) /* dont know */ tputs(cursor_right,1,_outch); else if (rp && rp->length > i) _outch(rp->body[i]&A_CHARTEXT); else /* off edge */ _outch(' '); } } return (c1 < c0) ? c1 : c0; }}static_loc_left(oldcol, newcol, domotion){ int c1, c2, c3; int i, tabcol, ntabs, nright, nleft; if (newcol > oldcol) /* can't go right with left motions */ return INFINITY; if (newcol == oldcol) return 0; /* already there - nothing to do */ /* figure out various costs */ if (cursor_left) { if (back_tab) { tabcol = (newcol+4)/8 * 8; /* round to nearest 8 */ /* tab past left margin is undefined */ if (tabcol < 8) tabcol = 8; ntabs = (oldcol-tabcol+7)/8; if (ntabs <= 0) tabcol = oldcol; if (tabcol < newcol) { /* some backtabs plus some rights */ nright = newcol - tabcol; c1 = ntabs*_cost(Back_tab) + nright*_cost(Cursor_right); } else { /* some tabs plus some lefts */ nleft = tabcol - newcol; c1 = ntabs*_cost(Back_tab) + nleft*_cost(Cursor_left); } } else { c1 = (oldcol - newcol) * _cost(Cursor_left); } } else c1 = INFINITY; if (parm_left_cursor) c2 = _cost(Parm_left_cursor); else c2 = INFINITY; if (column_address) c3 = _cost(Column_address); else c3 = INFINITY; #ifdef DEBUG if(outf) fprintf(outf, "_loc_left(%d, %d, %d), le %d, LE %d, ch %d\n", oldcol, newcol, domotion, c1, c2, c3);#endif /* Decide and maybe do them */ if (c3 <= c1 && c3 <= c2) { /* cheapest to use column absolute cursor addressing */#ifdef DEBUG if(outf) fprintf(outf, "chose column absolute cursor addressing\n");#endif if (domotion) tputs(tparm(column_address, newcol), 1, _outch); return c3; } else if (c2 <= c1) { /* cheapest to use column relative motion */#ifdef DEBUG if(outf) fprintf(outf, "chose column relative motion\n");#endif if (domotion) tputs(tparm(parm_left_cursor, oldcol-newcol), 1, _outch); return c2; } else { /* cheapest to use several left commands */#ifdef DEBUG if(outf) fprintf(outf, "chose several left commands\n");#endif if (domotion) if (back_tab) { for (i=0; i<ntabs; i++) tputs(back_tab, 1, _outch); if (tabcol < newcol) { /* some tabs plus some rights */ for (i=0; i<nright; i++) tputs(cursor_right,1, _outch); } else { /* some tabs plus some lefts */ for (i=0; i<nleft; i++) tputs(cursor_left,1,_outch); } } else { for (i=oldcol; i>newcol; i--) tputs(cursor_left, 1, _outch); } return c1; }}static_loc_up(oldrow, newrow, domotion){ int c1, c2, c3, i; if (newrow > oldrow) /* can't go down with up motions */ return INFINITY; if (newrow == oldrow) return 0; /* already there - nothing to do */ /* figure out various costs */ if (cursor_up) c1 = (oldrow - newrow) * _cost(Cursor_up); else c1 = INFINITY; if (parm_up_cursor) c2 = _cost(Parm_up_cursor); else c2 = INFINITY; if (row_address) c3 = _cost(Row_address); else c3 = INFINITY; #ifdef DEBUG if(outf) fprintf(outf, "_loc_up(%d, %d, %d), up %d, UP %d, cv %d\n", oldrow, newrow, domotion, c1, c2, c3);#endif /* Decide and maybe do them */ if (c3 <= c1 && c3 <= c2) { /* cheapest to use row absolute cursor addressing */#ifdef DEBUG if(outf) fprintf(outf, "chose row absolute cursor addressing\n");#endif if (domotion) tputs(tparm(row_address, newrow), 1, _outch); return c3; } else if (c2 <= c1) { /* cheapest to use row relative motion */#ifdef DEBUG if(outf) fprintf(outf, "chose row relative motion\n");#endif if (domotion) tputs(tparm(parm_up_cursor, oldrow-newrow), 1, _outch); return c2; } else { /* cheapest to use several up commands */#ifdef DEBUG if(outf) fprintf(outf, "chose several up commands\n");#endif if (domotion) for (i=oldrow; i>newrow; i--) tputs(cursor_up, 1, _outch); return c1; }}static_loc_down(oldrow, newrow, domotion, col){ int c1, c2, c3, i; if (newrow < oldrow) /* can't go up with down motions */ return INFINITY; if (newrow == oldrow) return 0; /* already there - nothing to do */ /* figure out various costs */ if (cursor_down && (col==0 || bare_lf_ok || *cursor_down!='\n')) c1 = (newrow - oldrow) * _cost(Cursor_down); else c1 = INFINITY; if (parm_down_cursor) c2 = _cost(Parm_down_cursor); else c2 = INFINITY; if (row_address) c3 = _cost(Row_address); else c3 = INFINITY; #ifdef DEBUG if(outf) fprintf(outf, "_loc_down(%d, %d, %d, %d), do %d, DO %d, cv %d\n", oldrow, newrow, domotion, col,c1, c2, c3);#endif /* Decide and maybe do them */ if (c3 <= c1 && c3 <= c2) { /* cheapest to use row absolute cursor addressing */#ifdef DEBUG if(outf) fprintf(outf, "chose row absolute cursor addressing\n");#endif if (domotion) tputs(tparm(row_address, newrow), 1, _outch); return c3; } else if (c2 <= c1) { /* cheapest to use row relative motion */#ifdef DEBUG if(outf) fprintf(outf, "chose row relative motion\n");#endif if (domotion) tputs(tparm(parm_down_cursor, newrow-oldrow), 1, _outch); return c2; } else { /* cheapest to use several down commands */#ifdef DEBUG if(outf) fprintf(outf, "chose several down commands\n");#endif if (domotion) for (i=oldrow; i<newrow; i++) tputs(cursor_down, 1, _outch); return c1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -