8

Reading ANSI escape sequences is nitty gritty and very easy to get wrong. I am after a library that includes an abstraction for reading escaped sequences preferrably as instances of some nice type. It would be nice if the library offered strongly types rather than everything is a strong and good luck do the stuff yourself.

Any pointers to a foss library would be appreciated.

A similar question A library to convert ANSI escapes (terminal formatting/color codes) to HTML which seems to have a similar motivation also remains unanswered.

Community
  • 1
  • 1
mP.
  • 18,002
  • 10
  • 71
  • 105
  • I know no library, but once implemented some part of this for a Java terminal implementation. Only color changes and cursor movements, I think. – Paŭlo Ebermann Jun 29 '11 at 12:50
  • @PE, yes ive looked at a few terminal emulators but the logic to parse the stream, handle the escape sequences is almost always embedded with logic to do swing stuff like move the cursor etc. Unfortunately these term emulators dont separate the two concerns with everything lumped into one. – mP. Jun 30 '11 at 00:55
  • @Giann because so few of my q get answered. Take a look at my q and see for yourself. I try and ask interesting q that require some thought rather than simply pointing to google or doco. – mP. Jun 30 '11 at 00:58
  • Unfortunately I do not know of such library. Like others, I once wrote code to handle these sequences (for a Java terminal emulator). But I was curious as to what you are trying to do with the intermediate types? And where would input come from? – StaxMan Jun 30 '11 at 01:02
  • I hope to write a term emulator layer between a server(ApacheSshd) abd a shell. – mP. Jun 30 '11 at 05:29
  • The idea being perhaps my in-betweeen-bit would add stuff like a history, tab completion etc. – mP. Jun 30 '11 at 05:30

2 Answers2

7

You may want to take a look at Jansi.
Here is the homepage and github repo

I hope that helps.

erichelgeson
  • 2,310
  • 1
  • 16
  • 24
c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48
  • Almost, it does seem to support writing ansi, but looking at the class heirarchy it does not appear to do any reading (there are no classes called XXXReader). – mP. Jun 30 '11 at 05:32
  • It seems it does read ansi encoded files too. Look at [`AnsiConsoleExample2`](https://github.com/fusesource/jansi/blob/master/jansi/src/test/java/org/fusesource/jansi/AnsiConsoleExample2.java).It uses the regular io-streams after registering jansi to the system. Seems good as in you can reuse the functionallity of the already implemented streams. – c00kiemon5ter Jun 30 '11 at 09:16
0

ANSI4J is a Java library that parses text with escape codes. It supports all ISO 6429 functions both with parameters and without parameters.

Pavel_K
  • 10,748
  • 13
  • 73
  • 186