public TtyContext(ITrace trace, int fd, bool echo) { EnsureArgument.NotNull(trace, nameof(trace)); EnsureArgument.PositiveOrZero(fd, nameof(fd)); _trace = trace; _fd = fd; int error = 0; // Capture current terminal settings so we can restore them later if ((error = Termios.tcgetattr(_fd, out termios t)) != 0) { throw new InteropException("Failed to get initial terminal settings", error); } _originalTerm = t; // Set desired echo state _trace.WriteLine($"Setting terminal echo state to '{echo}'"); t.c_lflag &= echo ? LocalFlags.ECHO : ~LocalFlags.ECHO; if ((error = Termios.tcsetattr(_fd, SetActionFlags.TCSAFLUSH, ref t)) != 0) { throw new InteropException("Failed to set terminal settings", error); } }
public static int cfsetspeed(ref termios termios, uint speed) { termios.c_cflag &= ~CBAUD; termios.c_cflag |= BOTHER; termios.c_ispeed = speed; termios.c_ospeed = speed; return(0); }
public static void cfmakeraw(ref termios termios) { // See https://linux.die.net/man/3/cfmakeraw "Raw mode" heading. termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); termios.c_oflag &= ~OPOST; termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); termios.c_cflag &= ~(CSIZE | PARENB); termios.c_cflag |= CS8; }
public static extern int cfsetspeed(ref termios termios, UIntPtr speed);
public static extern void cfmakeraw(ref termios termios);
static extern int tcgetattr(int fd, out termios termios_p);
public static extern int tcsetattr(int fd, int optionsActoins, ref termios t);
public static int tcsetattr(int filedes, int actions, ref termios termios) { Debug.Assert(actions == TCSANOW); return(ioctl(filedes, TCSETS2, ref termios)); }
public static int tcgetattr(int filedes, out termios termios) { termios = new termios(); return(ioctl(filedes, TCGETS2, ref termios)); }
private void memset(ref termios term, int p, int p_2) { throw new System.NotImplementedException(); }
public static extern int ioctl(int filedes, UIntPtr command, ref termios value);
private void tcsetattr(int input,int _T_FLUSH,ref termios term) { throw new System.NotImplementedException(); }
private void memset(ref termios term,int p,int p_2) { throw new System.NotImplementedException(); }
private int tcgetattr(int input, ref termios oterm) { throw new System.NotImplementedException(); }
private void tcsetattr(int input, int _T_FLUSH, ref termios term) { throw new System.NotImplementedException(); }
public static extern int tcgetattr(int filedes, out termios termios);
public static extern int tcsetattr(int filedes, int actions, ref termios termios);