2121#include < regex>
2222#include < sstream>
2323#include < system_error>
24+ #include < vector>
25+ #include < optional>
2426
2527#include < vix/cli/Style.hpp>
2628
2729namespace vix ::cli::build
2830{
2931 namespace style = vix::cli::style;
3032
33+ static std::string colorize (
34+ const char *color,
35+ const std::string &value)
36+ {
37+ return std::string (color) + value + style::RESET;
38+ }
39+
3140 namespace
3241 {
3342 static std::string trim_copy (const std::string &value)
@@ -51,13 +60,6 @@ namespace vix::cli::build
5160 return value.substr (begin, end - begin);
5261 }
5362
54- static std::string colorize (
55- const char *color,
56- const std::string &value)
57- {
58- return std::string (color) + value + style::RESET;
59- }
60-
6163 static bool is_absolute_or_relative_path_like (const std::string &value)
6264 {
6365 if (value.empty ())
@@ -106,6 +108,9 @@ namespace vix::cli::build
106108 if (label == " code:" )
107109 return style::CYAN;
108110
111+ if (label == " message:" )
112+ return style::CYAN;
113+
109114 return style::GRAY;
110115 }
111116
@@ -131,6 +136,99 @@ namespace vix::cli::build
131136 }
132137 } // namespace
133138
139+ void print_build_header_full (
140+ std::ostream &out,
141+ const std::string &target,
142+ const std::string &preset,
143+ const std::optional<std::string> &launcher,
144+ const std::optional<std::string> &fastLinkerFlag,
145+ int jobs)
146+ {
147+ out << style::CYAN
148+ << style::BOLD
149+ << " Compiling"
150+ << style::RESET;
151+
152+ if (!target.empty ())
153+ {
154+ out << " "
155+ << style::CYAN
156+ << style::BOLD
157+ << target
158+ << style::RESET;
159+ }
160+
161+ if (!preset.empty ())
162+ out << " " << colorize (style::GRAY, " (" + preset + " )" );
163+
164+ out << " \n " ;
165+
166+ std::vector<std::string> meta;
167+
168+ if (launcher && !launcher->empty ())
169+ {
170+ meta.push_back (
171+ " launcher: " + colorize (style::MAGENTA, *launcher));
172+ }
173+
174+ if (fastLinkerFlag && !fastLinkerFlag->empty ())
175+ {
176+ const std::string name =
177+ fastLinkerFlag->find (" mold" ) != std::string::npos
178+ ? " mold"
179+ : " lld" ;
180+
181+ meta.push_back (
182+ " linker: " + colorize (style::MAGENTA, name));
183+ }
184+
185+ if (jobs > 0 )
186+ {
187+ meta.push_back (
188+ " jobs: " + colorize (style::MAGENTA, std::to_string (jobs)));
189+ }
190+
191+ if (!meta.empty ())
192+ {
193+ out << style::GRAY << " * " << style::RESET;
194+
195+ for (std::size_t i = 0 ; i < meta.size (); ++i)
196+ {
197+ if (i > 0 )
198+ out << style::GRAY << " | " << style::RESET;
199+
200+ out << meta[i];
201+ }
202+
203+ out << " \n " ;
204+ }
205+ }
206+
207+ void print_build_success_timed (
208+ std::ostream &out,
209+ const std::string &message,
210+ long long milliseconds)
211+ {
212+ out << " "
213+ << colorize (style::GREEN, " ok" )
214+ << " "
215+ << message;
216+
217+ if (milliseconds > 0 )
218+ {
219+ const double seconds = static_cast <double >(milliseconds) / 1000.0 ;
220+
221+ std::ostringstream time;
222+ time.setf (std::ios::fixed);
223+ time.precision (seconds >= 10.0 ? 1 : 2 );
224+ time << seconds << " s" ;
225+
226+ out << " " << colorize (style::GRAY, " | " + time.str ());
227+ }
228+
229+ out << " \n " ;
230+ }
231+
134232 bool BuildLocation::valid () const
135233 {
136234 return !file.empty ();
@@ -289,17 +387,24 @@ namespace vix::cli::build
289387 std::ostream &out,
290388 const BuildDiagnostic &diagnostic)
291389 {
292- out << " \n " ;
390+ const std::string title =
391+ diagnostic.title .empty ()
392+ ? std::string (" Build failed" )
393+ : diagnostic.title ;
394+
293395 out << " "
294- << colorize ( style::RED, " ✖ " )
295- << " "
296- << colorize (style::BOLD, diagnostic. title . empty ()
297- ? std::string ( " Build failed " )
298- : diagnostic. title )
396+ << style::RED
397+ << style::BOLD
398+ << " ✖ "
399+ << title
400+ << style::RESET
299401 << " \n\n " ;
300402
301403 if (!diagnostic.message .empty ())
302- out << " " << diagnostic.message << " \n\n " ;
404+ {
405+ print_label (out, " message:" );
406+ out << " " << diagnostic.message << " \n\n " ;
407+ }
303408
304409 if (diagnostic.has_location ())
305410 {
0 commit comments