nodejs-ansibuffer

0.0.5 • Public • Published

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

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( 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.

ANSIBuffer.center( 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.

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

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 - terminal.app 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.

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.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i nodejs-ansibuffer

      Weekly Downloads

      1

      Version

      0.0.5

      License

      BSD

      Last publish

      Collaborators

      • jtsage