'Add one byte to the terminal at the cursor and make consequent state
updates.
If b is a carriage return, move the cursor to the beginning of the
current row.
If b is a line feed, move the cursor to the next row or scroll down if
the cursor is already in the last row.
Otherwise, if b is printable, put it at the cursor position (inserting
or overwriting as dictated by the current mode) and move the cursor.'

def insertAtCursor(self, b):

    if (b == '\r'):
        self.x = 0
    elif (b == '\n'):
        self._scrollDown()
    elif (b in string.printable.encode('ascii')):
        if (self.x >= self.width):
            self.nextLine()
        ch = (b, self._currentFormattingState())
        if self.modes.get(insults.modes.IRM):
            self.lines[self.y][self.x:self.x] = [ch]
            self.lines[self.y].pop()
        else:
            self.lines[self.y][self.x] = ch
        self.x += 1
