def _ensure_nlines_max(self):
        """
        Keep number of lines under control
        """
        char_count = line_count = 0
        for _ in xrange(self.nlines_max, self.nlines):
            # Remove the top line
            for idx in xrange(self.text_length):
                char_count += 1
                if self._buffer.popleft().data == '\n':
                    line_count += 1
                    break

        if char_count > 0:
            self.intact_left_bound += char_count
            self.intact_right_bound -= char_count
            self.cursor_xs -= char_count
            self.cursor_xe -= char_count
            self.x_drawend -= char_count

        if line_count > 0:
            self.nlines -= line_count

        Keep number of lines under control
        
system/shscreens.py