'Add command to history'

def add_to_history(self, command):

    command = to_text_string(command)
    if ((command in ['', '\n']) or command.startswith('Traceback')):
        return
    if command.endswith('\n'):
        command = command[:(-1)]
    self.histidx = None
    if ((len(self.history) > 0) and (self.history[(-1)] == command)):
        return
    self.history.append(command)
    text = (os.linesep + command)
    if (self.history_filename not in self.HISTORY_FILENAMES):
        self.HISTORY_FILENAMES.append(self.history_filename)
        text = (self.SEPARATOR + text)
    encoding.write(text, self.history_filename, mode='ab')
    if (self.append_to_history is not None):
        self.append_to_history.emit(self.history_filename, text)
