1 # Copyright 2020 The Pigweed Authors
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
14 """Defines ANSI color codes."""
20 def _make_color(*codes):
21 # Apply all the requested ANSI color codes. Note that this is unbalanced
22 # with respect to the reset, which only requires a '0' to erase all codes.
23 start = ''.join('\033[{}m'.format(code) for code in codes)
26 return staticmethod(lambda msg: u'{}{}{}'.format(start, msg, reset))
29 class Color: # pylint: disable=too-few-public-methods
30 """Helpers to surround text with ASCII color escapes"""
33 bold_red = _make_color(31, 1)
34 green = _make_color(32)
35 magenta = _make_color(35, 1)
40 kernel32 = ctypes.windll.kernel32
41 kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)