'Prints a text on the screen.
It uses sys.stdout.write(), so no readline library is necessary.
Parameters
color : choose from the colors below, "" means default color
align : "left"/"right", "left" is a normal print, "right" is aligned on
the right-hand side of the screen, filled with spaces if
necessary
width : the screen width'

def write(self, text, color='', align='left', width=None, force_colors=False):

    color_templates = (('Black', '0;30'), ('Red', '0;31'), ('Green', '0;32'), ('Brown', '0;33'), ('Blue', '0;34'), ('Purple', '0;35'), ('Cyan', '0;36'), ('LightGray', '0;37'), ('DarkGray', '1;30'), ('LightRed', '1;31'), ('LightGreen', '1;32'), ('Yellow', '1;33'), ('LightBlue', '1;34'), ('LightPurple', '1;35'), ('LightCyan', '1;36'), ('White', '1;37'))
    colors = {}
    for (name, value) in color_templates:
        colors[name] = value
    c_normal = '\x1b[0m'
    c_color = '\x1b[%sm'
    if (width is None):
        width = self.terminal_width
    if (align == 'right'):
        if ((self._write_pos + len(text)) > width):
            self.write('\n')
        self.write(('    ' * ((width - self._write_pos) - len(text))))
    if ((not self._force_colors) and hasattr(sys.stdout, 'isatty') and (not sys.stdout.isatty())):
        color = ''
    elif (sys.platform == 'win32'):
        color = ''
    elif (not self._colors):
        color = ''
    if self._line_wrap:
        if (text[0] != '\n'):
            sys.stdout.write('\n')
    if (PY3 and IS_WINDOWS):
        text = text.encode('raw_unicode_escape').decode('utf8', 'ignore')
    elif (PY3 and (not sys.stdout.encoding.lower().startswith('utf'))):
        text = text.encode(sys.stdout.encoding, 'backslashreplace').decode(sys.stdout.encoding)
    if (color == ''):
        sys.stdout.write(text)
    else:
        sys.stdout.write(('%s%s%s' % ((c_color % colors[color]), text, c_normal)))
    sys.stdout.flush()
    l = text.rfind('\n')
    if (l == (-1)):
        self._write_pos += len(text)
    else:
        self._write_pos = ((len(text) - l) - 1)
    self._line_wrap = (self._write_pos >= width)
    self._write_pos %= width
