1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/lib/terminal_unix.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,37 @@ 1.4 +import sys 1.5 + 1.6 +class Terminal(object): 1.7 + COLOR = { 1.8 + 'red': '31', 1.9 + 'green': '32', 1.10 + 'blue': '34', 1.11 + 'gray': '37' 1.12 + } 1.13 + NORMAL_INTENSITY = '1' 1.14 + BRIGHT_INTENSITY = '2' 1.15 + ESCAPE = '\x1b[' 1.16 + RESET = '0' 1.17 + SEPARATOR = ';' 1.18 + COLOR_CODE = 'm' 1.19 + CLEAR_RIGHT_CODE = 'K' 1.20 + 1.21 + @classmethod 1.22 + def set_color(cls, color): 1.23 + """ 1.24 + color: str - color definition string 1.25 + """ 1.26 + mod = Terminal.NORMAL_INTENSITY 1.27 + if color.startswith('bright'): 1.28 + mod = Terminal.BRIGHT_INTENSITY 1.29 + color = color[len('bright'):] 1.30 + color_code = Terminal.COLOR[color] 1.31 + 1.32 + sys.stdout.write(cls.ESCAPE + color_code + cls.SEPARATOR + mod + cls.COLOR_CODE) 1.33 + 1.34 + @classmethod 1.35 + def reset_color(cls): 1.36 + sys.stdout.write(cls.ESCAPE + cls.RESET + cls.COLOR_CODE) 1.37 + 1.38 + @classmethod 1.39 + def clear_right(cls): 1.40 + sys.stdout.write(cls.ESCAPE + cls.CLEAR_RIGHT_CODE)