Skip to content

Commit

Permalink
make sure log emits legible messages outside terminals
Browse files Browse the repository at this point in the history
e.g. in a gui notification
  • Loading branch information
sndrs committed Nov 7, 2023
1 parent 31ac8f0 commit e183b80
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ const green = '\u001b[32m';
const dim = '\x1b[2m';
const reset = '\x1b[0m';

const colourise = (colour, str) =>
process.stdout.isTTY ? `${colour}${str}${reset}` : str;

const logIt = (messages = [], color = dim) => {
console.log(`${color}%s${reset}`, capitalize(messages.join('\n')));
console.log(colourise(color, capitalize(messages.join('\n'))));
};

const log = (...messages) => logIt(messages);
Expand Down

0 comments on commit e183b80

Please sign in to comment.