'Emit a log record or create/update an animated progress logger
depending on whether :data:`term.term_mode` is enabled.'

def emit(self, record):

    level = logging.getLogger(record.name).getEffectiveLevel()
    if (level == 1):
        level = context.log_level
    if (level > record.levelno):
        return
    progress = getattr(record, 'pwnlib_progress', None)
    if ((progress is None) or (not term.term_mode)):
        super(Handler, self).emit(record)
        return
    msgtype = record.pwnlib_msgtype
    record.pwnlib_msgtype = 'animated'
    msg = ('%s\n' % self.format(record))
    if (not hasattr(progress, '_spinner_handle')):
        spinner_handle = term.output('')
        msg_handle = term.output(msg)
        stop = threading.Event()
        def spin():
            'Wheeeee!'
            state = 0
            states = random.choice(spinners.spinners)
            while True:
                prefix = ('[%s]    ' % _spinner_style(states[state]))
                spinner_handle.update(prefix)
                state = ((state + 1) % len(states))
                if stop.wait(0.1):
                    break
        t = Thread(target=spin)
        t.daemon = True
        t.start()
        progress._spinner_handle = spinner_handle
        progress._msg_handle = msg_handle
        progress._stop_event = stop
        progress._spinner_thread = t
    else:
        progress._msg_handle.update(msg)
    if (msgtype != 'status'):
        progress._stop_event.set()
        progress._spinner_thread.join()
        (style, symb) = _msgtype_prefixes[msgtype]
        prefix = ('[%s]    ' % style(symb))
        progress._spinner_handle.update(prefix)
