Skip to content
Escape code aware (ANSI) chunked input/output buffer (BBS like - for telnet)
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
README.md
ansibuffer.js
package.json
test.js

README.md

ANSIBuffer

Purpose

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.

TOC

Usage

var net = require('net');
var ansi = require('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); } 
        }, 5);

    // 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');

    outpurBuffer.queue(" `9W`1welcome `9T`1o `9ANSIB`1uffer `2!!");
});
server.listen(8124, function() { //'listening' listener
    console.log('server bound');
});

ANSIBuffer() API

To create a new buffer, import the module, and create a new ANSIBuffer() object.

var ansi = require('ansibuffer');
var buffer = new ansi.ANSIBuffer();

ANSIBuffer.dump()

Returns the full contents of the buffer, while emptying it.

ANSIBuffer.bite()

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.

ANSIBuffer.clear()

Empty the buffer, drop all the contents.

ANSIBuffer.queue()

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. (see below)

ANSIChars

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}["

Backtick Color

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

Current status

This module is in a development stage. It's probably broken horribly in places - not sure.

Contributors

Compatibility

This module was only tested using node >= 0.8.8. There is no reason it shouldn't run under earlier versions though.

Licence

node-ansibuffer is licensed under the MIT license. Or the BSD license. Or no license if that's more convient for you.

Something went wrong with that request. Please try again.