'Flush buffer, write text to console'

def flush(self, error=False, prompt=False):

    if PY3:
        try:
            text = ''.join(self.__buffer)
        except TypeError:
            text = ''.join(self.__buffer)
            try:
                text = text.decode(locale.getdefaultlocale()[1])
            except:
                pass
    else:
        text = ''.join(self.__buffer)
    self.__buffer = []
    self.insert_text(text, at_end=True, error=error, prompt=prompt)
    QCoreApplication.processEvents()
    self.repaint()
    self.new_input_line = True
