@@ -13,6 +13,27 @@ public class Ansi {
1313 public static final String DEC_SET = "h" ;
1414 public static final String DEC_RST = "l" ;
1515
16+ // ANSI style codes
17+ public static final int STYLE_RESET = 0 ;
18+ public static final int STYLE_BOLD = 1 ;
19+ public static final int STYLE_FAINT = 2 ;
20+ public static final int STYLE_ITALIC = 3 ;
21+ public static final int STYLE_UNDERLINE = 4 ;
22+ public static final int STYLE_BLINK = 5 ;
23+ public static final int STYLE_INVERSE = 7 ;
24+ public static final int STYLE_HIDDEN = 8 ;
25+ public static final int STYLE_STRIKETHROUGH = 9 ;
26+ public static final int STYLE_DOUBLE_UNDERLINE = 21 ;
27+ public static final int STYLE_NORMAL = 22 ;
28+ public static final int STYLE_ITALIC_OFF = 23 ;
29+ public static final int STYLE_UNDERLINE_OFF = 24 ;
30+ public static final int STYLE_BLINK_OFF = 25 ;
31+ public static final int STYLE_INVERSE_OFF = 27 ;
32+ public static final int STYLE_HIDDEN_OFF = 28 ;
33+ public static final int STYLE_STRIKETHROUGH_OFF = 29 ;
34+ public static final int STYLE_OVERLINE = 53 ;
35+ public static final int STYLE_OVERLINE_OFF = 55 ;
36+
1637 // Positive mode numbers are official ANSI modes
1738 public static final int MODE_ECHO = 12 ;
1839
@@ -37,39 +58,51 @@ public class Ansi {
3758 public static final int MODE_UNICODE = -2027 ;
3859 public static final int MODE_SYSTEMTHEME = -2031 ;
3960
40- public static String csi (String post , int ... params ) {
61+ public static String csi (String post , Object ... params ) {
4162 return csi ((String ) null , post , params );
4263 }
4364
44- public static String csi (String pre , String post , int ... params ) {
65+ public static String csi (String pre , String post , Object ... params ) {
4566 try {
4667 return csi (new StringBuilder (), pre , post , params ).toString ();
4768 } catch (IOException e ) {
4869 throw new RuntimeException (e );
4970 }
5071 }
5172
52- public static Appendable csi (Appendable appendable , String post , int ... params )
73+ public static Appendable csi (Appendable appendable , String post , Object ... params )
5374 throws IOException {
5475 return csi (appendable , null , post , params );
5576 }
5677
57- public static Appendable csi (Appendable appendable , String pre , String post , int ... params )
78+ public static Appendable csi (Appendable appendable , String pre , String post , Object ... params )
5879 throws IOException {
5980 appendable .append (CSI );
6081 if (pre != null ) {
6182 appendable .append (pre );
6283 }
6384 for (int i = 0 ; i < params .length ; i ++) {
6485 if (i > 0 ) appendable .append (";" );
65- appendable .append (Integer . toString ( params [i ]));
86+ appendable .append (params [i ]. toString ( ));
6687 }
6788 if (post != null ) {
6889 appendable .append (post );
6990 }
7091 return appendable ;
7192 }
7293
94+ public static String style (Object ... params ) {
95+ return csi ("" , "m" , params );
96+ }
97+
98+ public static String resetStyle () {
99+ return style (STYLE_RESET );
100+ }
101+
102+ public static String styled (String text , Object ... params ) {
103+ return style (params ) + text + resetStyle ();
104+ }
105+
73106 public static String modeQuery (int mode ) {
74107 if (mode >= 0 ) {
75108 return csi ("" , "$p" , mode );
0 commit comments