« get me outta code hell

Add setBackground ansi utility function - 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:
authorFlorrie <towerofnix@gmail.com>2019-08-22 14:02:09 -0300
committerFlorrie <towerofnix@gmail.com>2019-08-22 14:02:09 -0300
commitddd817edd8d78311f811f3d0d06b138c0b295550 (patch)
treede36859141702cf3b4046a743e4d18b3b8efd888 /util
parentd809ba2081041504998ad3b77c66b24e051f9458 (diff)
Add setBackground ansi utility function
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.