js/src/tests/lib/terminal_unix.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 import sys
michael@0 2
michael@0 3 class Terminal(object):
michael@0 4 COLOR = {
michael@0 5 'red': '31',
michael@0 6 'green': '32',
michael@0 7 'blue': '34',
michael@0 8 'gray': '37'
michael@0 9 }
michael@0 10 NORMAL_INTENSITY = '1'
michael@0 11 BRIGHT_INTENSITY = '2'
michael@0 12 ESCAPE = '\x1b['
michael@0 13 RESET = '0'
michael@0 14 SEPARATOR = ';'
michael@0 15 COLOR_CODE = 'm'
michael@0 16 CLEAR_RIGHT_CODE = 'K'
michael@0 17
michael@0 18 @classmethod
michael@0 19 def set_color(cls, color):
michael@0 20 """
michael@0 21 color: str - color definition string
michael@0 22 """
michael@0 23 mod = Terminal.NORMAL_INTENSITY
michael@0 24 if color.startswith('bright'):
michael@0 25 mod = Terminal.BRIGHT_INTENSITY
michael@0 26 color = color[len('bright'):]
michael@0 27 color_code = Terminal.COLOR[color]
michael@0 28
michael@0 29 sys.stdout.write(cls.ESCAPE + color_code + cls.SEPARATOR + mod + cls.COLOR_CODE)
michael@0 30
michael@0 31 @classmethod
michael@0 32 def reset_color(cls):
michael@0 33 sys.stdout.write(cls.ESCAPE + cls.RESET + cls.COLOR_CODE)
michael@0 34
michael@0 35 @classmethod
michael@0 36 def clear_right(cls):
michael@0 37 sys.stdout.write(cls.ESCAPE + cls.CLEAR_RIGHT_CODE)

mercurial