lib.cuckoo.common.colors

Package lib :: Package cuckoo :: Package common :: Module colors |
[hide private]
[frames] | no frames]

# Source Code for Module lib.cuckoo.common.colors

     1  # Copyright (C) 2010-2013 Claudio Guarnieri.
     2  # Copyright (C) 2014-2016 Cuckoo Foundation.
     3  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
     4  # See the file 'docs/LICENSE' for copying permission.
     5
     6  import os
     7  import sys
     8
     9 -def color(text, color_code):
    10      """Colorize text.
    11      @param text: text.
    12      @param color_code: color.
    13      @return: colorized text.
    14      """
    15      # $TERM under Windows:
    16      # cmd.exe -> "" (what would you expect..?)
    17      # cygwin -> "cygwin" (should support colors, but doesn't work somehow)
    18      # mintty -> "xterm" (supports colors)
    19      if sys.platform == "win32" and os.getenv("TERM") != "xterm":
    20          return text
    21      return "\x1b[%dm%s\x1b[0m" % (color_code, text)
    22
    23 -def black(text):
    24      return color(text, 30)
    25
    26 -def red(text):
    27      return color(text, 31)
    28
    29 -def green(text):
    30      return color(text, 32)
    31
    32 -def yellow(text):
    33      return color(text, 33)
    34
    35 -def blue(text):
    36      return color(text, 34)
    37
    38 -def magenta(text):
    39      return color(text, 35)
    40
    41 -def cyan(text):
    42      return color(text, 36)
    43
    44 -def white(text):
    45      return color(text, 37)
    46
    47 -def bold(text):
    48      return color(text, 1)
    49