XenoAtom.Ansi [](https://github.com/XenoAtom/XenoAtom.Ansi/actions/workflows/ci.yml) [](https://www.nuget.org/packages/XenoAtom.Ansi/)

April 27, 2026 ยท View on GitHub

XenoAtom.Ansi is a fast, allocation-friendly .NET library for building rich ANSI/VT output and processing ANSI text. It helps you emit styled sequences, format markup, tokenize streams, and perform ANSI-aware text operations.

โœจ Features

  • net10.0+ library and NativeAOT ready
  • Fast, allocation-friendly APIs
  • Rendering / Emitting
    • AnsiWriter fluent API (writes to TextWriter or IBufferWriter<char>)
    • AnsiMarkup for markup strings, including interpolated strings (formatted values are escaped)
    • SGR styling: colors (basic-16, 256-color, truecolor RGB), decorations (bold/dim/italic/underline/etc), reset
    • Capability-aware output (AnsiCapabilities) including color downgrading, private-mode gating, and optional safe-mode behavior
    • Cursor/screen helpers (ANSI/DEC/xterm/Windows Terminal): move/position, save/restore, erase (incl. scrollback), insert/delete chars/lines, scrolling + scroll regions, cursor style, mode toggles, tabs, alternate screen, soft reset
    • OSC helpers with configurable terminator (BEL or ST): generic OSC, window title (OSC 0/2), palette edits (OSC 4), hyperlinks (OSC 8)
    • Low-level terminal string control/protocol framing helpers: DCS, SOS, PM, APC, Kitty graphics APC, iTerm2 image OSC 1337, and Sixel DCS payload wrappers
  • Parsing
    • Streaming ANSI/VT tokenizer (AnsiTokenizer) with chunked parsing support (ESC and 8-bit C1 forms)
    • Token model for Text, selected controls, ESC, CSI, OSC, DCS/SOS/PM/APC string controls, decoded SGR, and malformed/unknown sequences (tolerant; never throws)
    • Input interpretation helpers for keys, mouse (SGR), and cursor position reports (CPR)
    • Styled runs parser (AnsiStyledTextParser) that interprets SGR + OSC 8 into AnsiStyle/hyperlink runs
  • Text Utilities
    • ANSI-aware text helpers (AnsiText): strip, visible width measurement (wcwidth), wrap, truncate (optionally preserving ANSI)
  • Color Helpers
    • Palettes (AnsiColors, AnsiColors.Web, AnsiPalettes) for named colors and xterm-like RGB approximations

Note

XenoAtom.Ansi is a low-level foundation library, not a terminal UI framework like Spectre.Console. It focuses on emitting and parsing ANSI/VT sequences against TextWriter / character buffers. It does not provide widgets, layout, input loops, or terminal state management (those belong in higher-level libraries).

๐Ÿงช Samples

Example of XenoAtom.Ansi output

  • samples/HelloWorld โ€” basic formatting across a few lines
  • samples/HelloAdvanced โ€” richer demo (colors, decorations, markup, OSC 8 links, screen helpers)

Run:

  • dotnet run --project samples/HelloWorld/HelloWorld.csproj
  • dotnet run --project samples/HelloAdvanced/HelloAdvanced.csproj

๐Ÿ“– User Guide

For more details on how to use XenoAtom.Ansi, please visit the user guide.

๐Ÿชช License

This software is released under the BSD-2-Clause license.

๐Ÿค— Author

Alexandre Mutel aka xoofx.