XTerm 256 Colors

As of version 2.3.4, Rapture supports the 256-color extension to the ANSI colors standard, allowing a MUD server to send control codes to a user’s client to display more than the 16 standard ANSI colors.  XTerm-256 can be used simultaneously with the standard ANSI escape codes, and is also fully backwards compatible.  Sending 4 as the requested color (dim blue) to the client in either 256 mode or 16 mode will result in the client displaying the same color to the user.  Rapture will also automatically downconvert color codes to the 16-color mode if the user does not have 256-color mode enabled and game code attempts to send a 256-color code to a user.

More information about the 256-color standard can be found at http://www.mudpedia.org- /mediawiki- /index.php- /Xterm_256_colors

A useful reference showing the full pallette of colors available can be found at https://upload.wikimedia.org- /wikipedia- /en- /1- /15- /Xterm_256color_chart.svg, although full control of the specific shades of colors displayed will be determined by the user’s client.

Summary
As of version 2.3.4, Rapture supports the 256-color extension to the ANSI colors standard, allowing a MUD server to send control codes to a user’s client to display more than the 16 standard ANSI colors.
To enable support for 256 colors on a specific node, set node[].xterm256 to 1.
When a new node connects, Rapture automatically negotiates the terminal type (http://www.rfc-base.org/txt/rfc-1091.txt) of the user’s client, and stores all of the client’s replies in node[].ttype@.
While it is possible to send colored output to a node by manually crafting the escape sequence in game code, Rapture provides two recommended methods of displaying colored output.

Enabling 256-color mode

To enable support for 256 colors on a specific node, set node[].xterm256 to 1.  Rapture will then send all ANSI escape color codes using the extended commands.

Detecting support for 256 colors

Terminal Types

When a new node connects, Rapture automatically negotiates the terminal type (http://www.rfc-base.org/txt/rfc-1091.txt) of the user’s client, and stores all of the client’s replies in node[].ttype@.  You can check the entries in that vector for a ttype that is known to support 256 colors (such as something that ends in “-256color”.  Correctly identifying terminal types that support 256 colors will likely require some perusal of individual client documentation and experimentating.

User Configuration

Alternatively, the easier solution may be to allow a user to enable 256-color support via some configuration verb which manually sets node[].xterm256 to 1.

Sending colored output

While it is possible to send colored output to a node by manually crafting the escape sequence in game code, Rapture provides two recommended methods of displaying colored output.

Using node[].forecolor and node[].backcolor

Setting node[].forecolor and node[].backcolor on the built-in node database provides an easy way to set the desired color for any future text sent to that node.  An example

node[ply].forecolor = 226; (* Set the foreground color to bright yellow *)
node[ply].backcolor = 22; (* Set the background color to dark green *)
msgstr(ply, "Hello World!\n"); (* Send some colored text to the node *)

This usage is preferable if large blocks of text of a single color are going to be sent to a user.

Using ansicolor$()

Rapture has a built-in function that will construct an ANSI escape sequence that can then be sent to a node to instruct the client to change the color.  An example

local hello$, world$;
hello$ = ansicolor$(226, 22) + "Hello";
world$ = ansicolor$(88, 69) + "World!";
msgstr(ply, hello$ + " " + world$ + "\n");

This is preferable if the code changes the colors of some text frequently, or if one string must be constructed and sent to multiple nodes.