Skip to content

Force color output in rescript_bsb.js if NINJA_ANSI_FORCED=1 #7032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#### :nail_care: Polish

- Improve bigint literal comparison. https://github.com/rescript-lang/rescript-compiler/pull/7029
- Force color output in `rescript_bsb.js` if `NINJA_ANSI_FORCED=1`. https://github.com/rescript-lang/rescript-compiler/pull/7032

# 12.0.0-alpha.3

Expand Down
12 changes: 6 additions & 6 deletions cli/rescript_bsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function clean(args) {
delegate(["clean", ...args]);
}

const isTtyError = process.stderr.isTTY;
const isTtyStd = process.stdout.isTTY;
const shouldColorizeError = process.stderr.isTTY || process.env.NINJA_ANSI_FORCED == "1";
const shouldColorize = process.stdout.isTTY || process.env.NINJA_ANSI_FORCED == "1";

/**
* @type {[number,number]}
Expand All @@ -133,7 +133,7 @@ function logFinishCompiling(code) {
if (code) {
log = log + " (exit: " + code + ")";
}
if (isTtyStd) {
if (shouldColorize) {
log = "\x1b[36m" + log + "\x1b[0m";
}
if (code) {
Expand All @@ -146,7 +146,7 @@ function logFinishCompiling(code) {
function logStartCompiling() {
updateStartTime();
let log = `>>>> Start compiling`;
if (isTtyStd) {
if (shouldColorize) {
log = "\x1b[36m" + log + "\x1b[0m";
}
console.log(log);
Expand Down Expand Up @@ -265,7 +265,7 @@ function watch(args) {
.on("error", function (err) {
// @ts-ignore
if (err !== undefined && err.code === "EADDRINUSE") {
var error = isTtyStd ? `\x1b[1;31mERROR:\x1b[0m` : `ERROR:`;
var error = shouldColorize ? `\x1b[1;31mERROR:\x1b[0m` : `ERROR:`;
console.error(`${error} The websocket port number ${webSocketPort} is in use.
Please pick a different one using the \`-ws [host:]port\` flag from bsb.`);
} else {
Expand Down Expand Up @@ -358,7 +358,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`);
* @param highlight {string}
*/
function outputError(error, highlight) {
if (isTtyError && highlight) {
if (shouldColorizeError && highlight) {
process.stderr.write(
error.replace(highlight, "\x1b[1;31m" + highlight + "\x1b[0m"),
);
Expand Down