How to use the unicode function from blessed

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

blessed.unicode is a module that provides Unicode box-drawing characters for use in creating user interfaces with the blessed terminal interface library.

203
204
205
206
207
208
209
210
211
    instead of re-writing Blessed's unicode handling stuff (a huge pain),
    I just added a flag to the Terminal's cells (index 2), to indicate combo/double width characters.
*/
if (this.fullUnicode) {
    if (
        blessed.unicode.charWidth(line[x][1]) === 2 ||
        uni === true
    ) {
        line[x].length = 2;
fork icon0
star icon0
watch icon1

455
456
457
458
459
460
461
462
463
464
    }
    continue;
}

if (this.screen.fullUnicode && content[ci - 1]) {
    var point = blessed.unicode.codePointAt(content, ci - 1);
    // Handle combining chars:
    // Make sure they get in the same cell and are counted as 0.
    if (blessed.unicode.combining[point]) {
        if (point > 0x00ffff) {
fork icon0
star icon0
watch icon1

How does blessed.unicode work?

blessed.unicode is a module that provides an object with various properties containing Unicode box-drawing characters. These characters can be used to draw lines and boxes in a terminal-based user interface created with the blessed library. For example, the blessed.unicode.rightDouble property contains the Unicode character for a double-line right border character (╣), which could be used to draw a double-lined box.

The module provides a range of different box-drawing characters for different styles of boxes and lines, including single and double lines, corners, T-junctions, and crosses. By using these characters in conjunction with the blessed library's cursor positioning and color capabilities, it's possible to create rich, interactive user interfaces in the terminal.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const blessed = require("blessed");
const { unicode } = require("blessed");

const screen = blessed.screen();

const box = blessed.box({
  top: "center",
  left: "center",
  width: 40,
  height: 10,
  border: {
    type: "line",
    fg: "white",
    bg: "black",
    // use double-line box drawing characters
    // from blessed.unicode module
    left: unicode.leftDouble,
    right: unicode.rightDouble,
    top: unicode.topDouble,
    bottom: unicode.bottomDouble,
    topLeft: unicode.topLeftDouble,
    topRight: unicode.topRightDouble,
    bottomLeft: unicode.bottomLeftDouble,
    bottomRight: unicode.bottomRightDouble,
  },
  content: "Hello, world!",
});

screen.append(box);

screen.key(["escape", "q", "C-c"], function (ch, key) {
  return process.exit(0);
});

screen.render();

In this example, we're creating a blessed user interface that contains a single box element. We're using the blessed.unicode module to specify double-lined box-drawing characters for the box's border, and setting the type, fg, and bg properties to create a bordered box with a white foreground color and black background color. Finally, we're appending the box to the screen, setting up a handler for the escape, q, and C-c keys to exit the program, and calling screen.render() to render the interface on the terminal. By using blessed.unicode to draw a double-lined box, we've created a visually interesting element in our blessed user interface. We've used the various box-drawing characters provided by the module to draw lines and corners in a double-lined style, and specified the appearance of the box with the type, fg, and bg properties of the border.