⚡ A zero-dependency, zero-allocation UTF-16 ANSI and VT100/VT220/Xterm escape sequence parser for Java, engineered for ultra-high-performance TUI layouts, terminal graphics, and console telemetry pipelines.
FastANSI is the dedicated high-speed text processing substrate of the FastJava ecosystem. It introduces a highly optimized, stack-free procedural state machine designed to parse raw terminal output streams containing styles, cursor movements, and custom colors into structured cell representations at the physical hardware level.
By operating with absolutely exactly zero object allocations on the Java heap, FastANSI is 100% garbage-collection-free and suited to run in demanding, high-throughput console-composing pipelines.
- Why FastANSI?
- Key Features
- Performance
- API Quick Reference
- Installation
- Documentation
- Platform Support
- Related Projects
- License
The mission is to establish the fastest, most comprehensive escape sequence parser in the JVM universe. FastANSI enables terminal viewports to consume raw external ANSI dumps dynamically, process global terminal styling, and support custom 24-bit True Color rendering with zero garbage collection overhead.
import fastansi.FastANSI;
public class Demo {
public static void main(String[] args) {
String ansiStream = "Hello \033[1;31mRed Bold\033[0m Text!";
FastANSI.parse(ansiStream, new FastANSI.ANSIListener() {
@Override
public void onText(CharSequence text, int start, int end) {
System.out.println("Text: " + text.subSequence(start, end));
}
@Override
public void onReset() {
System.out.println("Reset Styles");
}
@Override
public void onBold(boolean enable) {
System.out.println("Bold: " + enable);
}
@Override
public void onForegroundColor(int colorType, int r, int g, int b) {
System.out.println("FG Color - Type: " + colorType + ", R:" + r);
}
// ... Implement other low-overhead cursor & mode callbacks
});
}
}- 🚫 Zero Dependencies — Completely standalone, lightweight, pure Java 17 library.
- ⚡ Zero Heap Allocation — Renders cell properties purely using coordinate pointers (
start,end) and primitives, avoiding all standard String splits or regex overhead. - 🎨 Complete Color & Style Support — Full parsing of standard SGR parameters (bold, italic, underlines, standard 4-bit, 8-bit index, and 24-bit True Color RGB).
- 📏 Cursor & Erase Commands — Recognizes all standard VT navigation codes (Cursor up/down/forward/backward, cursor absolute, display/line erasing).
- 📺 Private & OSC Operating Modes — Detects alternate screen buffers (
?1049h/l), cursor display toggles (?25h/l), and window title adjustments via Operating System Commands (OSC).
FastANSI is rigorously profiled using JMH to guarantee zero overhead. Watch the JMH Benchmark
Benchmark: Stripping ANSI escape codes from a text string.
| Operation | Standard Regex (replaceAll) |
FastANSI State Engine | Speedup | Allocations (GC) |
|---|---|---|---|---|
| Strip ANSI String | ~478 ns / op | ~99 ns / op | ~4.8x | Zero |
Measured on Windows 11, Intel Core i5-1135G7 (Surface Pro 8), JDK 25.0.1. The engine bypasses Thread.sleep via FastDWM to guarantee zero-jitter native heartbeats even under GC pressure.
| Method | Description | Path |
|---|---|---|
parse(input, listener) |
Parses a text stream procedurally, triggering corresponding callbacks on the listener. | Reference → |
fg(r, g, b) / fg(idx) |
Generates 24-bit TrueColor or 8-bit index foreground ANSI escape sequences. | FastANSI.java |
bg(r, g, b) / bg(idx) |
Generates 24-bit TrueColor or 8-bit index background ANSI escape sequences. | FastANSI.java |
cursorTo(row, col) |
Generates cursor absolute positioning escape codes. | FastANSI.java |
Tip
See REFERENCE.md for complete callback listings, SGR color codes, and parsed parameters.
FastANSI is pure-Java and has zero external dependencies.
Add the JitPack repository and the dependency to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastANSI</artifactId>
<version>v0.1.0</version>
</dependency>
</dependencies>repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.andrestubbe:FastANSI:v0.1.0'
}Download the latest JAR directly to add it to your classpath:
- 📦 fastansi-v0.1.0.jar (The Core Library)
- REFERENCE.md: Exhaustive catalog of SGR styles, OSC window parameters, and callback contracts.
- PHILOSOPHIE.md: Zero-allocation and low-overhead processing designs.
- ROADMAP.md: Planned milestone features and performance extensions.
- CHANGELOG.md: Planned milestone features and performance extensions.
| Platform | Status |
|---|---|
| Windows 10/11 | ✅ Fully Supported |
| Linux | ✅ Fully Supported |
| macOS | ✅ Fully Supported |
MIT License — See LICENSE file for details.
- FastFileIndex - Binary file indexing with mmap support
- FastFileSearch - Prefix Trie, N-Gram index, and Ranking engine
- FastFileWatch - USN Journal-based live file monitoring
- FastCore - Unified JNI loader and platform abstraction
Part of the FastJava Ecosystem — Making the JVM faster. Small package. Maximum speed. Zero bloat. 🚀📋
