    static struct termios told;
	   struct termios tnew;

	mch_tcgetattr(read_cmd_fd, &told);

    tnew = told;
    if (tmode == TMODE_RAW)
    {
	tnew.c_iflag &= ~(ICRNL | (T_XON == NULL || *T_XON == NUL ? IXON : 0));
	tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE | IEXTEN);
	//
	tnew.c_oflag &= ~(ONLCR | XTABS);
	
	tnew.c_oflag &= ~(ONLCR | TAB3);
	
	tnew.c_oflag &= ~ONLCR;
	//
	
	tnew.c_cc[VMIN] = 1;		// return after 1 char
	tnew.c_cc[VTIME] = 0;		// don't wait
    }
    else if (tmode == TMODE_SLEEP)
    {
	tnew.c_lflag &= ~(ICANON | ECHO);
	tnew.c_cc[VMIN] = 1;		// return after 1 char
	tnew.c_cc[VTIME] = 0;		// don't wait
    }

    {
	int	n = 10;

	// A signal may cause tcsetattr() to fail (e.g., SIGCONT).  Retry a
	// few times.
	while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1
						   && errno == EINTR && n > 0)
	    --n;
    }
