Moved MyYamlLexer into logger

now cmdline runs without pygments
master
Alexander Graf 4 years ago
parent ce9a9ec572
commit 9cb6962335

@ -53,34 +53,34 @@ def mapped(cls):
_model2schema[cls.Meta.model] = cls _model2schema[cls.Meta.model] = cls
return cls return cls
class MyYamlLexer(YamlLexer):
""" colorize yaml constants and integers """
def get_tokens(self, text, unfiltered=False):
for typ, value in super().get_tokens(text, unfiltered):
if typ is Token.Literal.Scalar.Plain:
if value in {'true', 'false', 'null'}:
typ = Token.Keyword.Constant
elif value == HIDDEN:
typ = Token.Error
else:
try:
int(value, 10)
except ValueError:
try:
float(value)
except ValueError:
pass
else:
typ = Token.Literal.Number.Float
else:
typ = Token.Literal.Number.Integer
yield typ, value
class Logger: class Logger:
""" helps with counting and colorizing """ helps with counting and colorizing
imported and exported data imported and exported data
""" """
class MyYamlLexer(YamlLexer):
""" colorize yaml constants and integers """
def get_tokens(self, text, unfiltered=False):
for typ, value in super().get_tokens(text, unfiltered):
if typ is Token.Literal.Scalar.Plain:
if value in {'true', 'false', 'null'}:
typ = Token.Keyword.Constant
elif value == HIDDEN:
typ = Token.Error
else:
try:
int(value, 10)
except ValueError:
try:
float(value)
except ValueError:
pass
else:
typ = Token.Literal.Number.Float
else:
typ = Token.Literal.Number.Integer
yield typ, value
def __init__(self, want_color=None, can_color=False, debug=False, secrets=False): def __init__(self, want_color=None, can_color=False, debug=False, secrets=False):
self.lexer = 'yaml' self.lexer = 'yaml'
@ -323,7 +323,7 @@ class Logger:
return data return data
lexer = lexer or self.lexer lexer = lexer or self.lexer
lexer = MyYamlLexer() if lexer == 'yaml' else get_lexer_by_name(lexer) lexer = Logger.MyYamlLexer() if lexer == 'yaml' else get_lexer_by_name(lexer)
formatter = get_formatter_by_name(formatter or self.formatter, colorscheme=self.colorscheme) formatter = get_formatter_by_name(formatter or self.formatter, colorscheme=self.colorscheme)
if strip is None: if strip is None:
strip = self.strip strip = self.strip

Loading…
Cancel
Save