9term, acme: autoscroll

Ignore scroll/noscroll window setting.
Instead, scroll when the write begins in
or immediately after the displayed window content.

In the new scrolling discipline, executing
"Noscroll" is replaced by typing Page Up or
using the mouse to scroll higher in the buffer,
and executing "Scroll" is replaced by typing End
or using the mouse to scroll to the bottom of
the buffer.

R=r, r2
http://codereview.appspot.com/4433060
This commit is contained in:
Russ Cox 2011-04-27 13:18:07 -04:00
parent 42ef984cf2
commit ba31ab3044
12 changed files with 32 additions and 72 deletions

View file

@ -30,8 +30,9 @@ Otherwise button 2 brings up a menu, described below.
.PP .PP
The The
.B -s .B -s
option initializes the window so that text scrolls; option has no effect. It formerly set the scrolling mode,
the default is not to scroll. and is recognized to avoid breaking scripts that create new windows.
See below for a description of scrolling behavior.
.PP .PP
The The
.B -c .B -c
@ -205,10 +206,9 @@ always treats the DEL keystroke as an interrupt request.
In response it sends the terminal's current interrupt character In response it sends the terminal's current interrupt character
(which need not be DEL). (which need not be DEL).
.PP .PP
Normally, written output to a window blocks when Written output to a window is appended to the end of the window.
the text reaches the end of the screen and the terminal The window scrolls to display the new output only if the
buffer fills; end of the window was visible before the write.
a button 2 menu item toggles scrolling.
.PP .PP
.I 9term .I 9term
changes behavior according to changes behavior according to

View file

@ -646,13 +646,17 @@ window and runs a
(default (default
.BR $SHELL ) .BR $SHELL )
in it, turning the window into something analogous to an in it, turning the window into something analogous to an
.IR rio (1) .IR 9term (1)
window. window.
Executing text in a Executing text in a
.I win .I win
window with button window with button
2 is similar to using 2 is similar to using
.BR Send . .BR Send .
.I Win
windows follow the same scrolling heuristic as in
.IR 9term (1):
the window scrolls on output only if the window is displaying the end of the buffer.
.PP .PP
.I Awd .I Awd
loads the tag line of its window with the directory in which it's running, suffixed loads the tag line of its window with the directory in which it's running, suffixed

View file

@ -73,13 +73,11 @@ and then to fall back to
.IR xterm (1). .IR xterm (1).
The The
.B \-s .B \-s
option causes option has no effect. It formerly set the scrolling mode for
.I rio new windows and is recognized to avoid breaking scripts.
to add See
.B -s .IR 9term (1)
to for a description of scrolling behavior.
.IR 9term 's
command-line, starting the window in scrolling mode.
.PP .PP
The The
.B \-version .B \-version

View file

@ -236,22 +236,11 @@ may be undone in a single
.B Undo .B Undo
interactive command. interactive command.
.TP .TP
.B noscroll
Turn off automatic `scrolling' of the window to show text written to the body.
.TP
.B put .B put
Equivalent to the Equivalent to the
.B Put .B Put
interactive command with no arguments; accepts no arguments. interactive command with no arguments; accepts no arguments.
.TP .TP
.B scroll
Cancel a
.B noscroll
message, returning the window to the default state wherein each write
to the
.B body
file causes the window to `scroll' to display the new text.
.TP
.B show .B show
Guarantee at least some of the selected text is visible on the display. Guarantee at least some of the selected text is visible on the display.
.RE .RE

View file

@ -67,7 +67,7 @@ threadmain(int argc, char *argv[])
fontname = EARGF(usage()); fontname = EARGF(usage());
break; break;
case 's': case 's':
scrolling = TRUE; /* no-op */
break; break;
case 'c': case 'c':
cooked = TRUE; cooked = TRUE;
@ -114,7 +114,7 @@ threadmain(int argc, char *argv[])
timerinit(); timerinit();
servedevtext(); servedevtext();
rcpid = rcstart(argc, argv, &rcfd, &sfd); rcpid = rcstart(argc, argv, &rcfd, &sfd);
w = new(screen, FALSE, scrolling, rcpid, ".", nil, nil); w = new(screen, FALSE, rcpid, ".", nil, nil);
threadcreate(keyboardthread, nil, STACK); threadcreate(keyboardthread, nil, STACK);
threadcreate(mousethread, nil, STACK); threadcreate(mousethread, nil, STACK);
@ -241,7 +241,7 @@ wpointto(Point pt)
} }
Window* Window*
new(Image *i, int hideit, int scrollit, int pid, char *dir, char *cmd, char **argv) new(Image *i, int hideit, int pid, char *dir, char *cmd, char **argv)
{ {
Window *w; Window *w;
Mousectl *mc; Mousectl *mc;
@ -258,7 +258,7 @@ new(Image *i, int hideit, int scrollit, int pid, char *dir, char *cmd, char **ar
*mc = *mousectl; *mc = *mousectl;
/* mc->image = i; */ /* mc->image = i; */
mc->c = cm; mc->c = cm;
w = wmk(i, mc, ck, cctl, scrollit); w = wmk(i, mc, ck, cctl);
free(mc); /* wmk copies *mc */ free(mc); /* wmk copies *mc */
window = erealloc(window, ++nwindow*sizeof(Window*)); window = erealloc(window, ++nwindow*sizeof(Window*));
window[nwindow-1] = w; window[nwindow-1] = w;
@ -288,7 +288,6 @@ enum
Snarf, Snarf,
Plumb, Plumb,
Send, Send,
Scroll,
Cook Cook
}; };
@ -298,7 +297,6 @@ char *menu2str[] = {
"snarf", "snarf",
"plumb", "plumb",
"send", "send",
"scroll",
"cook", "cook",
nil nil
}; };
@ -317,10 +315,6 @@ button2menu(Window *w)
if(w->deleted) if(w->deleted)
return; return;
incref(&w->ref); incref(&w->ref);
if(w->scrolling)
menu2str[Scroll] = "noscroll";
else
menu2str[Scroll] = "scroll";
if(cooked) if(cooked)
menu2str[Cook] = "nocook"; menu2str[Cook] = "nocook";
else else
@ -365,11 +359,6 @@ button2menu(Window *w)
wshow(w, w->nr); wshow(w, w->nr);
break; break;
case Scroll:
if(w->scrolling ^= 1)
wshow(w, w->nr);
break;
case Cook: case Cook:
cooked ^= 1; cooked ^= 1;
break; break;

