Generate interrupt key (according to terminal settings)

when user presses DEL.
This commit is contained in:
rsc 2005-08-11 16:43:37 +00:00
parent ae89363c30
commit 38897b2053
4 changed files with 30 additions and 3 deletions

View file

@ -946,13 +946,16 @@ key(Rune r)
} }
if(r == 0x7F){ /* DEL: send interrupt; what a mess */ if(r == 0x7F){ /* DEL: send interrupt; what a mess */
char rubout[1];
if(holdon){ if(holdon){
holdon = 0; holdon = 0;
drawhold(holdon); drawhold(holdon);
} }
t.qh = t.q0 = t.q1 = t.nr; t.qh = t.q0 = t.q1 = t.nr;
show(t.q0); show(t.q0);
write(rcfd, "\x7F", 1); rubout[0] = getintr(sfd);
write(rcfd, rubout, 1);
return; return;
} }
@ -1031,7 +1034,7 @@ consready(void)
/* look to see if there is a complete line */ /* look to see if there is a complete line */
for(i=t.qh; i<t.nr; i++){ for(i=t.qh; i<t.nr; i++){
c = t.r[i]; c = t.r[i];
if(c=='\n' || c=='\004' || c=='\x7F') if(c=='\n' || c=='\004' || c==0x7F)
return 1; return 1;
} }
return 0; return 0;
@ -1062,7 +1065,12 @@ consread(void)
c = *p; c = *p;
p += width; p += width;
n -= width; n -= width;
if(!raw && (c == '\n' || c == '\004' || c == '\x7F')) if(c == 0x7F){
*(p-1) = getintr(sfd);
if(!raw)
break;
}
if(!raw && (c == '\n' || c == '\004'))
break; break;
} }
n = p-buf; n = p-buf;

View file

@ -95,3 +95,12 @@ setecho(int fd, int newe)
} }
return old; return old;
} }
int
getintr(int fd)
{
if((tcgetattr(fd, &ttmode) < 0)
return 0x7F;
return ttmode.c_cc[VINTR];
}

View file

@ -117,3 +117,12 @@ setecho(int fd, int newe)
} }
return old; return old;
} }
int
getintr(int fd)
{
if(tcgetattr(fd, &ttmode) < 0)
return 0x7F;
return ttmode.c_cc[VINTR];
}

View file

@ -6,3 +6,4 @@ extern int rcstart(int, char*[], int*, int*);
extern int isecho(int); extern int isecho(int);
extern int setecho(int, int); extern int setecho(int, int);
extern int noecho; extern int noecho;
extern int getintr(int);