Ejemplo n.º 1
0
            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_MacOS.tcgetattr(_fd, out termios_MacOS 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}'");
                if (echo)
                {
                    t.c_lflag |= LocalFlags.ECHO;
                }
                else
                {
                    t.c_lflag &= ~LocalFlags.ECHO;
                }

                if ((error = Termios_MacOS.tcsetattr(_fd, SetActionFlags.TCSAFLUSH, ref t)) != 0)
                {
                    throw new InteropException("Failed to set terminal settings", error);
                }
            }