View file

@ -131,7 +131,6 @@ struct Window
Rectangle lastsr; Rectangle lastsr;
int topped; int topped;
int notefd; int notefd;
uchar scrolling;
Cursor cursor; Cursor cursor;
Cursor *cursorp; Cursor *cursorp;
uchar holding; uchar holding;
@ -149,7 +148,7 @@ int winborder(Window*, Point);
void winctl(void*); void winctl(void*);
void winshell(void*); void winshell(void*);
Window* wlookid(int); Window* wlookid(int);
Window* wmk(Image*, Mousectl*, Channel*, Channel*, int); Window* wmk(Image*, Mousectl*, Channel*, Channel*);
Window* wpointto(Point); Window* wpointto(Point);
Window* wtop(Point); Window* wtop(Point);
void wtopme(Window*); void wtopme(Window*);

View file

@ -6,7 +6,7 @@ int whide(Window*);
int wunhide(int); int wunhide(int);
void freescrtemps(void); void freescrtemps(void);
int parsewctl(char**, Rectangle, Rectangle*, int*, int*, int*, int*, char**, char*, char*); int parsewctl(char**, Rectangle, Rectangle*, int*, int*, int*, int*, char**, char*, char*);
Window *new(Image*, int, int, int, char*, char*, char**); Window *new(Image*, int, int, char*, char*, char**);
void riosetcursor(Cursor*, int); void riosetcursor(Cursor*, int);
int min(int, int); int min(int, int);
int max(int, int); int max(int, int);

View file

