Class DeviceAttributes

java.lang.Object
org.aesh.terminal.DeviceAttributes

public class DeviceAttributes extends Object
Represents device attributes queried from a terminal via DA1/DA2 sequences.

Device attributes provide information about terminal capabilities that cannot be determined from terminfo alone. This includes:

  • Terminal type and conformance level (VT100, VT220, xterm, etc.)
  • Supported features (sixel graphics, mouse, rectangular editing)
  • Firmware/version information

Use TerminalFeatures.queryDeviceAttributes(long) to obtain an instance of this class.

Author:
Ståle Pedersen
  • Constructor Details

    • DeviceAttributes

      public DeviceAttributes(int deviceClass, Set<Integer> parameters)
      Create DeviceAttributes from DA1 response data.
      Parameters:
      deviceClass - the device class (conformance level)
      parameters - the feature parameter codes from DA1 response
    • DeviceAttributes

      public DeviceAttributes(int deviceClass, Set<Integer> parameters, DeviceAttributes.TerminalType terminalType, int firmwareVersion, int romCartridge)
      Create DeviceAttributes from both DA1 and DA2 response data.
      Parameters:
      deviceClass - the device class from DA1
      parameters - the feature parameters from DA1
      terminalType - the terminal type from DA2
      firmwareVersion - the firmware version from DA2
      romCartridge - the ROM cartridge registration from DA2
  • Method Details

    • getDeviceClass

      public int getDeviceClass()
      Get the device class / conformance level.

      Common values:

      • 1 or 2: VT100
      • 62: VT220
      • 63: VT320
      • 64: VT420
      Returns:
      the device class, or -1 if not available
    • getFeatures

      public Set<DeviceAttributes.Feature> getFeatures()
      Get the set of features reported by the terminal.
      Returns:
      unmodifiable set of features
    • getRawParameters

      public Set<Integer> getRawParameters()
      Get the raw parameter codes from DA1 response.

      This includes both recognized and unrecognized parameters.

      Returns:
      unmodifiable set of parameter codes
    • getTerminalType

      public DeviceAttributes.TerminalType getTerminalType()
      Get the terminal type from DA2 response.
      Returns:
      the terminal type
    • getFirmwareVersion

      public int getFirmwareVersion()
      Get the firmware version from DA2 response.
      Returns:
      the firmware version, or -1 if not available
    • getRomCartridge

      public int getRomCartridge()
      Get the ROM cartridge registration number from DA2.
      Returns:
      the ROM cartridge number, or -1 if not available
    • hasFeature

      public boolean hasFeature(DeviceAttributes.Feature feature)
      Check if the terminal supports a specific feature.
      Parameters:
      feature - the feature to check
      Returns:
      true if the feature is supported
    • supportsSixel

      public boolean supportsSixel()
      Check if the terminal supports Sixel graphics.
      Returns:
      true if Sixel is supported
    • supportsAnsiColor

      public boolean supportsAnsiColor()
      Check if the terminal supports ANSI colors.
      Returns:
      true if ANSI color is supported
    • supportsMouse

      public boolean supportsMouse()
      Check if the terminal supports mouse/locator.

      This checks for DEC locator (Ps=16) or ANSI text locator (Ps=29).

      Returns:
      true if mouse/locator is supported
    • supportsRectangularEditing

      public boolean supportsRectangularEditing()
      Check if the terminal supports rectangular editing operations.
      Returns:
      true if rectangular editing is supported
    • supports132Columns

      public boolean supports132Columns()
      Check if the terminal supports 132-column mode.
      Returns:
      true if 132-column mode is supported
    • hasDA1

      public boolean hasDA1()
      Check if DA1 data is available.
      Returns:
      true if DA1 was successfully queried
    • hasDA2

      public boolean hasDA2()
      Check if DA2 data is available.
      Returns:
      true if DA2 was successfully queried
    • likelySupportsOscQueries

      public boolean likelySupportsOscQueries()
      Check if the terminal likely supports OSC (Operating System Command) queries.

      This is inferred from DA1 capabilities. Terminals that report modern features like ANSI color or Sixel graphics typically also support OSC queries for color detection (OSC 10/11), clipboard (OSC 52), etc.

      Note: This is an inference, not a guarantee. Some terminals may report these features but not support all OSC commands.

      Returns:
      true if OSC queries are likely supported based on DA1 features
    • merge

      public DeviceAttributes merge(DeviceAttributes other)
      Merge this DeviceAttributes with another, combining data from both.

      This is useful when DA1 and DA2 are queried separately.

      Parameters:
      other - the other DeviceAttributes to merge with
      Returns:
      a new DeviceAttributes with combined data
    • inferTerminalType

      public Device.TerminalType inferTerminalType()
      Infer the terminal type from DA1/DA2 attributes.

      This method attempts to determine which Device.TerminalType best matches the features and capabilities reported by the terminal.

      Use this in combination with environment-based detection for more accurate terminal identification:

       Device.TerminalType envType = device.detectTerminalType();
       DeviceAttributes attrs = connection.queryDeviceAttributes(500);
       Device.TerminalType daType = attrs.inferTerminalType();
      
       // envType is usually more specific, but daType confirms capabilities
       
      Returns:
      the inferred terminal type, or UNKNOWN if not determinable
    • inferColorDepth

      public ColorDepth inferColorDepth()
      Infer the color depth from DA1 features.

      This provides an authoritative color depth based on what the terminal actually reports, rather than environment-based heuristics.

      Returns:
      the inferred color depth
    • matchesTerminalType

      public boolean matchesTerminalType(Device.TerminalType expectedType)
      Validate that this terminal's attributes match the expected features for a given terminal type.

      This can be used to verify that environment-detected terminal type matches the actual terminal capabilities.

      Parameters:
      expectedType - the terminal type detected from environment
      Returns:
      true if the attributes are consistent with the expected type
    • getCapabilitySummary

      public String getCapabilitySummary(Device.TerminalType envType)
      Get enhanced terminal capabilities by combining DA1/DA2 data with environment-detected terminal type.

      This method returns a summary of capabilities using both sources of information for the most accurate detection.

      Parameters:
      envType - the terminal type detected from environment variables
      Returns:
      a capabilities summary string
    • toString

      public String toString()
      Overrides:
      toString in class Object