neo-blessed/README.md

111 lines
2.7 KiB
Markdown
Raw Normal View History

2013-01-27 16:06:58 +00:00
# blessed
A curses-like library for node.js.
2013-02-24 02:52:49 +00:00
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.
2013-01-27 17:14:06 +00:00
I want this library to eventually become a high-level library for terminal
widgets.
## Example Usage
2013-02-24 02:52:49 +00:00
This will actually parse the xterm terminfo and compile every
string capability to a javascript function:
``` js
var Tput = require('blessed').Tput
, tput = Tput('xterm');
2013-02-24 16:59:20 +00:00
console.log(tput.setaf(4) + 'hello' + tput.sgr0());
2013-02-24 02:52:49 +00:00
```
2013-02-24 18:14:12 +00:00
To play around with it on the command line, it works just like tput:
``` bash
$ tput.js setaf 2
$ tput.js sgr0
2013-02-24 18:53:37 +00:00
$ echo "$(tput.js setaf 2)hello world$(tput.js sgr0)"
2013-02-24 18:14:12 +00:00
```
The higher level functionality is exposed in the main `blessed` module:
2013-01-27 17:14:06 +00:00
``` js
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);
}
});
2013-01-27 17:14:06 +00:00
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);
2013-01-27 17:14:06 +00:00
}
program.move(data.x, data.y);
program.bg('red');
program.write(' ');
program.bg('!red');
2013-01-27 17:14:06 +00:00
});
program.on('focus', function() {
program.move(1, program.rows);
program.write('Gained focus.');
});
2013-01-27 17:14:06 +00:00
program.on('blur', function() {
program.move(1, program.rows);
program.write('Lost focus.');
2013-01-27 17:14:06 +00:00
});
program.alternateBuffer();
program.enableMouse();
program.hideCursor();
2013-01-27 17:14:06 +00:00
program.clear();
program.move(1, 1);
program.bg('black');
2013-01-27 18:33:32 +00:00
program.write('Hello world', 'blue fg');
program.setx((program.cols / 2 | 0) - 4);
2013-01-27 17:14:06 +00:00
program.down(5);
program.write('Hi again!');
program.bg('!black');
2013-01-27 17:14:06 +00:00
program.feed();
2013-01-27 17:33:04 +00:00
program.getCursor(function(err, data) {
if (!err) {
program.write('Cursor is at: ' + data.x + ', ' + data.y + '.');
program.feed();
2013-01-27 17:33:04 +00:00
}
2013-01-27 17:14:06 +00:00
program.charset('SCLD');
program.write('abcdefghijklmnopqrstuvwxyz0123456789');
program.charset('US');
program.setx(1);
2013-01-27 17:14:06 +00:00
});
```
2013-01-27 16:06:58 +00:00
## License
Copyright (c) 2013, Christopher Jeffrey. (MIT License)
See LICENSE for more info.