[ANN] Fansi: a library for dealing with fancy colored Ansi strings

48 views
Skip to first unread message

Haoyi Li

unread,
May 26, 2016, 3:39:08 PM5/26/16
to scala-user
Fansi is a tiny library I wrote to make it easier to deal with colored text for display in the terminal. 
Inline image 1
It let's you easily apply or remove Ansi color codes to strings, or portions of them, and substring or split the colored strings according to their on-screen width. At the same time, it avoids problems with Ansi colors leaking "rightward" because you forgot to Console.RESET, and does all this efficiently with low memory use and high performance. 

This makes it very convenient if you are not just constructing Ansi colored strings for immediate printing, but also passing them around your program, splicing/manipulating them, or applying additional colors after-the-fact. These are things that are traditionally very error-prone to do with java.lang.Strings with Ansi codes embedded, but with Fansi they are quick and easy.

Fansi was originally the text handling library for the Ammonite REPL, now extracted into its own tiny library and published separately for people to use stand-alone.

Try it out; hope someone finds this useful!


Viktor Klang

unread,
May 26, 2016, 3:50:15 PM5/26/16
to Haoyi Li, scala-user
What a lovely name for that library!

(This also gives me a lot of nostalgia from the time where I programmed MUDs, in C as it so were, but in any case!)

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Naftoli Gugenheim

unread,
May 26, 2016, 11:08:48 PM5/26/16
to Haoyi Li, scala-user
...and he does it again! 😂


On Thu, May 26, 2016, 3:38 PM Haoyi Li <haoy...@gmail.com> wrote:
Fansi is a tiny library I wrote to make it easier to deal with colored text for display in the terminal. 

It let's you easily apply or remove Ansi color codes to strings, or portions of them, and substring or split the colored strings according to their on-screen width. At the same time, it avoids problems with Ansi colors leaking "rightward" because you forgot to Console.RESET, and does all this efficiently with low memory use and high performance. 

This makes it very convenient if you are not just constructing Ansi colored strings for immediate printing, but also passing them around your program, splicing/manipulating them, or applying additional colors after-the-fact. These are things that are traditionally very error-prone to do with java.lang.Strings with Ansi codes embedded, but with Fansi they are quick and easy.

Fansi was originally the text handling library for the Ammonite REPL, now extracted into its own tiny library and published separately for people to use stand-alone.

Try it out; hope someone finds this useful!


Matthew Pocock

unread,
May 27, 2016, 5:28:35 AM5/27/16
to Naftoli Gugenheim, Haoyi Li, scala-user
This is a possibly complementary library I knocked up for colored and styled output. It supports ansii color codes for terminals, but also some other formats.

https://github.com/drdozer/ansi_color

Matthew
--
Dr Matthew Pocock
Turing ate my hamster LTD

Integrative Bioinformatics Group, School of Computing Science, Newcastle University

skype: matthew.pocock
tel: (0191) 2566550
Reply all
Reply to author
Forward
0 new messages