Class 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 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:
    Terminal.getAttributes(), Terminal.setAttributes(Attributes)
    • 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 modify
        value - 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 modify
        value - true to enable the flag, false to disable it
        See Also:
        Attributes.InputFlag, getInputFlag(InputFlag)
      • setOutputFlags

        public void setOutputFlags​(java.util.EnumSet<Attributes.OutputFlag> flags,
                                   boolean value)
      • setControlFlags

        public void setControlFlags​(java.util.EnumSet<Attributes.ControlFlag> flags,
                                    boolean value)
      • setLocalFlags

        public void setLocalFlags​(java.util.EnumSet<Attributes.LocalFlag> flags,
                                  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()
      • 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:
        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 class java.lang.Object