How to use blessed

Comprehensive blessed code examples:

How to use blessed.Program:

1
2
3
4
5
6
7
8
9
10
patchBlessed()
var contrib = require('blessed-contrib');
var _ = require('lodash');

function patchBlessed() {
  blessed.Program.prototype.listen = function() {}
  process.on = function() {}
}

exports.register = function (server, options, next) {

How to use blessed.Element:

1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
    this.renderCoords = coords;


    return coords;
};


blessed.Element.prototype._render = blessed.Element.prototype.render;


/*
    Make .hidden a bit more robust by checking immediate parent, so it's viable to
    use in place of .visible (which recurses up the node tree on every execution)

How to use blessed.clear:

369
370
371
372
373
374
375
376
377
378

const cli = require('blessed').program();

cli.on('keypress', function(ch, evt) {
    if (ch === 'q' || ch === 'Q') {
        cli.clear();
        cli.cursorShape('block');
        cli.normalBuffer();
        if (ch === 'q') {
            // We exited gracefully, it's fine

How to use blessed.unicode:

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;

How to use blessed.Table:

54
55
56
57
58
59
60
61
62
63
  content: 'q - Quit\nz - Zero/Tare'
});

screen.append(helpBox);

let dataTable = blessed.Table({
  bottom: 1,
  right: 0,
  width: 19,
  height: 'shrink',

How to use blessed.Listbar:

79
80
81
82
83
84
85
86
87
88

Screen.key('1', showMethods);
Screen.key('2', showHeaders);
Screen.key('3', showBody);

var menuBar = Blessed.Listbar({
  top: 0,
  height: 3,
  width: '100%',
  keys: true,

How to use blessed.Log:

53
54
55
56
57
58
59
60
61
62
                        fg: 'grey'
                }
        }
})

let displayLogContent = blessed.Log({
        parent: displayLog,
        top: 0,
        left: 0,
        // width: '100%',

How to use blessed.cleanTags:

158
159
160
161
162
163
164
165
166
167
      else name = name + '{|}Last Seen {grey-fg}'+moment(online_expires).fromNow()+'{/grey-fg}'
  } else if(f === 'label'){
    name = 'to ' + name
  }
  if(f) return name
  return blessed.cleanTags(name)
}

data.escapeFromList = function(txt){
  return blessed.stripTags(txt.text || txt.content || String(text)).replace('* ','')

How to use blessed.ListTable:

527
528
529
530
531
532
533
534
535
536
537
        height: screen.height - 3,
    },
});


let branches = [];
let branchList = blessed.ListTable({
    parent: remotetMenu,
    mouse: true,
    keys: true,
    vi: true,

How to use blessed.ScrollableBox:

How to use blessed.Loading:

198
199
200
201
202
203
204
205
206
207
    style: data.getDefaultStyle()
  }
}

// Widget used to show loading windows
data.loader = blessed.Loading(data.getDefaultPopupStyle())
data.screen.append(data.loader)
data.load = function(msg){
  data.loader.stop()
  data.loader.load(msg)

How to use blessed.ANSIImage:

320
321
322
323
324
325
326
327
328
329
330
        }
    }
});


//  Image of each part
var partPic = blessed.ANSIImage({
    // Halfway to the right minus half the image's width
    left: '50%-14',
    top: 1,
    scale: 1,

How to use blessed.normalBuffer:

371
372
373
374
375
376
377
378
379
380

cli.on('keypress', function(ch, evt) {
    if (ch === 'q' || ch === 'Q') {
        cli.clear();
        cli.cursorShape('block');
        cli.normalBuffer();
        if (ch === 'q') {
            // We exited gracefully, it's fine
            require('fs').unlinkSync(logFile);
        }

How to use blessed.escape:

105
106
107
108
109
110
111
112
113
114
  keyable: false,
  tags: true,
  content:
    `{bold}${blessed.escape(story.name || "")}{/bold}\n\n` +
    labels +
    blessed.escape(story.description || ""),
  style: theme.TEXT_STYLING
});
const controlBar = blessed.box({
  parent: infoScreen,

How to use blessed.BigText:

17
18
19
20
21
22
23
24
25
26
  style: {
    bg: 'cyan-bg'
  }
})

let box = blessed.BigText({
  top: 0,
  right: 0,
  width: 'shrink',
  height: 'shrink',

How to use blessed.cursorShape:

370
371
372
373
374
375
376
377
378
379
const cli = require('blessed').program();

cli.on('keypress', function(ch, evt) {
    if (ch === 'q' || ch === 'Q') {
        cli.clear();
        cli.cursorShape('block');
        cli.normalBuffer();
        if (ch === 'q') {
            // We exited gracefully, it's fine
            require('fs').unlinkSync(logFile);

How to use blessed.Message:

49
50
51
52
53
54
55
56
57
this.context.room.on('joinError', function (err) {
  // Log the error.
  logger.error('There was an error joining the room.');

  // Create a new blessed message box instance.
  var message = Blessed.Message();

  // Remove the loading screen.
  self.loading.stop();

How to use blessed.Prompt:

How to use blessed.parseTags:

175
176
177
178
179
180
181
182
183
184
185
186
        screen.render();
      });
    }
  });


  nodeBox.setLine(1, blessed.parseTags('{#000033-fg}>{/#000033-fg} ' + family));


  screen.render();
});

How to use blessed.tput:

3
4
5
6
7
8
9
10
11
string capability to a javascript function:

``` js
var blessed = require('blessed');

var tput = blessed.tput({
  terminal: 'xterm-256color',
  extended: true
});

How to use blessed.scrollablebox:

180
181
182
183
184
185
186
187
188
189
  }
  return ret;
};

// This fix prevents crashing, when view is removed from parent during before nextTick call.
const _setScrollPerc = blessed.scrollablebox.prototype.setScrollPerc;
blessed.scrollablebox.prototype.setScrollPerc = function (percent) {
  if (this.parent) {
    _setScrollPerc.call(this, percent);
  }

How to use blessed.FileManager:

12
13
14
15
16
17
18
19
20
21

opts = _(Slap.global.options.fileBrowser).merge({
  focusable: true
}).merge(opts || {}).toObject();
BaseElement.call(self, opts);
blessed.FileManager.call(self, _({
  keys: true,
  mouse: true
}).merge(opts).toObject());
self.refresh();

How to use blessed.bigtext:

108
109
110
111
112
113
114
115
116
117
// Append our box to the screen.
screen.append(awayBox);
screen.append(homeBox);

// Create a box perfectly centered horizontally and vertically.
const teamBox = blessed.bigtext({
  font: __dirname + '/../fonts/ter-u12n.json',
  fontBold: __dirname + '/../fonts/ter-u12b.json',
  top: 0,
  left: '70%',

How to use blessed.Button:

43
44
45
46
47
48
49
50
51
52
    },
    inputOnFocus: true,
    mouse: true,
});

const save = new Button({
    parent: prompt,
    width: 'shrink',
    height: 1,
    mouse: true,

How to use blessed.Line:

58
59
60
61
62
63
64
65
66
67
  keys: true,
  vi: true,
  mouse: true
})

blessed.Line({
  parent: consoleContainer,
  type: 'line',
  orientation: 'horizontal',
  top: '100%-5',

How to use blessed.stripTags:

162
163
164
165
166
167
168
169
170
171
  if(f) return name
  return blessed.cleanTags(name)
}

data.escapeFromList = function(txt){
  return blessed.stripTags(txt.text || txt.content || String(text)).replace('* ','')
}

data.nameToObj = function(name){
  var id = data.gnameToGid[name]

How to use blessed.question:

17
18
19
20
21
22
23
24
25
26
list    = blessed.list(styles.list);
menubar = blessed.listbar(styles.menubar);

styles.confirm.parent = screen;

confirm = blessed.question(styles.confirm);

return {
  layout : layout,
  list   : list,

How to use blessed.ansiimage:

58
59
60
61
62
63
64
65
66
67
68
	top: '96%',
	left: '1%',
	content: `Version ${ceta.util.version}`
});


const whale = blessed.ansiimage({
	parent: screen,
	top: 1,
	left: `center`,
	file: 'whale.png',

How to use blessed.with:

27
28
29
30
31
32
33
34
35
36
super();
let current_namespace, pod_selected, container_selected, pods_list = {};
const cancellations = new task.Cancellations();
const dashboard = this;

const pods_table = blessed.with(focusIndicator, scroll, throttle).listtable({
  label  : 'Pods',
  parent : screen,
  left   : 0,
  top    : 1,