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.

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

mercurial