Docstring, comments and whitespace fixes

This commit is contained in:
BlauFeuer 2017-02-20 01:36:58 -05:00 committed by GitHub
parent 695cc4d218
commit dc1545cb27

View file

@ -5,12 +5,15 @@ Use the codes defined in ANSIPARSER in your text
to apply colour to text according to the ANSI standard. to apply colour to text according to the ANSI standard.
Examples: Examples:
This is %crRed text%cn and this is normal again. This is |rRed text|n and this is normal again.
This is {rRed text{n and this is normal again. This is {rRed text{n and this is normal again. # soon to be depreciated
This is %crRed text%cn and this is normal again. # depreciated
Mostly you should not need to call parse_ansi() explicitly; Mostly you should not need to call parse_ansi() explicitly;
it is run by Evennia just before returning data to/from the it is run by Evennia just before returning data to/from the
user. user. Depreciated example forms are available by extending
the ansi mapping.
""" """
from builtins import object, range from builtins import object, range
@ -143,9 +146,9 @@ class ANSIParser(object):
else: else:
# grayscale values (xterm indexes 0, 232-255, 15) for full spectrum # grayscale values (xterm indexes 0, 232-255, 15) for full spectrum
letter = rgbtag[int(background) + 1] letter = rgbtag[int(background) + 1]
if (letter == 'a'): if letter == 'a':
colval = 16 # pure black @ index 16 (first color cube entry) colval = 16 # pure black @ index 16 (first color cube entry)
elif (letter == 'z'): elif letter == 'z':
colval = 231 # pure white @ index 231 (last color cube entry) colval = 231 # pure white @ index 231 (last color cube entry)
else: else:
# letter in range [b..y] (exactly 24 values!) # letter in range [b..y] (exactly 24 values!)
@ -161,7 +164,7 @@ class ANSIParser(object):
colval = 16 + (red * 36) + (green * 6) + blue colval = 16 + (red * 36) + (green * 6) + blue
return "\033[%s8;5;%sm" % (3 + int(background), colval) return "\033[%s8;5;%sm" % (3 + int(background), colval)
# replaced since some cliens (like Potato) does not accept codes with leading zeroes, see issue #1024. # replaced since some clients (like Potato) does not accept codes with leading zeroes, see issue #1024.
# return "\033[%s8;5;%s%s%sm" % (3 + int(background), colval // 100, (colval % 100) // 10, colval%10) # return "\033[%s8;5;%s%s%sm" % (3 + int(background), colval // 100, (colval % 100) // 10, colval%10)
else: else:
@ -366,7 +369,7 @@ class ANSIParser(object):
(r'{[W', ANSI_BACK_WHITE), # light grey background (r'{[W', ANSI_BACK_WHITE), # light grey background
(r'{[X', ANSI_BACK_BLACK), # pure black background (r'{[X', ANSI_BACK_BLACK), # pure black background
## alternative |-format # alternative |-format
(r'|n', ANSI_NORMAL), # reset (r'|n', ANSI_NORMAL), # reset
(r'|/', ANSI_RETURN), # line break (r'|/', ANSI_RETURN), # line break
@ -433,8 +436,7 @@ class ANSIParser(object):
(r'{[w', r'{[555'), # white background (r'{[w', r'{[555'), # white background
(r'{[x', r'{[222'), # dark grey background (r'{[x', r'{[222'), # dark grey background
## |-style variations # |-style variations
(r'|[r', r'|[500'), (r'|[r', r'|[500'),
(r'|[g', r'|[050'), (r'|[g', r'|[050'),
(r'|[y', r'|[550'), (r'|[y', r'|[550'),
@ -450,11 +452,11 @@ class ANSIParser(object):
xterm256_map = [ xterm256_map = [
(r'\{[0-5]{3}', ""), # {123 - foreground colour (r'\{[0-5]{3}', ""), # {123 - foreground colour
(r'\{\[[0-5]{3}', ""), # {[123 - background colour (r'\{\[[0-5]{3}', ""), # {[123 - background colour
## |-style # |-style
(r'\|[0-5]{3}', ""), # |123 - foreground colour (r'\|[0-5]{3}', ""), # |123 - foreground colour
(r'\|\[[0-5]{3}', ""), # |[123 - background colour (r'\|\[[0-5]{3}', ""), # |[123 - background colour
## grayscale entries including ansi extremes: {=a .. {=z # grayscale entries including ansi extremes: {=a .. {=z
(r'\{=[a-z]', ""), (r'\{=[a-z]', ""),
(r'\{\[=[a-z]', ""), (r'\{\[=[a-z]', ""),
(r'\|=[a-z]', ""), (r'\|=[a-z]', ""),
@ -512,6 +514,7 @@ def strip_ansi(string, parser=ANSI_PARSER):
markup. markup.
Args: Args:
string (str): The string to strip.
parser (ansi.AnsiParser, optional): The parser to use. parser (ansi.AnsiParser, optional): The parser to use.
Returns: Returns:
@ -520,6 +523,7 @@ def strip_ansi(string, parser=ANSI_PARSER):
""" """
return parser.parse_ansi(string, strip_ansi=True) return parser.parse_ansi(string, strip_ansi=True)
def strip_raw_ansi(string, parser=ANSI_PARSER): def strip_raw_ansi(string, parser=ANSI_PARSER):
""" """
Remove raw ansi codes from string. This assumes pure Remove raw ansi codes from string. This assumes pure
@ -1129,7 +1133,6 @@ class ANSIString(with_metaclass(ANSIMeta, unicode)):
rstripped = rstripped[::-1] rstripped = rstripped[::-1]
return ANSIString(lstripped + raw[ir1:ir2+1] + rstripped) return ANSIString(lstripped + raw[ir1:ir2+1] + rstripped)
def lstrip(self, chars=None): def lstrip(self, chars=None):
""" """
Strip from the left, taking ANSI markers into account. Strip from the left, taking ANSI markers into account.