A drop-in replacement for for Blessed. A high-level terminal interface library for node.js.
Go to file
Christopher Jeffrey 1d37b2b6e2 reorganize 2013-06-03 20:33:08 -05:00
bin bin, readme. 2013-02-24 12:53:37 -06:00
example move tput test. 2013-02-24 20:58:08 -06:00
lib reorganize 2013-06-03 20:33:08 -05:00
test reorganize 2013-06-03 20:33:08 -05:00
usr add xterm-256color terminfo. 2013-03-06 04:28:03 -06:00
LICENSE readme. license. 2013-01-27 10:06:58 -06:00
README.md bin, readme. 2013-02-24 12:53:37 -06:00
index.js initial 2013-01-27 04:30:52 -06:00
package.json v0.0.6 2013-03-06 04:53:39 -06:00

README.md

blessed

A curses-like library for node.js.

Blessed was originally written to only support the xterm terminfo, but can now parse and compile any terminfo to be completely portable accross all terminals. See the tput example below.

I want this library to eventually become a high-level library for terminal widgets.

Example Usage

This will actually parse the xterm terminfo and compile every string capability to a javascript function:

var Tput = require('blessed').Tput
  , tput = Tput('xterm');

console.log(tput.setaf(4) + 'hello' + tput.sgr0());

To play around with it on the command line, it works just like tput:

$ tput.js setaf 2
$ tput.js sgr0
$ echo "$(tput.js setaf 2)hello world$(tput.js sgr0)"

The higher level functionality is exposed in the main blessed module:

var blessed = require('blessed')
  , program = blessed();

program.on('keypress', function(ch, key) {
  if (key.name === 'q') {
    program.clear();
    program.disableMouse();
    program.showCursor();
    program.normalBuffer();
    process.exit(0);
  }
});

program.on('mouse', function(data) {
  if (data.action === 'mouseup') return;
  program.move(1, program.rows);
  program.eraseInLine('right');
  if (data.action === 'wheelup') {
    program.write('Mouse wheel up at: ' + data.x + ', ' + data.y);
  } else if (data.action === 'wheeldown') {
    program.write('Mouse wheel down at: ' + data.x + ', ' + data.y);
  } else if (data.action === 'mousedown' && data.button === 'left') {
    program.write('Left button down at: ' + data.x + ', ' + data.y);
  } else if (data.action === 'mousedown' && data.button === 'right') {
    program.write('Right button down at: ' + data.x + ', ' + data.y);
  } else {
    program.write('Mouse at: ' + data.x + ', ' + data.y);
  }
  program.move(data.x, data.y);
  program.bg('red');
  program.write(' ');
  program.bg('!red');
});

program.on('focus', function() {
  program.move(1, program.rows);
  program.write('Gained focus.');
});

program.on('blur', function() {
  program.move(1, program.rows);
  program.write('Lost focus.');
});

program.alternateBuffer();
program.enableMouse();
program.hideCursor();
program.clear();

program.move(1, 1);
program.bg('black');
program.write('Hello world', 'blue fg');
program.setx((program.cols / 2 | 0) - 4);
program.down(5);
program.write('Hi again!');
program.bg('!black');
program.feed();

program.getCursor(function(err, data) {
  if (!err) {
    program.write('Cursor is at: ' + data.x + ', ' + data.y + '.');
    program.feed();
  }

  program.charset('SCLD');
  program.write('abcdefghijklmnopqrstuvwxyz0123456789');
  program.charset('US');
  program.setx(1);
});

License

Copyright (c) 2013, Christopher Jeffrey. (MIT License)

See LICENSE for more info.