Пример #1
0
mvcur(int yold, int xold, int ynew, int xnew)
/* optimized cursor move from (yold, xold) to (ynew, xnew) */
{
    NCURSES_CH_T oldattr;
    int code;

    TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
				  yold, xold, ynew, xnew));

    if (SP == 0) {
	code = ERR;
    } else if (yold == ynew && xold == xnew) {
	code = OK;
    } else {

	/*
	 * Most work here is rounding for terminal boundaries getting the
	 * column position implied by wraparound or the lack thereof and
	 * rolling up the screen to get ynew on the screen.
	 */
	if (xnew >= screen_columns) {
	    ynew += xnew / screen_columns;
	    xnew %= screen_columns;
	}

	/*
	 * Force restore even if msgr is on when we're in an alternate
	 * character set -- these have a strong tendency to screw up the CR &
	 * LF used for local character motions!
	 */
	oldattr = SCREEN_ATTRS(SP);
	if ((AttrOf(oldattr) & A_ALTCHARSET)
	    || (AttrOf(oldattr) && !move_standout_mode)) {
	    TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
			       (unsigned long) AttrOf(oldattr),
			       _traceattr(AttrOf(oldattr))));
	    (void) VIDATTR(A_NORMAL, 0);
	}

	if (xold >= screen_columns) {
	    int l;

	    if (SP->_nl) {
		l = (xold + 1) / screen_columns;
		yold += l;
		if (yold >= screen_lines)
		    l -= (yold - screen_lines - 1);

		if (l > 0) {
		    if (carriage_return) {
			TPUTS_TRACE("carriage_return");
			putp(carriage_return);
		    } else
			_nc_outch('\r');
		    xold = 0;

		    while (l > 0) {
			if (newline) {
			    TPUTS_TRACE("newline");
			    putp(newline);
			} else
			    _nc_outch('\n');
			l--;
		    }
		}
	    } else {
		/*
		 * If caller set nonl(), we cannot really use newlines to
		 * position to the next row.
		 */
		xold = -1;
		yold = -1;
	    }
	}

	if (yold > screen_lines - 1)
	    yold = screen_lines - 1;
	if (ynew > screen_lines - 1)
	    ynew = screen_lines - 1;

	/* destination location is on screen now */
	code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);

	/*
	 * Restore attributes if we disabled them before moving.
	 */
	if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) {
	    TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
			       (unsigned long) AttrOf(oldattr),
			       _traceattr(AttrOf(oldattr))));
	    (void) VIDATTR(AttrOf(oldattr), GetPair(oldattr));
	}
    }
    returnCode(code);
}
Пример #2
0
mvcur(int yold, int xold, int ynew, int xnew)
/* optimized cursor move from (yold, xold) to (ynew, xnew) */
{
    TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
				  yold, xold, ynew, xnew));

    if (SP == 0)
	returnCode(ERR);

    if (yold == ynew && xold == xnew)
	returnCode(OK);

    /*
     * Most work here is rounding for terminal boundaries getting the
     * column position implied by wraparound or the lack thereof and
     * rolling up the screen to get ynew on the screen.
     */

    if (xnew >= screen_columns) {
	ynew += xnew / screen_columns;
	xnew %= screen_columns;
    }
    if (xold >= screen_columns) {
	int l;

	if (SP->_nl) {
	    l = (xold + 1) / screen_columns;
	    yold += l;
	    if (yold >= screen_lines)
		l -= (yold - screen_lines - 1);

	    while (l > 0) {
		if (newline) {
		    TPUTS_TRACE("newline");
		    tputs(newline, 0, _nc_outch);
		} else
		    putchar('\n');
		l--;
		if (xold > 0) {
		    if (carriage_return) {
			TPUTS_TRACE("carriage_return");
			tputs(carriage_return, 0, _nc_outch);
		    } else
			putchar('\r');
		    xold = 0;
		}
	    }
	} else {
	    /*
	     * If caller set nonl(), we cannot really use newlines to position
	     * to the next row.
	     */
	    xold = -1;
	    yold = -1;
	}
    }

    if (yold > screen_lines - 1)
	yold = screen_lines - 1;
    if (ynew > screen_lines - 1)
	ynew = screen_lines - 1;

    /* destination location is on screen now */
    returnCode(onscreen_mvcur(yold, xold, ynew, xnew, TRUE));
}