A Scala library for safely and efficiently manipulating ANSI-colored strings in command-line applications.
Fansi is a Scala library that provides a type-safe, efficient abstraction for creating and manipulating ANSI-colored strings in command-line applications. It solves the problem of error-prone manual ANSI code concatenation by offering immutable data structures with safe operations for styling, concatenation, and length calculation. Originally part of the Ammonite REPL, it's now a standalone zero-dependency library.
Scala developers building command-line tools, REPLs, or terminal interfaces that require colored output, such as CLI apps, build tools, or interactive shells.
Developers choose Fansi because it eliminates common ANSI-related bugs like color leaks and incorrect string lengths, while providing a performant, immutable API that works across JVM, Scala.js, and Scala Native without dependencies.
Scala/Scala.js library for manipulating Fancy Ansi colored strings
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically manages ANSI resets to prevent color leaks between concatenated strings, as demonstrated in the README's error examples comparing manual string handling to Fansi's correct behavior.
Uses fast array copies and while-loops for operations like length calculation and substring extraction, with memory usage only 3x that of java.lang.String, making it suitable for performance-sensitive terminal apps.
Supports a comprehensive set of ANSI attributes including 8-bit and 24-bit colors, backgrounds, bold, underline, and more through type-safe Attr and Attrs types, enabling precise text styling.
Zero-dependency library that works seamlessly on JVM, Scala.js, and Scala Native, allowing consistent terminal styling across diverse Scala environments without external dependencies.
The fansi.Str class has a skeletal API compared to java.lang.String or scala.RichString, requiring custom implementations for advanced operations, as admitted in the 'Digging Deeper' section of the README.
Incurs a 3x memory overhead and slower operations compared to plain strings, which could impact high-performance applications or those with severe resource limitations, despite the README's claims of efficiency.
Designed solely for Scala ecosystems, making it unsuitable for projects in other languages or mixed-language environments without additional bridging code, limiting its broader adoption.