mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Merge "Pylint and PEP8 fixes for color.py"
This commit is contained in:
commit
4214585073
16
color.py
16
color.py
@ -36,15 +36,17 @@ ATTRS = {None :-1,
|
|||||||
'blink': 5,
|
'blink': 5,
|
||||||
'reverse': 7}
|
'reverse': 7}
|
||||||
|
|
||||||
RESET = "\033[m" # pylint: disable=W1401
|
RESET = "\033[m"
|
||||||
# backslash is not anomalous
|
|
||||||
|
|
||||||
def is_color(s):
|
def is_color(s):
|
||||||
return s in COLORS
|
return s in COLORS
|
||||||
|
|
||||||
|
|
||||||
def is_attr(s):
|
def is_attr(s):
|
||||||
return s in ATTRS
|
return s in ATTRS
|
||||||
|
|
||||||
|
|
||||||
def _Color(fg=None, bg=None, attr=None):
|
def _Color(fg=None, bg=None, attr=None):
|
||||||
fg = COLORS[fg]
|
fg = COLORS[fg]
|
||||||
bg = COLORS[bg]
|
bg = COLORS[bg]
|
||||||
@ -52,7 +54,7 @@ def _Color(fg = None, bg = None, attr = None):
|
|||||||
|
|
||||||
if attr >= 0 or fg >= 0 or bg >= 0:
|
if attr >= 0 or fg >= 0 or bg >= 0:
|
||||||
need_sep = False
|
need_sep = False
|
||||||
code = "\033[" #pylint: disable=W1401
|
code = "\033["
|
||||||
|
|
||||||
if attr >= 0:
|
if attr >= 0:
|
||||||
code += chr(ord('0') + attr)
|
code += chr(ord('0') + attr)
|
||||||
@ -71,7 +73,6 @@ def _Color(fg = None, bg = None, attr = None):
|
|||||||
if bg >= 0:
|
if bg >= 0:
|
||||||
if need_sep:
|
if need_sep:
|
||||||
code += ';'
|
code += ';'
|
||||||
need_sep = True
|
|
||||||
|
|
||||||
if bg < 8:
|
if bg < 8:
|
||||||
code += '4%c' % (ord('0') + bg)
|
code += '4%c' % (ord('0') + bg)
|
||||||
@ -82,9 +83,9 @@ def _Color(fg = None, bg = None, attr = None):
|
|||||||
code = ''
|
code = ''
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
DEFAULT = None
|
DEFAULT = None
|
||||||
|
|
||||||
|
|
||||||
def SetDefaultColoring(state):
|
def SetDefaultColoring(state):
|
||||||
"""Set coloring behavior to |state|.
|
"""Set coloring behavior to |state|.
|
||||||
|
|
||||||
@ -145,6 +146,7 @@ class Coloring(object):
|
|||||||
def printer(self, opt=None, fg=None, bg=None, attr=None):
|
def printer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
s = self
|
s = self
|
||||||
c = self.colorer(opt, fg, bg, attr)
|
c = self.colorer(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt, *args):
|
def f(fmt, *args):
|
||||||
s._out.write(c(fmt, *args))
|
s._out.write(c(fmt, *args))
|
||||||
return f
|
return f
|
||||||
@ -152,6 +154,7 @@ class Coloring(object):
|
|||||||
def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
|
def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
s = self
|
s = self
|
||||||
c = self.nofmt_colorer(opt, fg, bg, attr)
|
c = self.nofmt_colorer(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt):
|
def f(fmt):
|
||||||
s._out.write(c(fmt))
|
s._out.write(c(fmt))
|
||||||
return f
|
return f
|
||||||
@ -159,11 +162,13 @@ class Coloring(object):
|
|||||||
def colorer(self, opt=None, fg=None, bg=None, attr=None):
|
def colorer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
if self._on:
|
if self._on:
|
||||||
c = self._parse(opt, fg, bg, attr)
|
c = self._parse(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt, *args):
|
def f(fmt, *args):
|
||||||
output = fmt % args
|
output = fmt % args
|
||||||
return ''.join([c, output, RESET])
|
return ''.join([c, output, RESET])
|
||||||
return f
|
return f
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def f(fmt, *args):
|
def f(fmt, *args):
|
||||||
return fmt % args
|
return fmt % args
|
||||||
return f
|
return f
|
||||||
@ -171,6 +176,7 @@ class Coloring(object):
|
|||||||
def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
|
def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
if self._on:
|
if self._on:
|
||||||
c = self._parse(opt, fg, bg, attr)
|
c = self._parse(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt):
|
def f(fmt):
|
||||||
return ''.join([c, fmt, RESET])
|
return ''.join([c, fmt, RESET])
|
||||||
return f
|
return f
|
||||||
|
Loading…
Reference in New Issue
Block a user