`const { styleText } = require('node:util');`
Docs: https://nodejs.org/api/util.html#utilstyletextformat-text-op...
`const { styleText } = require('node:util');`
Docs: https://nodejs.org/api/util.html#utilstyletextformat-text-op...
text: {
angry : "\u001b[1m\u001b[31m",
blue : "\u001b[34m",
bold : "\u001b[1m",
boldLine : "\u001b[1m\u001b[4m",
clear : "\u001b[24m\u001b[22m",
cyan : "\u001b[36m",
green : "\u001b[32m",
noColor : "\u001b[39m",
none : "\u001b[0m",
purple : "\u001b[35m",
red : "\u001b[31m",
underline: "\u001b[4m",
yellow : "\u001b[33m"
}
And then you can call that directly like: `${vars.text.green}whatever${vars.text.none}`;Using a library which handles that (an a thousand other quirks) makes much more sense
The real issue is invented here syndrome. People irrationally defer to libraries to cure their emotional fear of uncertainty. For really large problems, like complete terminal emulation, I understand that. However, when taken to an extreme, like the left pad debacle, it’s clear people are loading up on dependencies for irrational reasons.
It's easy to solve though, simply assign empty strings to escape code variables when the output is not an interactive shell.
If you want to do it yourself, do it right—or defer to one of the battle-tested libraries that handle this for you, and additional edge cases you didn’t think of (such as NO_COLOR).
Typically JS developers define that as assuming something must be safe if enough people use it. That is a huge rift between the typical JS developer and organizations that actually take security more seriously. There is no safety rating for most software on NPM and more and more highly consumed packages are being identified as malicious or compromised.
If you do it yourself and get it wrong there is still a good chance you are in a safer place than completely throwing dependency management to the wind or making wild guesses upon vetted by the community.
Also, I'm guessing if I pipe your logs to a file you'll still write escapes into it? Why not just make life easier?
cjk→⋰⋱| | ← cjk space btw | |
thinsp | |
deg°
⋯ …
‾⎻⎼⎽ lines
_ light lines
⏤ wide lines
↕
∧∨
┌────┬────┐
│ │ ⋱ ⎸ ← left bar, right bar: ⎹
└────┴────┘
⊃⊂ ⊐≣⊏
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯====›‥‥‥‥
◁ ◿ ◺ ◻ ◸
Λ
╱│╲
╱ │ ╲
──┼──
╲ │ ╱
╲│╱
V
┌ ─┏━━┳━━━━━━━┓
│ ┃ ┃ ┃
├ ─┣━━╋━━━━━━━┫
│ ┃ ┃ ┃
└ ─┗━━┻━━━━━━━┛
┌ ─ ┬ ─ ┐
├ ─ ┼ ─ ┤
└ ─ ┴ ─ ┘
┌───┬───┐
├───┼───┤
│ │ │
└───┴───┘
.
╱│╲
↘╱ │ ╲ ↙
╱ │ ╲
→‹───┼───›←
╲ │ ╱
↗ ╲ │ ╱ ↖
╲│╱
↓↑
╳
.
╱ ╲
╱ ╲
╱ ⋰ ╲
╱⋰______╲