nodejs-ANSIBuffer is a chunked, escape code aware input/output buffer for use in BBS-like telnet programs. It's primary use it to provide a factory to mimic the delay that we were all used to in the old BBS days.
- Usage
- ANSIBuffer API
- ANSIChars
- ANSICenter
- ANSIRightAlign
- Backtick Color
- Status
- Contributors
- Compatibility
- Licence
var net = require('net');
var ansi = require('nodejs-ansibuffer');
var server = net.createServer(function(c) { //'connection' listener
console.log('server connected');
var outputBuffer = new ansi.ANSIBuffer();
var delayedWriter = setInterval(
function() {
var tmp = outputBuffer.bite();
if ( tmp !== false ) { c.write(tmp); }
}, 15);
// Set character mode (client side - do not wait for CR-LF)
c.write(String.fromCharCode(255) + String.fromCharCode(253) + String.fromCharCode(34),'ascii');
// No local (client-side) echo
c.write(String.fromCharCode(255) + String.fromCharCode(251) + String.fromCharCode(1),'ascii');
outputBuffer.queue(" `9W`1elcome `9T`1o `9ANSIB`1uffer `2!!");
});
server.listen(8124, function() { //'listening' listener
console.log('server bound');
});
To create a new buffer, import the module, and create a new ANSIBuffer() object.
var ansi = require('nodejs-ansibuffer');
var buffer = new ansi.ANSIBuffer();
Returns the full contents of the buffer, while emptying it.
Returns an inteligent "chunk" of the buffer, of variable length. Great pains are taken to never "break" an ANSI control sequence - odd things happen when there is a manufactured delay in these - well, sometimes anyway.
Empty the buffer, drop all the contents.
Queue text for display. This can be plain text, a string containing full escape codes, or a string containing "Legend of the Red Dragon" backtick codes.
Queue text for display (same as above) - But center it on an 80 column screen. If not specified, defaults to a TERM width of 80.
This is an object that contains some well-used high-ASCII characters, reimagined in unicode.
- A176 - ░ - Light Shade
- A177 - ▒ - Medium Shade
- A178 - ▓ - Dark Shade
- A219 - █ - Full Fill
- A220 - ▄ - Bottom Half Box
- A221 - ▌ - Left Half Box
- A222 - ▐ - Right Half Box
- A223 - ▀ - Top Half Box
- A254 - ▪ - Center Square
- ESC - Escape Sequence Start "{ESC}["
This is a function that allows you to center an ANSI string prior to queueing it.
This is a function that allows you to right-align an ANSI string prior to queueing it. Column can be either "absolute" (default), or based on the rest of the line.
a/n: Absolute method moves to the named column, then backs up the length of the string. Relative method "spaces" over that many columns, then backs up the length of the string.
These are the backtick color codes based on how the Legend of the Red Dragon did things.
- `1 : Dark Red
- `2 : Dark Green
- `3 : Dark Yellow or Brown (depends on terminal)
- `4 : Dark Blue
- `5 : Dark Magenta or Purple (depends on terminal)
- `6 : Dark Cyan
- `7 : Light Grey (a.k.a. Dark White) (a.k.a. Normal)
- `8 : Dark Grey (a.k.a. Light Black)
- `9 : Bright Red
- `0 : Bright Green
- `! : Bright Yellow
- `@ : Bright Blue
- `# : Bright Magenta
- `$ : Bright Cyan
- `% : Bright White
- `. : Reset to TERM Default
Note the lack of dark grey. This is an issue with the default colors on the mac terminal. (taken from iTerm - terminal.app is even worse)
Taken in terminator. gnome-terminal is comparable
This module is in a development stage. It's probably broken horribly in places - not sure.
This module was only tested using node >= 0.8.8. There is no reason it shouldn't run under earlier versions though.
node-ansibuffer is licensed under the MIT license. Or the BSD license. Or no license if that's more convient for you.