« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ansi.js15
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.