sequin

repository·main·Indexed 21 days ago

https://github.com/charmbracelet/sequin

A utility for debugging CLIs and TUIs by providing human-readable descriptions of ANSI escape sequences. Sequin allows developers to inspect raw ANSI output from STDIN, files, or by executing commands directly in a simulated TTY environment. It supports a wide range of sequences including CSI, OSC, DCS, and terminal-specific protocols for Kitty and iTerm2, covering cursor movement, colors, clipboard operations, and working directory URLs.

Tokens
7K
Snippets
32
Records
36
Agent score
73%

What's inside sequin

  1. Install Sequin

    main

    You can install Sequin using various package managers or by downloading binaries and using Go.

    Package Managers

    • macOS/Linux (Homebrew): brew install sequin
    • Arch Linux: yay -S sequin-bin
    • Nix (NUR): nix-shell -p nur.repos.charmbracelet.sequin
    • Nix: nix-shell -p sequin

    Debian/Ubuntu

    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
    echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
    sudo apt update && sudo apt install sequin

    Fedora/RHEL

    echo '[charm]
    name=Charm
    baseurl=https://repo.charm.sh/yum/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
    sudo yum install sequin

    Go

    go install github.com/charmbracelet/sequin@latest
    brew install sequin
  2. Generate shell completions for Sequin

    main

    If you installed Sequin from source, you can generate completion files for your shell. If you used a package manager like Homebrew or Deb, completions should be set up automatically if your shell is configured correctly.

    Available shells:

    • Bash
    • ZSH
    • Fish
    • PowerShell
    sequin completion bash -h
    sequin completion zsh -h
    sequin completion fish -h
    sequin completion powershell -h
  3. Use the Sequin CLI to explain ANSI sequences

    main

    Sequin is a utility that takes ANSI escape sequences (from STDIN, a file, or a command's output) and provides a human-readable explanation of what those sequences do. It breaks down sequences like CSI, DCS, OSC, and control characters into understandable text.

    Common Usage Patterns

    Explain sequences from STDIN: Pipe output from another command into sequin.

    Explain sequences from a file: Redirect a file into sequin.

    Run a command and explain its output: Pass a command as arguments to sequin to intercept and explain its output.

    # Explain sequences from STDIN:
    printf '\x1b[m' | sequin
    
    # Explain sequences from a file:
    sequin < file
    
    # Run a command and explain its output:
    sequin -- some command to execute
  4. Describe ANSI escape sequences

    main

    You can use Sequin to get a human-readable explanation of specific ANSI escape sequences by piping them into the utility. This is useful for debugging or learning how sequences work.

    Note: When piping output from programs, you may need to force ANSI output (e.g., using CLICOLOR_FORCE=1 or specific CLI flags) because many programs strip color when they detect they are not running in a TTY.

    printf "\x1b[38;5;4mCiao, \x1b[1;7mBaby.\x1b[0m\n" | sequin
  5. Inspect program output for ANSI sequences

    main

    Pipe the output of any command into Sequin to see the underlying ANSI sequences used for coloring and formatting. Ensure the command is configured to always output color/ANSI sequences.

    ls -1 --color=always | sequin
    
    git -c status.color=always status -sb | sequin
  6. Configure the Sequin theme via SEQUIN_THEME

    main

    You can control the visual theme used for the explanations by setting the SEQUIN_THEME environment variable.

    Supported theme values include:

    • ansi
    • carlos
    • secret_carlos
    • matchy

    If no valid theme is provided or the variable is unset, sequin defaults to a charmTheme that automatically detects whether your terminal has a dark or light background.

  7. Use Pro Mode for inline sequence highlighting

    main

    By default, Sequin describes sequences. If you want to see the regular text with the ANSI sequences highlighted inline (making it easier to separate text from sequences), use the --raw or -r flag.

    git -c status.color=always status -sb | sequin -r && echo
  8. Interpret Select Graphic Rendition (SGR) sequences

    main

    The handleSgr function processes ANSI Select Graphic Rendition (SGR) parameters from an ansi.Parser to produce a human-readable description of text styling. It handles various styling attributes including text effects, colors, and underline styles.

    Supported SGR Parameters

    Parameter(s)Description
    0Reset style
    1Bold
    2Faint
    3Italic
    4Underline (supports sub-styles: 1: Single, 2: Double, 3: Curly, 4: Dotted, 5: Dashed)
    5, 6Blink
    7Inverse
    8Invisible
    9Crossed-out
    22Normal intensity
    23No italic
    24No underline
    25No blink
    27No reverse
    28No conceal
    29No crossed-out
    30-37ANSI foreground color
    38Extended foreground color (ANSI256 or 24-bit RGB)
    39Default foreground color
    40-47ANSI background color
    48Extended background color (ANSI256 or 24-bit RGB)
    49Default background color
    58Extended underline color
    59Default underline color
    90-97Bright ANSI foreground color
    100-107Bright ANSI background color
  9. Implement a custom notify handler with handleNotify

    main

    The handleNotify function is a handler designed to process ANSI escape sequences specifically for terminal notifications. It expects the parser data to contain two parts separated by a semicolon (;). The first part is treated as a prefix, and the second part is extracted to create a formatted string: Notify "<part2>". If the data does not contain exactly two parts, it returns an error.

    // Example usage pattern for handleNotify
    func handleNotify(p *ansi.Parser) (string, error) {
    	parts := bytes.Split(p.Data(), []byte{';'})
    	if len(parts) != 2 {
    		// Invalid, ignore
    		return "", errInvalid
    	}
    
    	return fmt.Sprintf("Notify %q", parts[1]), nil
    }
  10. Handle iTerm2 finalterm escape sequences

    main

    The handleFinalTerm function processes ANSI escape sequences used for shell integration (specifically the finalterm sequence). It parses a semicolon-delimited byte slice from an ansi.Parser and returns a human-readable description of the terminal state change.

    Sequence Format

    The input data must follow the pattern [prefix];[type][;extra_info].

    Supported Types

    TypeDescription
    APrompt start
    BCommand start
    CCommand executed
    DCommand finished (optionally includes exit code)

    Exit Codes

    For type D (Command finished), if a third part is provided in the sequence (e.g., ;D;0), the function appends the exit code to the description: Command finished, exit code: 0.

    func handleFinalTerm(p *ansi.Parser) (string, error)