@ -181,7 +181,7 @@ threadmain(int argc, char **argv)
putenv("winid", buf); putenv("winid", buf);
sprint(buf, "%d/tag", id); sprint(buf, "%d/tag", id);
fd = fsopenfd(fs, buf, OWRITE|OCEXEC); fd = fsopenfd(fs, buf, OWRITE|OCEXEC);
write(fd, " Send Noscroll", 1+4+1+8); write(fd, " Send", 1+4);
close(fd); close(fd);
sprint(buf, "%d/event", id); sprint(buf, "%d/event", id);
eventfd = fsopen(fs, buf, ORDWR|OCEXEC); eventfd = fsopen(fs, buf, ORDWR|OCEXEC);
@ -440,14 +440,6 @@ stdinproc(void *v)
} }
char buf[100]; char buf[100];
snprint(buf, sizeof buf, "%.*S", e.nr, e.r); snprint(buf, sizeof buf, "%.*S", e.nr, e.r);
if(cistrcmp(buf, "scroll") == 0) {
fsprint(ctlfd, "scroll\nshow");
break;
}
if(cistrcmp(buf, "noscroll") == 0) {
fsprint(ctlfd, "noscroll");
break;
}
if(cistrcmp(buf, "cook") == 0) { if(cistrcmp(buf, "cook") == 0) {
cook = 1; cook = 1;
break; break;

View file

@ -36,7 +36,7 @@ static Image *lightholdcol;
static Image *paleholdcol; static Image *paleholdcol;
Window* Window*
wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling) wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl)
{ {
Window *w; Window *w;
Rectangle r; Rectangle r;
@ -77,7 +77,6 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
w->topped = ++topped; w->topped = ++topped;
w->id = ++id; w->id = ++id;
w->notefd = -1; w->notefd = -1;
w->scrolling = scrolling;
w->dir = estrdup(startdir); w->dir = estrdup(startdir);
w->label = estrdup("<unnamed>"); w->label = estrdup("<unnamed>");
r = insetrect(w->i->r, Selborder); r = insetrect(w->i->r, Selborder);
@ -192,7 +191,7 @@ winctl(void *arg)
{ {
Rune *rp, *bp, *up, *kbdr; Rune *rp, *bp, *up, *kbdr;
uint qh; uint qh;
int nr, nb, c, wid, i, npart, initial, lastb; int nr, nb, c, wid, i, npart, initial, lastb, scrolling;
char *s, *t, part[UTFmax]; char *s, *t, part[UTFmax];
Window *w; Window *w;
Mousestate *mp, m; Mousestate *mp, m;
@ -248,9 +247,6 @@ winctl(void *arg)
alts[WMouseread].op = CHANSND; alts[WMouseread].op = CHANSND;
else else
alts[WMouseread].op = CHANNOP; alts[WMouseread].op = CHANNOP;
if(!w->scrolling && !w->mouseopen && w->qh>w->org+w->f.nchars)
alts[WCwrite].op = CHANNOP;
else
alts[WCwrite].op = CHANSND; alts[WCwrite].op = CHANSND;
if(w->deleted || !w->wctlready) if(w->deleted || !w->wctlready)
alts[WWread].op = CHANNOP; alts[WWread].op = CHANNOP;
@ -369,8 +365,9 @@ winctl(void *arg)
w->qh = qh; w->qh = qh;
} }
nr = up - rp; nr = up - rp;
scrolling = w->org <= w->qh && w->qh <= w->org + w->f.nchars;
w->qh = winsert(w, rp, nr, w->qh)+nr; w->qh = winsert(w, rp, nr, w->qh)+nr;
if(w->scrolling || w->mouseopen) if(scrolling)
wshow(w, w->qh); wshow(w, w->qh);
wsetselect(w, w->q0, w->q1); wsetselect(w, w->q0, w->q1);
wscrdraw(w); wscrdraw(w);

View file

@ -243,7 +243,6 @@ struct Window
Range limit; Range limit;
uchar nopen[QMAX]; uchar nopen[QMAX];
uchar nomark; uchar nomark;
uchar noscroll;
Range wrselrange; Range wrselrange;
int rdselfd; int rdselfd;
Column *col; Column *col;

View file

@ -960,6 +960,7 @@ sendx(Text *et, Text *t, Text *_0, int _1, int _2, Rune *_3, int _4)
if(textreadc(t, t->file->b.nc-1) != '\n'){ if(textreadc(t, t->file->b.nc-1) != '\n'){
textinsert(t, t->file->b.nc, Lnl, 1, TRUE); textinsert(t, t->file->b.nc, Lnl, 1, TRUE);
textsetselect(t, t->file->b.nc, t->file->b.nc); textsetselect(t, t->file->b.nc, t->file->b.nc);
textshow(t, t->q1, t->q1, 1);
} }
} }

View file

@ -510,8 +510,8 @@ xfidwrite(Xfid *x)
if(tq1 >= q0) if(tq1 >= q0)
tq1 += nr; tq1 += nr;
textsetselect(t, tq0, tq1); textsetselect(t, tq0, tq1);
if(!t->w->noscroll) if(t->org <= q0 && q0 <= t->org+t->fr.nchars)
textshow(t, q0, q0+nr, 0); textshow(t, q0+nr, q0+nr, 0);
textscrdraw(t); textscrdraw(t);
winsettag(w); winsettag(w);
free(r); free(r);
@ -568,7 +568,7 @@ xfidwrite(Xfid *x)
} }
q0 = textbsinsert(t, q0, r, nr, TRUE, &nr); q0 = textbsinsert(t, q0, r, nr, TRUE, &nr);
textsetselect(t, t->q0, t->q1); /* insert could leave it somewhere else */ textsetselect(t, t->q0, t->q1); /* insert could leave it somewhere else */
if(qid!=QWwrsel && !t->w->noscroll) if(qid!=QWwrsel && t->org <= q0 && q0 < t->org+t->fr.nchars)
textshow(t, q0+nr, q0+nr, 1); textshow(t, q0+nr, q0+nr, 1);
textscrdraw(t); textscrdraw(t);
} }
@ -768,18 +768,10 @@ out:
w->filemenu = TRUE; w->filemenu = TRUE;
m = 4; m = 4;
}else }else
if(strncmp(p, "noscroll", 8) == 0){ /* turn off automatic scrolling */
w->noscroll = TRUE;
m = 8;
}else
if(strncmp(p, "cleartag", 8) == 0){ /* wipe tag right of bar */ if(strncmp(p, "cleartag", 8) == 0){ /* wipe tag right of bar */
wincleartag(w); wincleartag(w);
settag = TRUE; settag = TRUE;
m = 8; m = 8;
}else
if(strncmp(p, "scroll", 6) == 0){ /* turn on automatic scrolling (writes to body only) */
w->noscroll = FALSE;
m = 6;
}else{ }else{
err = Ebadctl; err = Ebadctl;
break; break;