Get the FREE Ultimate OpenClaw Setup Guide →

terminal-capability-detector

npx machina-cli add skill a5c-ai/babysitter/terminal-capability-detector --openclaw
Files (1)
SKILL.md
1.6 KB

Terminal Capability Detector

Detect terminal capabilities for adaptive CLI output.

Capabilities

  • Detect color support levels
  • Check TTY status
  • Get terminal dimensions
  • Detect Unicode support
  • Check for CI environment
  • Configure adaptive output

Generated Patterns

import process from 'process';
import tty from 'tty';

export interface TerminalCapabilities {
  isTTY: boolean;
  colorLevel: 0 | 1 | 2 | 3;
  supportsUnicode: boolean;
  columns: number;
  rows: number;
  isCI: boolean;
}

export function detectCapabilities(): TerminalCapabilities {
  const isTTY = tty.isatty(1);
  const isCI = Boolean(process.env.CI || process.env.CONTINUOUS_INTEGRATION);

  let colorLevel: 0 | 1 | 2 | 3 = 0;
  if (isTTY && !process.env.NO_COLOR) {
    if (process.env.COLORTERM === 'truecolor') colorLevel = 3;
    else if (process.env.TERM?.includes('256color')) colorLevel = 2;
    else if (process.env.TERM && process.env.TERM !== 'dumb') colorLevel = 1;
  }

  const supportsUnicode = process.platform !== 'win32' ||
    process.env.WT_SESSION ||
    process.env.TERM_PROGRAM === 'vscode';

  return {
    isTTY,
    colorLevel,
    supportsUnicode,
    columns: process.stdout.columns || 80,
    rows: process.stdout.rows || 24,
    isCI,
  };
}

Target Processes

  • cross-platform-cli-compatibility
  • cli-output-formatting
  • progress-status-indicators

Source

git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/cli-mcp-development/skills/terminal-capability-detector/SKILL.mdView on GitHub

Overview

This skill detects terminal capabilities to drive adaptive CLI output. It exposes a detectCapabilities() function that returns isTTY, colorLevel, supportsUnicode, columns, rows, and isCI, enabling responsive formatting.

How This Skill Works

It uses Node's process and tty APIs to determine if stdout is a TTY and reads environment variables (NO_COLOR, COLORTERM, TERM) to set colorLevel. It also infers Unicode support on Windows via WT_SESSION or VSCode terminals, and reads terminal dimensions from process.stdout.columns and process.stdout.rows, with sensible fallbacks. A CI environment is detected via CI or CONTINUOUS_INTEGRATION variables.

When to Use It

  • Build a colorized CLI that adapts to terminal capabilities
  • Detect and adapt behavior when running in CI environments
  • Adjust output layout based on terminal size (columns/rows)
  • Enable Unicode glyphs for richer UI on capable terminals
  • Ensure consistent behavior across Windows and Unix-like shells

Quick Start

  1. Step 1: import detectCapabilities from the skill module
  2. Step 2: const cap = detectCapabilities();
  3. Step 3: use cap.isTTY, cap.colorLevel, cap.columns, cap.rows, cap.supportsUnicode, and cap.isCI to drive output

Best Practices

  • Check isTTY before enabling color output to avoid spoilers in non-interactive shells
  • Honor NO_COLOR and avoid forcing color in CI environments
  • Fallback to 80x24 when terminal size is unavailable
  • Respect TERM hints (256color, truecolor) to maximize color depth when possible
  • Gracefully degrade Unicode usage on terminals that do not support it

Example Use Cases

  • Dynamic progress bars and colored status messages that adapt to colorLevel
  • Unicode-based UI elements (icons, symbols) on capable terminals
  • Responsive layouts that reflow content based on columns
  • Silent operation in CI by disabling interactive features
  • Cross-platform output with appropriate fallbacks for Windows and Unix shells

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers