9term, win: better \r handling (thanks, git)

Change-Id: I75563b911b54d8957d2d004b9c27d0a2f8f043b3
Reviewed-on: https://plan9port-review.googlesource.com/1390
Reviewed-by: Russ Cox <rsc@google.com>
This commit is contained in:
Russ Cox 2015-11-10 10:25:17 -05:00 committed by Russ Cox
parent 8ee5da7cf7
commit 0d2dfbc84f
2 changed files with 31 additions and 1 deletions

View file

@ -479,6 +479,32 @@ stdinproc(void *v)
}
}
int
dropcr(char *p, int n)
{
int i;
char *w, *r;
r = p;
w = p;
for(i=0; i<n; i++) {
switch(*r) {
case '\b':
if(w > p)
w--;
break;
case '\r':
*w++ = '\n';
break;
default:
*w++ = *r;
break;
}
r++;
}
return w-p;
}
void
stdoutproc(void *v)
{
@ -507,6 +533,10 @@ stdoutproc(void *v)
n = dropcrnl(buf+npart, n);
if(n == 0)
continue;
n = dropcr(buf+npart, n);
if(n == 0)
continue;
/* squash NULs */
s = memchr(buf+npart, 0, n);

View file

@ -361,7 +361,7 @@ winctl(void *arg)
if(up == rp)
initial = wbswidth(w, '\r');
}else if(i == nr-1)
*up = '\n';
*up++ = '\n';
break;
default:
*up++ = *bp;