From ddd817edd8d78311f811f3d0d06b138c0b295550 Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 22 Aug 2019 14:02:09 -0300 Subject: Add setBackground ansi utility function --- util/ansi.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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. -- cgit 1.3.0-6-gf8a5