Package net.morimekta.console.util
Class STTYModeSwitcher
- java.lang.Object
-
- net.morimekta.console.util.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 Summary
Constructors Constructor Description STTYModeSwitcher(STTYMode mode, java.lang.Runtime runtime)
Switch to the requested mode until closed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the terminal mode switcher and turn back the the mode before it was opened.static STTYMode
currentMode()
Get the current TTY mode.boolean
didChangeMode()
STTYMode
getBefore()
Get the mode that was replaced by the switcher.STTYMode
getCurrentMode()
Get the current TTY mode.STTYMode
getMode()
Get the mode set by the seitcher.protected void
setSttyMode(STTYMode mode)
Set terminal 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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.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.
-
-