How to use the colors function from blessed

Find comprehensive JavaScript blessed.colors code examples handpicked from public code repositorys.

blessed.colors is an object that defines a set of predefined terminal colors for use in the Blessed library.

64
65
66
67
68
69
70
71
72
73
Class.prototype._menu = function(){
  process.title = this.name;

  // get some colors
  var bg = blessed.colors.match(this.background);
  var fg = blessed.colors.match(this.foreground);

  // create screen
  this.menu = blessed.screen({
    term: (isWin ? 'windows-ansi' : null)
fork icon0
star icon6
watch icon3

+ 3 other calls in file

298
299
300
301
302
303
304
305
306
307
self.focusMainBox = function() {
  self.mainContentBox.focus();
}

self.setInputColor = function(color) {
  self.inputBox.style.fg = blessed.colors.convert(color);
}

self.lightBlack = function(s) {
  return '{light-black-fg}' + s + '{/light-black-fg}';
fork icon0
star icon1
watch icon1

+ 83 other calls in file

How does blessed.colors work?

blessed.colors is an object in the Blessed library that provides an easy way to define and manage color schemes for terminal UI applications, by mapping color names to their ANSI escape code equivalents. It allows users to easily customize the colors of their terminal UI components.

382
383
384
385
386
387
388
389
390
391
    i += 2;
    fg = +code[i];
    break;
} else if (c === 38 && +code[i + 1] === 2) {
    i += 2;
    fg = blessed.colors.convert(
        [+code[i], +code[i + 1], +code[i + 2]],
        'fg'
    );
    if (fg === -1) fg = (def >> 9) & 0x1ff;
fork icon0
star icon0
watch icon1

+ 3 other calls in file

208
209
210
211
212
213
214
215
216
217
            isXterm,
            false
        );
    }
} else if (Array.isArray(color)) {
    color = blessed.colors.match(
        color[0],
        color[1],
        color[2],
        layer,
fork icon0
star icon0
watch icon1

+ 21 other calls in file

Ai Example

1
2
3
4
5
6
const blessed = require("blessed");

// Get the color code for the color name
const colorCode = blessed.colors.match("#f00", "red");

console.log(colorCode); // Outputs: 1

In the above example, we're using the blessed.colors.match() method to get the color code for the color name "red". We're passing the color code "#f00" (which represents red) as the first argument and the color name "red" as the second argument. The method returns the color code, which is then logged to the console. In this case, the color code for "red" is 1.

190
191
192
193
194
195
196
197
198
199
200
};


/*
    - Adds italics and darken decorations
    - Checks if border style properties are functions, runs them (this seemed like an OK place to put this)
    - Different arguments for blessed.colors.convert because of changes to blessed.colors handling code,
      see ./color
*/
blessed.Element.prototype.sattr = function (style, fg, bg) {
    var bold = style.bold,
fork icon0
star icon0
watch icon1

+ 23 other calls in file

57
58
59
60
61
62
63
64
65
66
border: {
    type: "bg",
},
style: {
    fg: "gray",
    bg: blessed.colors.default,
    border: {
        fg: "#f0f0f0",
    },
},
fork icon0
star icon0
watch icon0