fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.11k stars 140 forks source link

Feature Request: java.lang.Appendable support in org.fusesource.jansi.Ansi #231

Closed Aison0 closed 2 years ago

Aison0 commented 2 years ago

Hello,

Would it be possible that org.fusesource.jansi.Ansi implements the interface java.lang.Appendable? Since Ansi class full-fills the requirements from Appendable, this seems natural:

An object to which char sequences and values can be appended. The Appendable interface must be implemented by any class whose instances are intended to receive formatted output from a java.util.Formatter.

It would be also nice if the field private final StringBuilder builder; is defined as private final Appendable builder;. Then one can also write directly to other Appendable instances like PrintWriter or PrintStream and not just StringBuilder. Of course

    @Override
    public String toString() {
        flushAttributes();
        return builder.toString();
    }

may return not the built string if builder is not an instance of StringBuilder.