|
| 1 | +package org.codejive.twinkle.ansi; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import org.jspecify.annotations.NonNull; |
| 5 | + |
| 6 | +public interface Printable { |
| 7 | + /** |
| 8 | + * Converts the object to an ANSI string, including ANSI escape codes for styles. This method |
| 9 | + * resets the current style to default at the start of the string. |
| 10 | + * |
| 11 | + * @return The ANSI string representation of the object. |
| 12 | + */ |
| 13 | + @NonNull String toAnsiString(); |
| 14 | + |
| 15 | + /** |
| 16 | + * Outputs the object as an ANSI string, including ANSI escape codes for styles. This method |
| 17 | + * resets the current style to default at the start of the output. |
| 18 | + * |
| 19 | + * @param appendable The <code>Appendable</code> to write the ANSI output to. |
| 20 | + * @return The <code>Appendable</code> passed as parameter. |
| 21 | + */ |
| 22 | + @NonNull Appendable toAnsi(Appendable appendable) throws IOException; |
| 23 | + |
| 24 | + /** |
| 25 | + * Converts the object to an ANSI string, including ANSI escape codes for styles. This method |
| 26 | + * takes into account the provided current style to generate a result that is as efficient as |
| 27 | + * possible in terms of ANSI codes. |
| 28 | + * |
| 29 | + * @param currentStyle The current style to start with. |
| 30 | + * @return The ANSI string representation of the object. |
| 31 | + */ |
| 32 | + default @NonNull String toAnsiString(Style currentStyle) { |
| 33 | + return toAnsiString(currentStyle.state()); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Outputs the object as an ANSI string, including ANSI escape codes for styles. This method |
| 38 | + * takes into account the provided current style to generate a result that is as efficient as |
| 39 | + * possible in terms of ANSI codes. |
| 40 | + * |
| 41 | + * @param appendable The <code>Appendable</code> to write the ANSI output to. |
| 42 | + * @param currentStyle The current style to start with. |
| 43 | + * @return The <code>Appendable</code> passed as parameter. |
| 44 | + */ |
| 45 | + default @NonNull Appendable toAnsi(Appendable appendable, Style currentStyle) |
| 46 | + throws IOException { |
| 47 | + return toAnsi(appendable, currentStyle.state()); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Converts the object to an ANSI string, including ANSI escape codes for styles. This method |
| 52 | + * takes into account the provided current style to generate a result that is as efficient as |
| 53 | + * possible in terms of ANSI codes. |
| 54 | + * |
| 55 | + * @param currentStyleState The current style to start with. |
| 56 | + * @return The ANSI string representation of the object. |
| 57 | + */ |
| 58 | + @NonNull String toAnsiString(long currentStyleState); |
| 59 | + |
| 60 | + /** |
| 61 | + * Outputs the object as an ANSI string, including ANSI escape codes for styles. This method |
| 62 | + * takes into account the provided current style to generate a result that is as efficient as |
| 63 | + * possible in terms of ANSI codes. |
| 64 | + * |
| 65 | + * @param appendable The <code>Appendable</code> to write the ANSI output to. |
| 66 | + * @param currentStyleState The current style to start with. |
| 67 | + * @return The <code>Appendable</code> passed as parameter. |
| 68 | + */ |
| 69 | + @NonNull Appendable toAnsi(Appendable appendable, long currentStyleState) throws IOException; |
| 70 | +} |
0 commit comments