def draw(self, c):
        """
        Add given char to the right end of the buffer and update the last draw
        location. This method should ONLY be called by ShStream.
        :param str c: A new character to draw
        """

        if self.cursor_xs == self.text_length:  # cursor is at the end
            if self.text_length < self.intact_right_bound:
                self.intact_right_bound = self.text_length
            self._buffer.append(self.attrs._replace(data=c))
            self.cursor_x = self.x_drawend = self.text_length

        else:  # cursor is in the middle
            # First rotate the text is that to the right of cursor
            with self.buffer_rotate(self.text_length - self.cursor_xs - 1):
                # Remove the character at the cursor and append new character
                # This is effectively character REPLACING operation
                c_poped = self._buffer.pop()
                self._buffer.append(self.attrs._replace(data=c))
                # The replacing must be within a single line, so the newline
                # character cannot be replaced and instead a new char is inserted
                # right before the newline.
                # Also when the new character is a newline, it is effectively an
                # insertion NOT replacement (i.e. it pushes everything following
                # it to the next line).
                if c == '\n' or c_poped.data == '\n':
                    self._buffer.append(c_poped)
                # Update the cursor and drawing end
                self.cursor_x = self.x_drawend = self.cursor_xs + 1
                # Update the intact right bound
                if self.x_drawend < self.intact_right_bound:
                    self.intact_right_bound = self.x_drawend

        # Count the number of lines
        if c == '\n':
            self.nlines += 1
            self._ensure_nlines_max()

        Add given char to the right end of the buffer and update the last draw
        location. This method should ONLY be called by ShStream.
        :param str c: A new character to draw
        
system/shscreens.py