How to use the helpers function from blessed

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

The blessed.helpers module provides various utility functions for the Blessed library.

41
42
43
44
45
46
47
48
49
50

if (cmd.keys && cmd.keys[0]) {
  cmd.prefix = cmd.keys[0];
}

var t = blessed.helpers.generateTags(this.style.prefix || { fg: 'lightblack' });

title = (cmd.prefix != null ? t.open + cmd.prefix + t.close + ':' : '') + cmd.text;

len = ((cmd.prefix != null ? cmd.prefix + ':' : '') + cmd.text).length;
fork icon148
star icon0
watch icon1

+ 31 other calls in file

113
114
115
116
117
118
119
120
121
122
  enumerable: true,
});

function updateTabTitle(tab, index, title) {
  const prefix = index + 1 + '';
  const t = blessed.helpers.generateTags(tabs.style.prefix /* || { fg: 'lightblack' } */);
  const content = (prefix != null ? t.open + prefix + t.close + ':' : '') + title;
  const len = tab.strWidth((prefix != null ? prefix + ':' : '') + title);
  tab.setContent(content);
  tab.width = len + 2;
fork icon148
star icon0
watch icon1

+ 11 other calls in file

How does blessed.helpers work?

blessed.helpers is an object that contains various utility functions used internally by the blessed library, such as clamp, strWidth, sprintf, parseTags, stripTags, etc. These functions help in calculating and formatting various values such as width and height of strings, string padding, colorizing text, etc. and are used by different components of the blessed library to render the terminal user interface.

15
16
17
18
19
20
21
22
23
24
//screen related data 

this.frameBuffer = this._createFrameBuffer()
this.screen = blessed.screen({smartCSR: true})
this.screen.title = "CHIP-8"
this.color = blessed.helpers.attrToBinary({fg: COLOR})

//key replated 
this.keys = 0
this.keyPressed = undefined
fork icon1
star icon0
watch icon1

+ 8 other calls in file

590
591
592
593
594
595
596
597
598
599

this.on('mousemove', (data) => {
    if (self.lockKeys) return;

    if (self._needsClickableSort) {
        self.clickable = blessed.helpers.hsort(self.clickable);
        self._needsClickableSort = false;
    }

    var i = 0,
fork icon0
star icon0
watch icon1

+ 3 other calls in file

Ai Example

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

// get the visual width of a string
const str = "Hello world";
const width = blessed.helpers.strwidth(str);

console.log(`The string "${str}" has a visual width of ${width} characters.`);

This will output: arduino Copy code

8
9
10
11
12
13
14
15
16
this.screen = blessed.screen({
    smartCSR: true
})
this.frameBuffer = this.createFrameBuffer()
this.screen.title = 'chip8'
this.color = blessed.helpers.attrToBinary({ fg: color })

this.keys = 0
this.keyPressed = undefined
fork icon0
star icon0
watch icon1

43
44
45
46
47
48
49
50
51
if (cmd.keys && cmd.keys[0]) {
  cmd.prefix = cmd.keys[0];
}

// PATCH BEGIN
var t = blessed.helpers.generateTags(this.style.prefix /* || { fg: 'lightblack' } */);
// PATCH END

title = (cmd.prefix != null ? t.open + cmd.prefix + t.close + ':' : '') + cmd.text;
fork icon0
star icon0
watch icon0

+ 13 other calls in file

43
44
45
46
47
48
49
50
51
52
this.selected = index;
const itemValue = this.ritems[this.selected];

this.value =
    typeof itemValue === 'string'
        ? blessed.helpers.cleanTags(itemValue)
        : itemValue;

if (!this.parent) return;
this.scrollTo(this.selected);
fork icon0
star icon0
watch icon0