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
AnsiWriterfluent API (writes toTextWriterorIBufferWriter<char>)AnsiMarkupfor 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 intoAnsiStyle/hyperlink runs
- Streaming ANSI/VT tokenizer (
- Text Utilities
- ANSI-aware text helpers (
AnsiText): strip, visible width measurement (wcwidth), wrap, truncate (optionally preserving ANSI)
- ANSI-aware text helpers (
- Color Helpers
- Palettes (
AnsiColors,AnsiColors.Web,AnsiPalettes) for named colors and xterm-like RGB approximations
- Palettes (
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

samples/HelloWorldโ basic formatting across a few linessamples/HelloAdvancedโ richer demo (colors, decorations, markup, OSC 8 links, screen helpers)
Run:
dotnet run --project samples/HelloWorld/HelloWorld.csprojdotnet 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.