Cross-Platform Methods to Enumerate Supported Terminal Types Across UNIX Systems with Solaris Focus


2 views

When working with terminal applications across UNIX variants, knowing available terminal types is crucial for proper TTY configuration and application compatibility. The challenge lies in the lack of a standardized method across different UNIX implementations.

For maximum portability, consider these methods:

# Method 1: Using terminfo database
find /usr/share/terminfo /lib/terminfo -type f | cut -d/ -f4- | sed 's/\//\//g'

# Method 2: Using infocmp (available on most systems)
infocmp -D | xargs -n1 basename

While not perfect, these commands work on most Linux distributions and BSD variants. The terminfo approach is generally more reliable but may miss some custom entries.

On Solaris systems, you'll need to account for its unique terminfo organization:

# Solaris method 1: Using /usr/share/lib/terminfo
find /usr/share/lib/terminfo -type f | awk -F/ '{print $NF}' | sort -u

# Solaris method 2: Using toe command (Solaris 10+)
toe -a | awk '{print $1}'

The toe command provides the most comprehensive list and should be preferred on modern Solaris installations.

For cross-platform scripts, implement a fallback chain:

#!/bin/sh

list_terminals() {
    # Try toe first (Solaris)
    if command -v toe >/dev/null 2>&1; then
        toe -a | awk '{print $1}'
        return $?
    fi
    
    # Fall back to terminfo search
    for dir in /usr/share/terminfo /usr/share/lib/terminfo /lib/terminfo; do
        if [ -d "$dir" ]; then
            find "$dir" -type f | awk -F/ '{print $NF}' | sort -u
            return $?
        fi
    done
    
    # Last resort: try infocmp
    if command -v infocmp >/dev/null 2>&1; then
        infocmp -D | xargs -n1 basename
        return $?
    fi
    
    echo "No terminal enumeration method found" >&2
    return 1
}

For frequent calls in production environments, consider caching:

TERMINAL_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/terminal_types.cache"
[ ! -f "$TERMINAL_CACHE" ] && list_terminals > "$TERMINAL_CACHE"

Terminal types (often referred to as TERM values) are crucial for proper terminal emulation and application behavior. Each terminal type defines specific capabilities and escape sequences that applications can use.

While there's no completely portable way across all Unix-like systems, these methods work on most:


# Method 1: Check terminfo database
ls -1 /usr/share/terminfo/?/*
ls -1 /usr/lib/terminfo/?/*

# Method 2: Use infocmp with wildcards (if available)
infocmp -1 | sort | uniq

On Solaris systems, terminal information is typically stored in these locations:


# Solaris 10 and earlier
/usr/share/lib/terminfo/?/*

# Solaris 11 and later
/usr/gnu/share/terminfo/?/*

For a comprehensive list, you can use:


find /usr/share/lib/terminfo /usr/gnu/share/terminfo -type f -print | \
    awk -F/ '{print $NF}' | sort | uniq

Here's a script that lists available terminal types while excluding less common ones:


#!/bin/sh

# Solaris-compatible terminal type lister
for termdb in /usr/share/lib/terminfo /usr/gnu/share/terminfo; do
    if [ -d "$termdb" ]; then
        find "$termdb" -type f -print | \
        awk -F/ '{
            split($NF, parts, ".");
            print parts[1]
        }' | \
        grep -E 'xterm|vt[0-9]+|ansi|sun|screen|linux|cygwin|rxvt'
    fi
done | sort | uniq

Once you have terminal types, you can check their capabilities:


# Example: Check if terminal supports color
tput colors >/dev/null 2>&1 && echo "Color supported" || echo "No color support"

# Check specific capabilities
infocmp $TERM | grep -E 'colors|cup'

If you encounter missing terminal definitions, you can:


# 1. Use a similar terminal type
export TERM=vt100

# 2. Compile a custom entry
tic /path/to/terminal.src