Color Output Without Library
NodeJS
Hard
4 views
Problem Description
Print green text using ANSI codes only when stdout is TTY.
Output Format
Print colored or plain.
Constraints
Use process.stdout.isTTY.
Official Solution
const isTTY = !!process.stdout.isTTY;
const text = 'meetcode ok';
if (isTTY) {
console.log('\\u001b[32m' + text + '\\u001b[0m');
} else {
console.log(text);
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!