Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Escape code aware (ANSI) chunked input/output buffer (BBS like - for telnet)
Branch: master
Failed to load latest commit information.
screens Version to 0.0.4, add Right Justify option. Clean up some stuff
tests Put the backtick dot (.) code back in
.npmignore Put the backtick dot (.) code back in
ansibuffer.js Put the backtick dot (.) code back in
package.json Put the backtick dot (.) code back in



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.



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

ANSIBuffer() API

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.

ANSIBuffer.queue( text )

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. text, [width] )

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

ANSICenter(text, [width]);

This is a function that allows you to center an ANSI string prior to queueing it.

ANSIRightAlign(text, column, [absolute]);

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.

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
  • `. : Reset to TERM Default

Mac Defaults:

Note the lack of dark grey. This is an issue with the default colors on the mac terminal. (taken from iTerm - is even worse)

Mac Color Options

Linux Defaults:

Taken in terminator. gnome-terminal is comparable

Linux Color Options

Current status

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.

Something went wrong with that request. Please try again.