# Path: fabulous/utils.py
# def memoize(function):
#     def _memoize(*args):
#     def __init__(self, bgcolor='black'):
#     def termfd(self):
#     def dimensions(self):
#     def width(self):
#     def height(self):
#     def _get_bgcolor(self):
#     def _set_bgcolor(self, color):
# def pil_check():
# class TerminalInfo(object):


import sys
import logging
from fabulous import utils
        if isinstance(level, int):
            self.levelno = level
        else:
            self.levelno = logging._levelNames[level]
        self.need_cr = False
        self.last = ""
        self.parent = logging.StreamHandler

    def close(self):
        if self.need_cr:
            self.stream.write("\n")
            self.need_cr = False
        self.parent.close(self)

    def write(self, data):
        if self.need_cr:
            width = max(min(utils.term.width, len(self.last)), len(data))
            fmt = "\r%-" + str(width) + "s\n" + self.last
        else:
            fmt = "%s\n"
        try:
            self.stream.write(fmt % (data))
        except UnicodeError:
            self.stream.write(fmt % (data.encode("UTF-8")))

    def transient_write(self, data):
        if self.need_cr:
            self.stream.write('\r')
        else:
            self.need_cr = True

# Path: fabulous/utils.py
# def memoize(function):
#     def _memoize(*args):
#     def __init__(self, bgcolor='black'):
#     def termfd(self):
#     def dimensions(self):
#     def width(self):
#     def height(self):
#     def _get_bgcolor(self):
#     def _set_bgcolor(self, color):
# def pil_check():
# class TerminalInfo(object):


# Path: fabulous/logs.py
import sys
import logging
from fabulous import utils

        if isinstance(level, int):
            self.levelno = level
        else:
            self.levelno = logging._levelNames[level]
        self.need_cr = False
        self.last = ""
        self.parent = logging.StreamHandler

    def close(self):
        if self.need_cr:
            self.stream.write("\n")
            self.need_cr = False
        self.parent.close(self)

    def write(self, data):
        if self.need_cr:
            width = max(min(utils.term.width, len(self.last)), len(data))
            fmt = "\r%-" + str(width) + "s\n" + self.last
        else:
            fmt = "%s\n"
        try:
            self.stream.write(fmt % (data))
        except UnicodeError:
            self.stream.write(fmt % (data.encode("UTF-8")))

    def transient_write(self, data):
        if self.need_cr:
            self.stream.write('\r')
        else:
            self.need_cr = True

        width = utils.term.width