Try any Node.js package right in your browser

Share this code:

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including nodejs-ansibuffer with all npm packages installed. Try it out:

nodejs-ansibuffer v0.0.5

Escape code aware (ANSI), chunked, input/output buffer

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.

ANSIBuffer() API

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.