File tree 2 files changed +24
-0
lines changed
main/java/org/fusesource/jansi
test/java/org/fusesource/jansi
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,10 @@ public int value() {
151
151
}
152
152
}
153
153
154
+ public interface Consumer {
155
+ void apply (Ansi ansi );
156
+ }
157
+
154
158
public static final String DISABLE = Ansi .class .getName () + ".disable" ;
155
159
156
160
private static Callable <Boolean > detector = new Callable <Boolean >() {
@@ -737,6 +741,17 @@ public Ansi format(String pattern, Object... args) {
737
741
return this ;
738
742
}
739
743
744
+ /**
745
+ * Applies another function to this Ansi instance.
746
+ *
747
+ * @param fun the function to apply
748
+ * @return this Ansi instance
749
+ */
750
+ public Ansi apply (Consumer fun ) {
751
+ fun .apply (this );
752
+ return this ;
753
+ }
754
+
740
755
@ Override
741
756
public String toString () {
742
757
flushAttributes ();
Original file line number Diff line number Diff line change @@ -52,4 +52,13 @@ public void testClone() throws CloneNotSupportedException {
52
52
53
53
assertEquals (ansi .a ("test" ).reset ().toString (), clone .a ("test" ).reset ().toString ());
54
54
}
55
+
56
+ @ Test
57
+ public void testApply () {
58
+ assertEquals ("test" , Ansi .ansi ().apply (new Ansi .Consumer () {
59
+ public void apply (Ansi ansi ) {
60
+ ansi .a ("test" );
61
+ }
62
+ }).toString ());
63
+ }
55
64
}
You can’t perform that action at this time.
0 commit comments