1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.cli.jansi;
20
21 import org.apache.maven.api.annotations.Experimental;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.services.MessageBuilder;
24 import org.fusesource.jansi.Ansi;
25
26 @Experimental
27 public class JansiMessageBuilder implements MessageBuilder {
28 private final Ansi ansi;
29
30 public JansiMessageBuilder() {
31 this.ansi = Ansi.ansi();
32 }
33
34 public JansiMessageBuilder(StringBuilder sb) {
35 this.ansi = Ansi.ansi(sb);
36 }
37
38 @Override
39 @Nonnull
40 public MessageBuilder debug(Object o) {
41 return style(Style.DEBUG, o);
42 }
43
44 @Override
45 @Nonnull
46 public MessageBuilder info(Object o) {
47 return style(Style.INFO, o);
48 }
49
50 @Override
51 @Nonnull
52 public MessageBuilder warning(Object o) {
53 return style(Style.WARNING, o);
54 }
55
56 @Override
57 @Nonnull
58 public MessageBuilder error(Object o) {
59 return style(Style.ERROR, o);
60 }
61
62 @Override
63 @Nonnull
64 public MessageBuilder success(Object o) {
65 return style(Style.SUCCESS, o);
66 }
67
68 @Override
69 @Nonnull
70 public MessageBuilder failure(Object o) {
71 return style(Style.FAILURE, o);
72 }
73
74 @Override
75 @Nonnull
76 public MessageBuilder strong(Object o) {
77 return style(Style.STRONG, o);
78 }
79
80 @Override
81 @Nonnull
82 public MessageBuilder mojo(Object o) {
83 return style(Style.MOJO, o);
84 }
85
86 @Override
87 @Nonnull
88 public MessageBuilder project(Object o) {
89 return style(Style.PROJECT, o);
90 }
91
92 private MessageBuilder style(Style style, Object o) {
93 style.apply(ansi).a(o).reset();
94 return this;
95 }
96
97 @Override
98 @Nonnull
99 public MessageBuilder a(char[] chars, int i, int i1) {
100 ansi.a(chars, i, i1);
101 return this;
102 }
103
104 @Override
105 @Nonnull
106 public MessageBuilder a(char[] chars) {
107 ansi.a(chars);
108 return this;
109 }
110
111 @Override
112 @Nonnull
113 public MessageBuilder a(CharSequence charSequence, int i, int i1) {
114 ansi.a(charSequence, i, i1);
115 return this;
116 }
117
118 @Override
119 @Nonnull
120 public MessageBuilder a(CharSequence charSequence) {
121 ansi.a(charSequence);
122 return this;
123 }
124
125 @Override
126 @Nonnull
127 public MessageBuilder a(Object o) {
128 ansi.a(o);
129 return this;
130 }
131
132 @Override
133 @Nonnull
134 public MessageBuilder newline() {
135 ansi.newline();
136 return this;
137 }
138
139 @Override
140 @Nonnull
141 public MessageBuilder format(String s, Object... objects) {
142 ansi.format(s, objects);
143 return this;
144 }
145
146 @Override
147 @Nonnull
148 public String build() {
149 return ansi.toString();
150 }
151
152 @Override
153 public String toString() {
154 return build();
155 }
156 }