- if (nvis < nvismax / 2) {
- /* not worth it */
- } else if (!tt.tt_noscroll && row1x == 0 && row2x == wwnrow && dir > 0)
- {
- /*
- * We're going to assume that a line feed at the
- * bottom of the screen will cause a scroll, unless
- * "ns" is set. This should work at least 99%
- * of the time. At any rate, vi seems to do it.
- */
- if (tt.tt_row != wwnrow - 1)
- (*tt.tt_move)(wwnrow - 1, 0);
- ttputc('\n');
- deleted++;
- } else if (tt.tt_delline && tt.tt_insline) {
- /*
- * Don't worry about retain when scrolling down,
- * but do worry when scrolling up, for hp2621.
- */
- if (dir > 0) {
- (*tt.tt_move)(row1x, 0);
- (*tt.tt_delline)();
- if (row2x < wwnrow) {
- (*tt.tt_move)(row2x - 1, 0);
- (*tt.tt_insline)();
- }
- } else {
- if (tt.tt_retain || row2x != wwnrow) {
- (*tt.tt_move)(row2x - 1, 0);
- (*tt.tt_delline)();
- }
- (*tt.tt_move)(row1x, 0);
+ if (nvis < nvismax / 2)
+ goto no_scroll; /* not worth it */
+ /*
+ * Try scrolling region (or scrolling the whole screen) first.
+ * Can we assume "sr" doesn't push text below the screen
+ * so we don't have to worry about retain below?
+ * What about scrolling down with a newline? It probably does
+ * push text above (with da). Scrolling up would then have
+ * to take care of that.
+ * It's easy to be fool proof, but that slows things down.
+ * The current solution is to disallow tt_scroll_up if da or db is true
+ * but cs (scrolling region) is not. Again, we sacrifice scrolling
+ * up in favor of scrolling down. The idea is having scrolling regions
+ * probably means we can scroll (even the whole screen) with impunity.
+ * This lets us work efficiently on simple terminals (use newline
+ * on the bottom to scroll), on any terminal without retain, and
+ * on vt100 style scrolling regions (I think).
+ */
+ if (scroll_func = dir > 0 ? tt.tt_scroll_down : tt.tt_scroll_up) {
+ if (tt.tt_scroll_top != row1x || tt.tt_scroll_bot != row2x - 1)
+ if (tt.tt_setscroll == 0)
+ scroll_func = 0;
+ else
+ (*tt.tt_setscroll)(row1x, row2x - 1);
+ if (scroll_func) {
+ (*scroll_func)();
+ goto did_scroll;
+ }
+ }
+ /*
+ * Try insert/delete line.
+ * Don't worry about retain when scrolling down,
+ * but do worry when scrolling up, for hp2621.
+ */
+ if (tt.tt_delline == 0 || tt.tt_insline == 0)
+ goto no_scroll;
+ if (dir > 0) {
+ (*tt.tt_move)(row1x, 0);
+ (*tt.tt_delline)();
+ if (row2x < wwnrow) {
+ (*tt.tt_move)(row2x - 1, 0);