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.
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 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): window title (OSC 0/2), palette edits (OSC 4), hyperlinks (OSC 8)
- 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, 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/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
For more details on how to use XenoAtom.Ansi, please visit the user guide.
This software is released under the BSD-2-Clause license.
Alexandre Mutel aka xoofx.

