Class Attributes
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
using Terminal.getAttributes()
,
modified as needed, and then applied back to the terminal using Terminal.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);
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Control characters used for special terminal functions.static enum
Control flags that manage hardware aspects of the terminal.static enum
Input flags that control how terminal input is processed.static enum
Local flags that control various terminal behaviors.static enum
Output flags that control how terminal output is processed. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Attributes instance with default settings.Attributes
(Attributes attr) Creates a new Attributes instance by copying another Attributes object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
copy
(Attributes attributes) Copies all settings from another Attributes object to this one.int
Returns the value of a specific control character.Returns the map of control characters and their values.boolean
boolean
Checks if a specific input flag is enabled.Returns the set of input flags currently enabled.boolean
boolean
void
setControlChar
(Attributes.ControlChar c, int value) Sets a specific control character to the specified value.void
Sets the control characters to the specified map of values.void
setControlFlag
(Attributes.ControlFlag flag, boolean value) void
void
setControlFlags
(EnumSet<Attributes.ControlFlag> flags, boolean value) void
setInputFlag
(Attributes.InputFlag flag, boolean value) Sets a specific input flag to the specified value.void
setInputFlags
(EnumSet<Attributes.InputFlag> flags) Sets the input flags to the specified set of flags.void
setInputFlags
(EnumSet<Attributes.InputFlag> flags, boolean value) Sets multiple input flags to the same value.void
setLocalFlag
(Attributes.LocalFlag flag, boolean value) void
setLocalFlags
(EnumSet<Attributes.LocalFlag> flags) void
setLocalFlags
(EnumSet<Attributes.LocalFlag> flags, boolean value) void
setOutputFlag
(Attributes.OutputFlag flag, boolean value) void
void
setOutputFlags
(EnumSet<Attributes.OutputFlag> flags, boolean value) toString()
-
Constructor Details
-
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
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:
-
-
Method Details
-
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:
-
setInputFlags
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:
-
getInputFlag
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:
-
setInputFlags
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:
-
setInputFlag
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:
-
getOutputFlags
-
setOutputFlags
-
getOutputFlag
-
setOutputFlags
-
setOutputFlag
-
getControlFlags
-
setControlFlags
-
getControlFlag
-
setControlFlags
-
setControlFlag
-
getLocalFlags
-
setLocalFlags
-
getLocalFlag
-
setLocalFlags
-
setLocalFlag
-
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:
-
setControlChars
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:
-
getControlChar
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:
-
setControlChar
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:
-
copy
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
-