Package lyntin :: Module ansi
[show private | hide private]
[frames | no frames]

Module lyntin.ansi

This holds a series of classes and functions for helping to manipulate ANSI color codes.

In general, Lyntin keeps the data from the mud intact without doing any transformations on it letting the ui do the transformations it needs to do to display the mud data. The exception to this is when the user has shut off mudansi using the #config command. Then we'll whack any incoming ANSI color stuff before moving it around.
Function Summary
string convert_tuple_to_ansi(token)
Takes in a color tuple like what figure_color creates and converts it into an ANSI color sequence.
((int, int, int), string) figure_color(textlist, currentcolor, leftover)
Takes a textlist of text and color tokens and figures out the latest current color.
string filter_ansi(text)
Takes in text and filters out the ANSI color codes.
string fix_color(color)
Helper function for debugging--it'll fix a color token so it's readable in ascii.
string get_color(style)
Looks at the style (which is a comma separated list of styles) and figures out the markup string and returns it.
boolean is_color_token(token)
Returns whether or not this is a color token.
list of strings split_ansi_from_text(text)
Takes in a string and separates it into a list of strings and ansi color strings.

Variable Summary
SRE_Pattern ANSI_COLOR_REGEXP = \[[0-9;]*m
list DEFAULT_COLOR = [0, 0, 0, 0, -1, -1]
int PLACE_BG = 5                                                                     
int PLACE_BLINK = 2                                                                     
int PLACE_BOLD = 0                                                                     
int PLACE_FG = 4                                                                     
int PLACE_REVERSE = 3                                                                     
int PLACE_UNDERLINE = 1                                                                     
int STYLE_BLINK = 5                                                                     
int STYLE_BOLD = 1                                                                     
int STYLE_NORMAL = 0                                                                     
int STYLE_REVERSE = 7                                                                     
int STYLE_UNDERLINE = 4                                                                     
dict STYLEMAP = {'yellow': '33', 'blink': '5', 'light blue': ...

Function Details

convert_tuple_to_ansi(token)

Takes in a color tuple like what figure_color creates and converts it into an ANSI color sequence.
Parameters:
token - the color tuple
           (type=tuple of ints)
Returns:
the ANSI color string
           (type=string)

figure_color(textlist, currentcolor, leftover='')

Takes a textlist of text and color tokens and figures out the latest current color.
Parameters:
textlist - the list of string and ansi color code tokens
           (type=list of strings)
currentcolor - a tuple of (options, foreground, background) that represent the current color
           (type=(int, int, int))
leftover - if we encounter a half done color code, we throw it in the leftover string. the leftover gets prepended to the textlist element on the next run of figure_color
           (type=string)
Returns:
the new currentcolor and leftover as a tuple
           (type=((int, int, int), string))

filter_ansi(text)

Takes in text and filters out the ANSI color codes.
Returns:
text without ANSI color codes
           (type=string)

fix_color(color)

Helper function for debugging--it'll fix a color token so it's readable in ascii. It just replaces instances of chr(27) with "ESC".
Parameters:
color - the color token
           (type=string)
Returns:
the pretty string
           (type=string)

get_color(style)

Looks at the style (which is a comma separated list of styles) and figures out the markup string and returns it.
Parameters:
style - the style to retrieve markup for
           (type=text)
Returns:
the ansi code markup for the given style
           (type=string)

is_color_token(token)

Returns whether or not this is a color token. It figures this out by checking to see if the token matches this regexp: chr(27) + '\[[0-9;]*[m]'
Parameters:
token - the token in question
           (type=string)
Returns:
1 if it's color, 0 if not
           (type=boolean)

split_ansi_from_text(text)

Takes in a string and separates it into a list of strings and ansi color strings.
Parameters:
text - the full string to split up
           (type=string)
Returns:
list of text and ansi color tokens
           (type=list of strings)

Variable Details

ANSI_COLOR_REGEXP

Type:
SRE_Pattern
Value:
\[[0-9;]*m                                                            

DEFAULT_COLOR

Type:
list
Value:
[0, 0, 0, 0, -1, -1]                                                   

PLACE_BG

Type:
int
Value:
5                                                                     

PLACE_BLINK

Type:
int
Value:
2                                                                     

PLACE_BOLD

Type:
int
Value:
0                                                                     

PLACE_FG

Type:
int
Value:
4                                                                     

PLACE_REVERSE

Type:
int
Value:
3                                                                     

PLACE_UNDERLINE

Type:
int
Value:
1                                                                     

STYLE_BLINK

Type:
int
Value:
5                                                                     

STYLE_BOLD

Type:
int
Value:
1                                                                     

STYLE_NORMAL

Type:
int
Value:
0                                                                     

STYLE_REVERSE

Type:
int
Value:
7                                                                     

STYLE_UNDERLINE

Type:
int
Value:
4                                                                     

STYLEMAP

Type:
dict
Value:
{'b black': '40',
 'b blue': '44',
 'b cyan': '46',
 'b green': '42',
 'b magenta': '45',
 'b red': '41',
 'b white': '47',
 'b yellow': '43',
...                                                                    

Generated by Epydoc 2.1 on Mon Aug 9 09:17:42 2004 http://epydoc.sf.net