Color Functions - fiendish/aardwolfclientpackage GitHub Wiki

(aardwolf_colors.lua)

This file is not a plugin. It is a lua snippet file that provides functions for handling Aardwolf color codes to any plugin that wants to use them.

How do I use this in a plugin?

Either call this first:

dofile(GetInfo(60).."aardwolf_colors.lua")

or this (which is simpler but slightly less good in a few obscure scenarios):

require "aardwolf_colors.lua"

Then use the provided functions as if they were part of your plugin.

What functions does it provide?

StylesToColours (styles)

Converts a table of MUSHclient style runs into a string containing Aardwolf color codes.

TruncateStyles (styles, start_index, end_index)

Returns a new styles table with any text before start_index and after end_index removed. Negative character indices will count back from the end, with -1 being the last character.b

ColoursToStyles (text)

The reverse of StylesToColours. This takes a string containing Aardwolf color codes and generates a sequence of MUSHclient style runs.

strip_colours (text)

Takes a string containing Aardwolf color codes and removes all of the color codes from it.

strip_colours_from_styles (styles)

Returns a string representing just the bare text from a style table.

canonicalize_colours (text)

Convert all color codes to 3 digit "@x" codes

stylesToANSI (styles, dollarC_resets)

Converts a series of style runs to a string with embedded ansi codes. Set dollarC_resets to true if you want "$C" in the text of a style to set the color to the previous color code.

AnsiToColours (ansi)

Takes a string and converts embedded ansi color codes into Aardwolf "@" codes.

ColoursToANSI (text)

Takes a string and converts embedded Aardwolf "@" codes into ansi color codes.

partition_boundaries (styles, separator_pattern)

Takes a table of styles and repartitions them at separator boundaries. For example, if the separator pattern is "%s+" for one or more spaces, the result would be {{nonspace styles},{space styles},{nonspace styles},...}

Will this handle xterm 256 colors?

Yes it will in all versions after r397.

Why do you use both the American and British spellings of "color"?

Because screw you, that's why!

Why dofile instead of the cleaner require?

Purely hysterical raisins.

Why don't the function names follow a consistent pattern?

See the above two answers.