Skip to content

Commit fa1b3c3

Browse files
authored
fix: color execution time based on duration in verbose mode (#680) (#681)
* fix: color execution time based on duration in verbose mode In verbose mode, execution time was always displayed in cyan (blue). Now uses a color palette to help spot slow operations: - ≤1s: green (fast) - 1-5s: cyan (normal) - 5-30s: yellow (slow) - ≥30s: red (very slow) Fixes #680 Signed-off-by: zlplzp123wyt <zlplzp123wyt@users.noreply.github.com> * fix: add blank line before return statement to fix lint error --------- Signed-off-by: zlplzp123wyt <zlplzp123wyt@users.noreply.github.com> Co-authored-by: zlplzp123wyt <zlplzp123wyt@users.noreply.github.com>
1 parent 40ac566 commit fa1b3c3

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/commands/scanner.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function initLogger(spec, verbose = true) {
195195
i18n.getTokenSync("cli.stat",
196196
kleur.blue().bold("verbose"),
197197
stat.name,
198-
kleur.cyan().bold(formatMs(stat.executionTime))
198+
colorExecutionTime(stat.executionTime)
199199
)));
200200
startSpinners();
201201
});
@@ -247,6 +247,21 @@ function formatMs(time) {
247247
return ms(Number(time.toFixed(2)));
248248
}
249249

250+
function colorExecutionTime(timeMs) {
251+
const formatted = formatMs(timeMs);
252+
if (timeMs <= 1_000) {
253+
return kleur.green().bold(formatted);
254+
}
255+
else if (timeMs <= 5_000) {
256+
return kleur.cyan().bold(formatted);
257+
}
258+
else if (timeMs <= 30_000) {
259+
return kleur.yellow().bold(formatted);
260+
}
261+
262+
return kleur.red().bold(formatted);
263+
}
264+
250265
function stopSpinners() {
251266
spinners.forEach((spinner) => {
252267
if (!spinner.succeeded) {

0 commit comments

Comments
 (0)