Class STTYModeSwitcher

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class STTYModeSwitcher
    extends java.lang.Object
    implements java.io.Closeable
    Switch terminal mode and make it return on close. Basic usage is: try (STTYModeSwitcher tty = new STTYModeSwitcher(STTYMode.RAW)) { // do stuff in raw mode. }
    • Constructor Detail

      • STTYModeSwitcher

        public STTYModeSwitcher​(STTYMode mode,
                                java.lang.Runtime runtime)
                         throws java.io.IOException
        Switch to the requested mode until closed.
        Parameters:
        mode - The mode to switch to.
        runtime - The runtime to execute stty commands on.
        Throws:
        java.io.IOException - If unable to switch.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Close the terminal mode switcher and turn back the the mode before it was opened.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException - If unable to switch back.
      • getMode

        public STTYMode getMode()
        Get the mode set by the seitcher.
        Returns:
        The tty mode.
      • getBefore

        public STTYMode getBefore()
        Get the mode that was replaced by the switcher.
        Returns:
        the tty mode.
      • getCurrentMode

        public STTYMode getCurrentMode()
        Get the current TTY mode.
        Returns:
        The tty mode.
      • didChangeMode

        public boolean didChangeMode()
        Returns:
        True if the mode switcher changed the tty mode.
      • currentMode

        public static STTYMode currentMode()
        Get the current TTY mode.
        Returns:
        The tty mode.
      • setSttyMode

        protected void setSttyMode​(STTYMode mode)
                            throws java.io.IOException
        Set terminal mode.
        Parameters:
        mode - The mode to set.
        Throws:
        java.io.IOException - If setting mode failed.