Class HtmlAnsiOutputStream

java.lang.Object
java.io.OutputStream
org.aesh.terminal.utils.HtmlAnsiOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class HtmlAnsiOutputStream extends OutputStream
An OutputStream that parses ANSI escape sequences from written bytes and converts them to HTML with inline CSS styles.

Supports SGR (Select Graphic Rendition) parameters including:

  • Basic 8 foreground and background colors (codes 30-37, 40-47)
  • Bright foreground and background colors (codes 90-97, 100-107)
  • 256-color extended palette (codes 38;5;n and 48;5;n)
  • True color RGB (codes 38;2;r;g;b and 48;2;r;g;b)
  • Bold, underline, italic, concealed, and other text attributes

HTML special characters (&, <, >, ") are escaped in the output.

Usage example:

 ByteArrayOutputStream html = new ByteArrayOutputStream();
 try (HtmlAnsiOutputStream out = new HtmlAnsiOutputStream(html)) {
     out.write("Error: Something failed".getBytes());
 }
 String result = html.toString(); // "<b><span style="color: red;">Error:</span></b> Something failed"
 
Author:
Ståle Pedersen