make echoing work.
This commit is contained in:
parent
aba09191af
commit
a2705f207f
9 changed files with 50 additions and 153 deletions
|
|
@ -835,7 +835,7 @@ key(Rune r)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rawon = israw(sfd);
|
rawon = !isecho(sfd);
|
||||||
if(rawon && t.q0==t.nr){
|
if(rawon && t.q0==t.nr){
|
||||||
addraw(&r, 1);
|
addraw(&r, 1);
|
||||||
consread();
|
consread();
|
||||||
|
|
@ -927,7 +927,7 @@ consready(void)
|
||||||
if(holdon)
|
if(holdon)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rawon = israw(sfd);
|
rawon = !isecho(sfd);
|
||||||
if(rawon)
|
if(rawon)
|
||||||
return t.nraw != 0;
|
return t.nraw != 0;
|
||||||
|
|
||||||
|
|
@ -946,12 +946,11 @@ consread(void)
|
||||||
{
|
{
|
||||||
char buf[8000], *p;
|
char buf[8000], *p;
|
||||||
int c, width, n;
|
int c, width, n;
|
||||||
int echo;
|
int s;
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(!consready())
|
if(!consready())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
n = sizeof(buf);
|
n = sizeof(buf);
|
||||||
p = buf;
|
p = buf;
|
||||||
c = 0;
|
c = 0;
|
||||||
|
|
@ -965,19 +964,22 @@ consread(void)
|
||||||
c = *p;
|
c = *p;
|
||||||
p += width;
|
p += width;
|
||||||
n -= width;
|
n -= width;
|
||||||
rawon = israw(sfd);
|
rawon = !isecho(sfd);
|
||||||
if(!rawon && (c == '\n' || c == '\004' || c == '\x7F'))
|
if(!rawon && (c == '\n' || c == '\004' || c == '\x7F'))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* take out control-d when not doing a zero length write */
|
|
||||||
n = p-buf;
|
n = p-buf;
|
||||||
if(0) fprint(2, "write buf\n");
|
|
||||||
/* temporarily disable echo for buf. sensitive to race? Axel. */
|
/*
|
||||||
// echo = setecho(sfd, 0);
|
* We've been echoing, so make sure the terminal isn't
|
||||||
|
* while we do the write. This screws up if someone
|
||||||
|
* else tries to turn on echo at the same time (we'll turn it
|
||||||
|
* off again after the write), but that's not too likely.
|
||||||
|
*/
|
||||||
|
s = setecho(sfd, 0);
|
||||||
if(write(rcfd, buf, n) < 0)
|
if(write(rcfd, buf, n) < 0)
|
||||||
exits(0);
|
exits(0);
|
||||||
// setecho(sfd, echo);
|
setecho(sfd, s);
|
||||||
/* mallocstats(); */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1258,7 +1260,7 @@ paste(Rune *r, int n, int advance)
|
||||||
{
|
{
|
||||||
Rune *rbuf;
|
Rune *rbuf;
|
||||||
|
|
||||||
rawon = israw(sfd);
|
rawon = !isecho(sfd);
|
||||||
if(rawon && t.q0==t.nr){
|
if(rawon && t.q0==t.nr){
|
||||||
addraw(r, n);
|
addraw(r, n);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
extern int getpts(int[], char*);
|
|
||||||
extern int childpty(int[], char*);
|
|
||||||
extern void updatewinsize(int, int, int, int);
|
|
||||||
extern int rcfd[];
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include "9term.h"
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/termios.h>
|
#include <sys/termios.h>
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include "term.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
getpts(int fd[], char *slave)
|
getpts(int fd[], char *slave)
|
||||||
|
|
|
||||||
|
|
@ -1,63 +1 @@
|
||||||
#include <u.h>
|
#include "bsdpty.c"
|
||||||
#include <termios.h>
|
|
||||||
#include <sys/termios.h>
|
|
||||||
#include <pty.h>
|
|
||||||
#include <libc.h>
|
|
||||||
#include "9term.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
getpts(int fd[], char *slave)
|
|
||||||
{
|
|
||||||
openpty(&fd[1], &fd[0], slave, 0, 0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
childpty(int fd[], char *slave)
|
|
||||||
{
|
|
||||||
int sfd;
|
|
||||||
|
|
||||||
close(fd[1]);
|
|
||||||
setsid();
|
|
||||||
sfd = open(slave, ORDWR);
|
|
||||||
if(sfd < 0)
|
|
||||||
sysfatal("open %s: %r\n", slave);
|
|
||||||
if(ioctl(sfd, TIOCSCTTY, 0) < 0)
|
|
||||||
fprint(2, "ioctl TIOCSCTTY: %r\n");
|
|
||||||
return sfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct winsize ows;
|
|
||||||
|
|
||||||
void
|
|
||||||
updatewinsize(int row, int col, int dx, int dy)
|
|
||||||
{
|
|
||||||
struct winsize ws;
|
|
||||||
|
|
||||||
ws.ws_row = row;
|
|
||||||
ws.ws_col = col;
|
|
||||||
ws.ws_xpixel = dx;
|
|
||||||
ws.ws_ypixel = dy;
|
|
||||||
if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
|
|
||||||
if(ioctl(rcfd[0], TIOCSWINSZ, &ws) < 0)
|
|
||||||
fprint(2, "ioctl: %r\n");
|
|
||||||
ows = ws;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
israw(int fd)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
/*
|
|
||||||
if(tcgetattr(fd, &ttmode) < 0)
|
|
||||||
fprint(2, "tcgetattr: %r\n");
|
|
||||||
return !(ttmode.c_lflag&(ICANON|ECHO));
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
setecho(int fd, int on)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include "9term.h"
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/termios.h>
|
#include <sys/termios.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include "term.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
getpts(int fd[], char *slave)
|
getpts(int fd[], char *slave)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "term.h"
|
#include "term.h"
|
||||||
|
|
||||||
|
#define debug 0
|
||||||
|
|
||||||
int
|
int
|
||||||
getpts(int fd[], char *slave)
|
getpts(int fd[], char *slave)
|
||||||
{
|
{
|
||||||
|
|
@ -55,72 +57,34 @@ updatewinsize(int row, int col, int dx, int dy)
|
||||||
ows = ws;
|
ows = ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* israw has been inspired by Matty Farrow's 9term.
|
|
||||||
* The code below is probably a gross simplification --
|
|
||||||
* for the few cases tested it seems to be enough.
|
|
||||||
* However, for example, Matty's code also looks at ISIG,
|
|
||||||
* whereas, we do not (yet?). Axel.
|
|
||||||
*
|
|
||||||
*Note: I guess only the get/set terminal mode attribute
|
|
||||||
* code needs to be here; the logic around it could be
|
|
||||||
* elswhere (9term.c) - but if the code below is split,
|
|
||||||
* the question is what a nice interface would be. Axel.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static struct termios ttmode;
|
static struct termios ttmode;
|
||||||
|
|
||||||
int
|
int
|
||||||
israw(int fd)
|
israw(int fd)
|
||||||
{
|
{
|
||||||
int e, c, i;
|
if(tcgetattr(fd, &ttmode) < 0)
|
||||||
|
fprint(2, "tcgetattr: %r\n");
|
||||||
tcgetattr(fd, &ttmode);
|
if(debug) fprint(2, "israw %c%c\n",
|
||||||
c = (ttmode.c_lflag & ICANON) ? 1 : 0;
|
ttmode.c_lflag&ICANON ? 'c' : '-',
|
||||||
e = (ttmode.c_lflag & ECHO) ? 1 : 0;
|
ttmode.c_lflag&ECHO ? 'e' : '-');
|
||||||
i = (ttmode.c_lflag & ISIG) ? 1 : 0;
|
return !(ttmode.c_lflag&(ICANON|ECHO));
|
||||||
|
|
||||||
if(0) fprint(2, "israw: icanon=%d echo=%d isig=%d\n", c, e, i);
|
|
||||||
|
|
||||||
return !c || !e ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
setecho(int fd, int on)
|
setecho(int fd, int newe)
|
||||||
{
|
{
|
||||||
int e, c, i;
|
int old;
|
||||||
int oldecho;
|
|
||||||
|
|
||||||
tcgetattr(fd, &ttmode);
|
if(tcgetattr(fd, &ttmode) < 0)
|
||||||
c = (ttmode.c_lflag & ICANON) ? 1 : 0;
|
fprint(2, "tcgetattr: %r\n");
|
||||||
e = (ttmode.c_lflag & ECHO) ? 1 : 0;
|
old = (ttmode.c_lflag&ECHO)==ECHO;
|
||||||
i = (ttmode.c_lflag & ISIG) ? 1 : 0;
|
if(old != newe){
|
||||||
|
if(newe)
|
||||||
if(0) fprint(2, "setecho(%d) pre: icanon=%d echo=%d isig=%d\n", on, c, e, i);
|
ttmode.c_lflag |= ECHO;
|
||||||
|
else
|
||||||
oldecho = e;
|
ttmode.c_lflag &= ~ECHO;
|
||||||
|
if(tcsetattr(fd, TCSANOW, &ttmode) < 0)
|
||||||
if (oldecho == on)
|
fprint(2, "tcsetattr: %r\n");
|
||||||
return oldecho;
|
|
||||||
|
|
||||||
if (on) {
|
|
||||||
ttmode.c_lflag |= ECHO;
|
|
||||||
tcsetattr(fd, TCSANOW, &ttmode);
|
|
||||||
} else {
|
|
||||||
ttmode.c_lflag &= ~ECHO;
|
|
||||||
tcsetattr(fd, TCSANOW, &ttmode);
|
|
||||||
}
|
}
|
||||||
|
return old;
|
||||||
if (0){
|
|
||||||
tcgetattr(fd, &ttmode);
|
|
||||||
c = (ttmode.c_lflag & ICANON) ? 1 : 0;
|
|
||||||
e = (ttmode.c_lflag & ECHO) ? 1 : 0;
|
|
||||||
i = (ttmode.c_lflag & ISIG) ? 1 : 0;
|
|
||||||
|
|
||||||
fprint(2, "setecho(%d) post: icanon=%d echo=%d isig=%d\n", on, c, e, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return oldecho;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,5 @@ SHORTLIB=complete frame draw plumb fs mux thread 9
|
||||||
|
|
||||||
LDFLAGS=-L$X11/lib -lX11
|
LDFLAGS=-L$X11/lib -lX11
|
||||||
|
|
||||||
|
Linux.$O: bsdpty.c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,10 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "term.h"
|
#include "term.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* Somehow we no longer automatically exit
|
|
||||||
* when the shell exits; hence the SIGCHLD stuff.
|
|
||||||
* Something that can be fixed? Axel.
|
|
||||||
*/
|
|
||||||
static int pid;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
rcstart(int argc, char **argv, int *pfd, int *tfd)
|
rcstart(int argc, char **argv, int *pfd, int *tfd)
|
||||||
{
|
{
|
||||||
int fd[2];
|
int fd[2], i, pid;
|
||||||
char *xargv[3];
|
char *xargv[3];
|
||||||
char slave[256];
|
char slave[256];
|
||||||
int sfd;
|
int sfd;
|
||||||
|
|
@ -36,7 +29,6 @@ rcstart(int argc, char **argv, int *pfd, int *tfd)
|
||||||
fd[0] = fd[1] = -1;
|
fd[0] = fd[1] = -1;
|
||||||
if(getpts(fd, slave) < 0)
|
if(getpts(fd, slave) < 0)
|
||||||
sysfatal("getpts: %r\n");
|
sysfatal("getpts: %r\n");
|
||||||
|
|
||||||
switch(pid = fork()) {
|
switch(pid = fork()) {
|
||||||
case 0:
|
case 0:
|
||||||
putenv("TERM", "9term");
|
putenv("TERM", "9term");
|
||||||
|
|
@ -44,7 +36,9 @@ rcstart(int argc, char **argv, int *pfd, int *tfd)
|
||||||
dup(sfd, 0);
|
dup(sfd, 0);
|
||||||
dup(sfd, 1);
|
dup(sfd, 1);
|
||||||
dup(sfd, 2);
|
dup(sfd, 2);
|
||||||
system("stty tabs -onlcr -echo erase '^h' intr '^?'");
|
system("stty tabs -onlcr onocr icanon echo erase '^h' intr '^?'");
|
||||||
|
for(i=3; i<100; i++)
|
||||||
|
close(i);
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
fprint(2, "exec %s failed: %r\n", argv[0]);
|
fprint(2, "exec %s failed: %r\n", argv[0]);
|
||||||
_exits("oops");
|
_exits("oops");
|
||||||
|
|
@ -54,10 +48,11 @@ rcstart(int argc, char **argv, int *pfd, int *tfd)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*pfd = fd[1];
|
*pfd = fd[1];
|
||||||
if(tfd)
|
close(fd[0]);
|
||||||
*tfd = fd[0];
|
if(tfd){
|
||||||
else
|
if((*tfd = open(slave, OREAD)) < 0)
|
||||||
close(fd[0]);
|
sysfatal("parent open %s: %r", slave);
|
||||||
|
}
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,5 @@ extern int childpty(int[], char*);
|
||||||
extern void updatewinsize(int, int, int, int);
|
extern void updatewinsize(int, int, int, int);
|
||||||
extern int rcfd;
|
extern int rcfd;
|
||||||
extern int rcstart(int, char*[], int*, int*);
|
extern int rcstart(int, char*[], int*, int*);
|
||||||
extern int israw(int);
|
extern int isecho(int);
|
||||||
extern int setecho(int, int);
|
extern int setecho(int, int);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue