diff options
author | Florrie <towerofnix@gmail.com> | 2019-08-22 14:02:09 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-08-22 14:02:09 -0300 |
commit | ddd817edd8d78311f811f3d0d06b138c0b295550 (patch) | |
tree | de36859141702cf3b4046a743e4d18b3b8efd888 /util | |
parent | d809ba2081041504998ad3b77c66b24e051f9458 (diff) |
Add setBackground ansi utility function
Diffstat (limited to 'util')
-rw-r--r-- | util/ansi.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/util/ansi.js b/util/ansi.js index 6f3e23e..c786db5 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -94,6 +94,21 @@ const ansi = { return ansi.setAttributes([color]) }, + setBackground(color) { + // Sets the background color to print text with. Accepts the same arguments + // as setForeground (C_(COLOR), C_RESET, etc). + // + // Note that attributes such as A_BRIGHT and A_DIM apply apply to only the + // foreground, not the background. To set a bright or dim background, you + // can set the appropriate color as the foreground and then invert. + + if (typeof color === 'undefined' || color === null) { + return '' + } + + return ansi.setAttributes([color + 10]) + }, + invert() { // Inverts the foreground and background colors. |