Class Attributes

java.lang.Object
org.jline.terminal.Attributes

public class Attributes extends 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 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:
  • 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

      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:
  • Method Details

    • getInputFlags

      public 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:
    • setInputFlags

      public void setInputFlags(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:
    • 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:
    • setInputFlags

      public void setInputFlags(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 modify
      value - true to enable the flags, false to disable them
      See Also:
    • 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 modify
      value - true to enable the flag, false to disable it
      See Also:
    • getOutputFlags

      public EnumSet<Attributes.OutputFlag> getOutputFlags()
    • setOutputFlags

      public void setOutputFlags(EnumSet<Attributes.OutputFlag> flags)
    • getOutputFlag

      public boolean getOutputFlag(Attributes.OutputFlag flag)
    • setOutputFlags

      public void setOutputFlags(EnumSet<Attributes.OutputFlag> flags, boolean value)
    • setOutputFlag

      public void setOutputFlag(Attributes.OutputFlag flag, boolean value)
    • getControlFlags

      public EnumSet<Attributes.ControlFlag> getControlFlags()
    • setControlFlags

      public void setControlFlags(EnumSet<Attributes.ControlFlag> flags)
    • getControlFlag

      public boolean getControlFlag(Attributes.ControlFlag flag)
    • setControlFlags

      public void setControlFlags(EnumSet<Attributes.ControlFlag> flags, boolean value)
    • setControlFlag

      public void setControlFlag(Attributes.ControlFlag flag, boolean value)
    • getLocalFlags

      public EnumSet<Attributes.LocalFlag> getLocalFlags()
    • setLocalFlags

      public void setLocalFlags(EnumSet<Attributes.LocalFlag> flags)
    • getLocalFlag

      public boolean getLocalFlag(Attributes.LocalFlag flag)
    • setLocalFlags

      public void setLocalFlags(EnumSet<Attributes.LocalFlag> flags, boolean value)
    • setLocalFlag

      public void setLocalFlag(Attributes.LocalFlag flag, boolean value)
    • getControlChars

      public EnumMap<Attributes.ControlChar,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:
    • setControlChars

      public void setControlChars(EnumMap<Attributes.ControlChar,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:
    • 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 and Attributes.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

      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 and Attributes.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 set
      value - the value to set for the control character
      See Also:
    • 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 String toString()
      Overrides:
      toString in class Object