Beispiel #1
0
        bool SetupTTY(int stdin)
        {
            // Ensure that we are using a real terminal,
            // rather than some short of file redirection.thing.
            if (!Terminal.IsTerminal(stdin))
            {
                Debug.Print("[Linux] Terminal.IsTerminal({0}) returned false.", stdin);
                return(false);
            }

            //original_stdin = Libc.dup(stdin);

            int ret = Terminal.GetAttributes(stdin, out original_state);

            if (ret < 0)
            {
                Debug.Print("[Linux] Terminal.GetAttributes({0}) failed. Error: {1}",
                            stdin, ret);
                return(false);
            }

            // Retrieve current keyboard mode
            ret = Libc.ioctl(stdin, KeyboardIoctlCode.GetMode, ref original_mode);
            if (ret != 0)
            {
                Debug.Print("[Linux] Libc.ioctl({0}, KeyboardIoctlCode.GetMode) failed. Error: {1}",
                            stdin, ret);
                return(false);
            }

            // Update terminal state
            current_state            = original_state;
            current_state.LocalMode &= ~(/*LocalFlags.ECHO |*/ LocalFlags.ICANON | LocalFlags.ISIG);
            current_state.InputMode &= ~(
                InputFlags.ISTRIP | InputFlags.IGNCR | InputFlags.ICRNL |
                InputFlags.INLCR | InputFlags.IXOFF | InputFlags.IXON);
            current_state.ControlCharacters.VMIN  = 0;
            current_state.ControlCharacters.VTIME = 0;
            Terminal.SetAttributes(stdin, OptionalActions.FLUSH, ref current_state);

            // Request keycodes
            int mode = 0x02; // K_MEDIUMRAW

            ret = Libc.ioctl(stdin, KeyboardIoctlCode.SetMode, mode);
            if (ret != 0)
            {
                Debug.Print("[Linux] Libc.ioctl({0}, KeyboardIoctlCode.SetMode, {1}) failed. Error: {2}",
                            stdin, mode, ret);
                ExitTTY(this, EventArgs.Empty);
                return(false);
            }

            // Ensure we reset the original keyboard/terminal state on exit,
            // even if we crash.
            HookEvents();

            return(true);
        }
        bool SetupTTY(int stdin)
        {
            // Ensure that we are using a real terminal,
            // rather than some short of file redirection.thing.
            if (!Terminal.IsTerminal(stdin))
            {
                Debug.Print("[Linux] Terminal.IsTerminal({0}) returned false.", stdin);
                return false;
            }

            //original_stdin = Libc.dup(stdin);

            int ret = Terminal.GetAttributes(stdin, out original_state);
            if (ret < 0)
            {
                Debug.Print("[Linux] Terminal.GetAttributes({0}) failed. Error: {1}",
                    stdin, ret);
                return false;
            }

            // Retrieve current keyboard mode
            ret = Libc.ioctl(stdin, KeyboardIoctlCode.GetMode, ref original_mode);
            if (ret != 0)
            {
                Debug.Print("[Linux] Libc.ioctl({0}, KeyboardIoctlCode.GetMode) failed. Error: {1}",
                    stdin, ret);
                return false;
            }

            // Update terminal state
            current_state = original_state;
            current_state.LocalMode &= ~(/*LocalFlags.ECHO |*/ LocalFlags.ICANON | LocalFlags.ISIG);
            current_state.InputMode &= ~(
                InputFlags.ISTRIP | InputFlags.IGNCR | InputFlags.ICRNL |
                InputFlags.INLCR | InputFlags.IXOFF | InputFlags.IXON);
            current_state.ControlCharacters.VMIN = 0;
            current_state.ControlCharacters.VTIME = 0;
            Terminal.SetAttributes(stdin, OptionalActions.FLUSH, ref current_state);

            // Request keycodes
            int mode = 0x02; // K_MEDIUMRAW
            ret = Libc.ioctl(stdin, KeyboardIoctlCode.SetMode, mode);
            if (ret != 0)
            {
                Debug.Print("[Linux] Libc.ioctl({0}, KeyboardIoctlCode.SetMode, {1}) failed. Error: {2}",
                    stdin, mode, ret);
                ExitTTY(this, EventArgs.Empty);
                return false;
            }

            // Ensure we reset the original keyboard/terminal state on exit,
            // even if we crash.
            HookEvents();

            return true;
        }
Beispiel #3
0
 public static extern int SetAttributes(int fd, OptionalActions actions, ref TerminalState state);
Beispiel #4
0
 public static extern int GetAttributes(int fd, out TerminalState state);
Beispiel #5
0
 public static extern int SetAttributes(int fd, OptionalActions actions, ref TerminalState state);
Beispiel #6
0
 public static extern int GetAttributes(int fd, out TerminalState state);