Class Attributes
- java.lang.Object
-
- org.jline.terminal.Attributes
-
public class Attributes extends java.lang.Object
Encapsulates 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
Terminal
usingTerminal.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 class
Attributes.ControlChar
Control characters used for special terminal functions.static class
Attributes.ControlFlag
Control flags that manage hardware aspects of the terminal.static class
Attributes.InputFlag
Input flags that control how terminal input is processed.static class
Attributes.LocalFlag
Local flags that control various terminal behaviors.static class
Attributes.OutputFlag
Output 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 void
copy(Attributes attributes)
Copies all settings from another Attributes object to this one.int
getControlChar(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.boolean
getControlFlag(Attributes.ControlFlag flag)
java.util.EnumSet<Attributes.ControlFlag>
getControlFlags()
boolean
getInputFlag(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.boolean
getLocalFlag(Attributes.LocalFlag flag)
java.util.EnumSet<Attributes.LocalFlag>
getLocalFlags()
boolean
getOutputFlag(Attributes.OutputFlag flag)
java.util.EnumSet<Attributes.OutputFlag>
getOutputFlags()
void
setControlChar(Attributes.ControlChar c, int value)
Sets a specific control character to the specified value.void
setControlChars(java.util.EnumMap<Attributes.ControlChar,java.lang.Integer> chars)
Sets the control characters to the specified map of values.void
setControlFlag(Attributes.ControlFlag flag, boolean value)
void
setControlFlags(java.util.EnumSet<Attributes.ControlFlag> flags)
void
setControlFlags(java.util.EnumSet<Attributes.ControlFlag> flags, boolean value)
void
setInputFlag(Attributes.InputFlag flag, boolean value)
Sets a specific input flag to the specified value.void
setInputFlags(java.util.EnumSet<Attributes.InputFlag> flags)
Sets the input flags to the specified set of flags.void
setInputFlags(java.util.EnumSet<Attributes.InputFlag> flags, boolean value)
Sets multiple input flags to the same value.void
setLocalFlag(Attributes.LocalFlag flag, boolean value)
void
setLocalFlags(java.util.EnumSet<Attributes.LocalFlag> flags)
void
setLocalFlags(java.util.EnumSet<Attributes.LocalFlag> flags, boolean value)
void
setOutputFlag(Attributes.OutputFlag flag, boolean value)
void
setOutputFlags(java.util.EnumSet<Attributes.OutputFlag> flags)
void
setOutputFlags(java.util.EnumSet<Attributes.OutputFlag> flags, boolean value)
java.lang.String
toString()
-
-
-
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:
true
if the flag is enabled,false
otherwise- 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
-true
to enable the flags,false
to 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
-true
to enable the flag,false
to 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.VMIN
andAttributes.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.VMIN
andAttributes.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:
toString
in classjava.lang.Object
-
-