Skip to content

Commit

Permalink
yoctocolors -> Node.js built-in styleText
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Jan 19, 2025
1 parent 2624c4e commit a69bc1e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@
"sass": "1.77.6",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0",
"workbox-build": "^7.3.0",
"yoctocolors": "^2.1.1"
"workbox-build": "^7.3.0"
},
"engines": {
"node": "^22.0.0",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions tools/watch/spinners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import process from "node:process";
import type { WriteStream } from "node:tty";
import { stripVTControlCharacters } from "util";
import yoctocolors from "yoctocolors";
import { stripVTControlCharacters, styleText } from "node:util";

const isUnicodeSupported =
process.platform !== "win32" || Boolean(process.env.WT_SESSION);
Expand All @@ -13,14 +12,14 @@ const isInteractive = (stream: WriteStream) =>
stream.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env),
);

const successSymbol = yoctocolors.green(isUnicodeSupported ? "✔" : "√");
const errorSymbol = yoctocolors.red(isUnicodeSupported ? "✖" : "×");
const successSymbol = styleText("green", isUnicodeSupported ? "✔" : "√");
const errorSymbol = styleText("red", isUnicodeSupported ? "✖" : "×");

const frames = (
isUnicodeSupported
? ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
: ["-", "\\", "|", "/"]
).map(frame => yoctocolors.cyan(frame));
).map(frame => styleText("cyan", frame));

const interval = 80;

Expand Down Expand Up @@ -309,9 +308,9 @@ export const spinners = new Spinners(
const time = dateStart.toLocaleTimeString();
let coloredTime;
if (millisecondsElapsed > TIME_CUTOFF_SPIN_2) {
coloredTime = yoctocolors.red(time);
coloredTime = styleText("red", time);
} else if (millisecondsElapsed > TIME_CUTOFF_SPIN_1) {
coloredTime = yoctocolors.yellow(time);
coloredTime = styleText("yellow", time);
} else {
coloredTime = time;
}
Expand All @@ -333,9 +332,9 @@ export const spinners = new Spinners(
const time = dateEnd.toLocaleTimeString();
let coloredTime;
if (millisecondsElapsed < TIME_CUTOFF_SUCCESS_1) {
coloredTime = yoctocolors.green(time);
coloredTime = styleText("green", time);
} else if (millisecondsElapsed < TIME_CUTOFF_SUCCESS_2) {
coloredTime = yoctocolors.yellow(time);
coloredTime = styleText("yellow", time);
} else {
coloredTime = time;
}
Expand Down

0 comments on commit a69bc1e

Please sign in to comment.