Class Attributes
- java.lang.Object
-
- org.jline.terminal.Attributes
-
public class Attributes extends java.lang.ObjectEncapsulates terminal attributes and settings that control terminal behavior.The Attributes class represents the terminal settings similar to the POSIX termios structure, providing control over terminal input/output behavior, control characters, and various flags. These attributes determine how the terminal processes input and output, handles special characters, and behaves in response to various conditions.
Terminal attributes are organized into several categories:
- Input Flags - Control input processing (e.g., character mapping, parity checking)
- Output Flags - Control output processing (e.g., newline translation)
- Control Flags - Control hardware settings (e.g., baud rate, character size)
- Local Flags - Control various terminal behaviors (e.g., echo, canonical mode)
- Control Characters - Define special characters (e.g., EOF, interrupt, erase)
Attributes objects are typically obtained from a
TerminalusingTerminal.getAttributes(), modified as needed, and then applied back to the terminal usingTerminal.setAttributes(Attributes).Example usage:
Terminal terminal = TerminalBuilder.terminal(); // Get current attributes Attributes attrs = terminal.getAttributes(); // Modify attributes attrs.setLocalFlag(LocalFlag.ECHO, false); // Disable echo attrs.setInputFlag(InputFlag.ICRNL, false); // Disable CR to NL mapping attrs.setControlChar(ControlChar.VMIN, 1); // Set minimum input to 1 character // Apply modified attributes terminal.setAttributes(attrs);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAttributes.ControlCharControl characters used for special terminal functions.static classAttributes.ControlFlagControl flags that manage hardware aspects of the terminal.static classAttributes.InputFlagInput flags that control how terminal input is processed.static classAttributes.LocalFlagLocal flags that control various terminal behaviors.static classAttributes.OutputFlagOutput flags that control how terminal output is processed.
-
Constructor Summary
Constructors Constructor Description Attributes()Creates a new Attributes instance with default settings.Attributes(Attributes attr)Creates a new Attributes instance by copying another Attributes object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcopy(Attributes attributes)Copies all settings from another Attributes object to this one.intgetControlChar(Attributes.ControlChar c)Returns the value of a specific control character.java.util.EnumMap<Attributes.ControlChar,java.lang.Integer>getControlChars()Returns the map of control characters and their values.booleangetControlFlag(Attributes.ControlFlag flag)java.util.EnumSet<Attributes.ControlFlag>getControlFlags()booleangetInputFlag(Attributes.InputFlag flag)Checks if a specific input flag is enabled.java.util.EnumSet<Attributes.InputFlag>getInputFlags()Returns the set of input flags currently enabled.booleangetLocalFlag(Attributes.LocalFlag flag)java.util.EnumSet<Attributes.LocalFlag>getLocalFlags()booleangetOutputFlag(Attributes.OutputFlag flag)java.util.EnumSet<Attributes.OutputFlag>getOutputFlags()voidsetControlChar(Attributes.ControlChar c, int value)Sets a specific control character to the specified value.voidsetControlChars(java.util.EnumMap<Attributes.ControlChar,java.lang.Integer> chars)Sets the control characters to the specified map of values.voidsetControlFlag(Attributes.ControlFlag flag, boolean value)voidsetControlFlags(java.util.EnumSet<Attributes.ControlFlag> flags)voidsetControlFlags(java.util.EnumSet<Attributes.ControlFlag> flags, boolean value)voidsetInputFlag(Attributes.InputFlag flag, boolean value)Sets a specific input flag to the specified value.voidsetInputFlags(java.util.EnumSet<Attributes.InputFlag> flags)Sets the input flags to the specified set of flags.voidsetInputFlags(java.util.EnumSet<Attributes.InputFlag> flags, boolean value)Sets multiple input flags to the same value.voidsetLocalFlag(Attributes.LocalFlag flag, boolean value)voidsetLocalFlags(java.util.EnumSet<Attributes.LocalFlag> flags)voidsetLocalFlags(java.util.EnumSet<Attributes.LocalFlag> flags, boolean value)voidsetOutputFlag(Attributes.OutputFlag flag, boolean value)voidsetOutputFlags(java.util.EnumSet<Attributes.OutputFlag> flags)voidsetOutputFlags(java.util.EnumSet<Attributes.OutputFlag> flags, boolean value)java.lang.StringtoString()
-
-
-
Constructor Detail
-
Attributes
public Attributes()
Creates a new Attributes instance with default settings.This constructor creates an Attributes object with all flags unset and all control characters undefined. The attributes can be modified using the various setter methods.
-
Attributes
public Attributes(Attributes attr)
Creates a new Attributes instance by copying another Attributes object.This constructor creates a new Attributes object with the same settings as the specified Attributes object. All flags and control characters are copied from the source object.
- Parameters:
attr- the Attributes object to copy- See Also:
copy(Attributes)
-
-
Method Detail
-
getInputFlags
public java.util.EnumSet<Attributes.InputFlag> getInputFlags()
Returns the set of input flags currently enabled.This method returns a reference to the internal set of input flags. Changes to the returned set will directly affect this Attributes object.
- Returns:
- the set of enabled input flags
- See Also:
Attributes.InputFlag,setInputFlags(EnumSet)
-
setInputFlags
public void setInputFlags(java.util.EnumSet<Attributes.InputFlag> flags)
Sets the input flags to the specified set of flags.This method replaces all current input flags with the specified set. Any previously enabled flags not in the new set will be disabled.
- Parameters:
flags- the set of input flags to enable- See Also:
Attributes.InputFlag,getInputFlags()
-
getInputFlag
public boolean getInputFlag(Attributes.InputFlag flag)
Checks if a specific input flag is enabled.This method returns whether the specified input flag is currently enabled in this Attributes object.
- Parameters:
flag- the input flag to check- Returns:
trueif the flag is enabled,falseotherwise- See Also:
Attributes.InputFlag,setInputFlag(InputFlag, boolean)
-
setInputFlags
public void setInputFlags(java.util.EnumSet<Attributes.InputFlag> flags, boolean value)
Sets multiple input flags to the same value.This method enables or disables all the specified input flags based on the value parameter. If value is true, all flags in the set will be enabled. If value is false, all flags in the set will be disabled.
- Parameters:
flags- the set of input flags to modifyvalue-trueto enable the flags,falseto disable them- See Also:
Attributes.InputFlag,setInputFlag(InputFlag, boolean)
-
setInputFlag
public void setInputFlag(Attributes.InputFlag flag, boolean value)
Sets a specific input flag to the specified value.This method enables or disables a single input flag based on the value parameter. If value is true, the flag will be enabled. If value is false, the flag will be disabled.
- Parameters:
flag- the input flag to modifyvalue-trueto enable the flag,falseto disable it- See Also:
Attributes.InputFlag,getInputFlag(InputFlag)
-
getOutputFlags
public java.util.EnumSet<Attributes.OutputFlag> getOutputFlags()
-
setOutputFlags
public void setOutputFlags(java.util.EnumSet<Attributes.OutputFlag> flags)
-
getOutputFlag
public boolean getOutputFlag(Attributes.OutputFlag flag)
-
setOutputFlags
public void setOutputFlags(java.util.EnumSet<Attributes.OutputFlag> flags, boolean value)
-
setOutputFlag
public void setOutputFlag(Attributes.OutputFlag flag, boolean value)
-
getControlFlags
public java.util.EnumSet<Attributes.ControlFlag> getControlFlags()
-
setControlFlags
public void setControlFlags(java.util.EnumSet<Attributes.ControlFlag> flags)
-
getControlFlag
public boolean getControlFlag(Attributes.ControlFlag flag)
-
setControlFlags
public void setControlFlags(java.util.EnumSet<Attributes.ControlFlag> flags, boolean value)
-
setControlFlag
public void setControlFlag(Attributes.ControlFlag flag, boolean value)
-
getLocalFlags
public java.util.EnumSet<Attributes.LocalFlag> getLocalFlags()
-
setLocalFlags
public void setLocalFlags(java.util.EnumSet<Attributes.LocalFlag> flags)
-
getLocalFlag
public boolean getLocalFlag(Attributes.LocalFlag flag)
-
setLocalFlags
public void setLocalFlags(java.util.EnumSet<Attributes.LocalFlag> flags, boolean value)
-
setLocalFlag
public void setLocalFlag(Attributes.LocalFlag flag, boolean value)
-
getControlChars
public java.util.EnumMap<Attributes.ControlChar,java.lang.Integer> getControlChars()
Returns the map of control characters and their values.This method returns a reference to the internal map of control characters. Changes to the returned map will directly affect this Attributes object.
- Returns:
- the map of control characters to their values
- See Also:
Attributes.ControlChar,setControlChars(EnumMap)
-
setControlChars
public void setControlChars(java.util.EnumMap<Attributes.ControlChar,java.lang.Integer> chars)
Sets the control characters to the specified map of values.This method replaces all current control character settings with the specified map. Any previously set control characters not in the new map will be unset.
- Parameters:
chars- the map of control characters to their values- See Also:
Attributes.ControlChar,getControlChars()
-
getControlChar
public int getControlChar(Attributes.ControlChar c)
Returns the value of a specific control character.This method returns the current value of the specified control character, or -1 if the control character is not defined.
For most control characters, the value represents the ASCII code of the character. For
Attributes.ControlChar.VMINandAttributes.ControlChar.VTIME, the values have special meanings related to non-canonical input mode.- Parameters:
c- the control character to retrieve- Returns:
- the value of the control character, or -1 if not defined
- See Also:
Attributes.ControlChar,setControlChar(ControlChar, int)
-
setControlChar
public void setControlChar(Attributes.ControlChar c, int value)
Sets a specific control character to the specified value.This method sets the value of the specified control character.
For most control characters, the value should be the ASCII code of the character. For
Attributes.ControlChar.VMINandAttributes.ControlChar.VTIME, the values have special meanings:- VMIN - Minimum number of characters for non-canonical read
- VTIME - Timeout in deciseconds for non-canonical read
- Parameters:
c- the control character to setvalue- the value to set for the control character- See Also:
Attributes.ControlChar,getControlChar(ControlChar)
-
copy
public void copy(Attributes attributes)
Copies all settings from another Attributes object to this one.This method copies all flags and control characters from the specified Attributes object to this object. Any previous settings in this object will be overwritten.
- Parameters:
attributes- the Attributes object to copy from
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-