def _get_last_lines(self, text, num_lines, return_count=False):
        """ Get the last specified number of lines of text (like `tail -n`).
        If return_count is True, returns a tuple of clipped text and the
        number of lines in the clipped text.
        """
        pos = len(text)
        if pos < num_lines:
            if return_count:
                return text, text.count('\n') if return_count else text
            else:
                return text
        i = 0
        while i < num_lines:
            pos = text.rfind('\n', None, pos)
            if pos == -1:
                pos = None
                break
            i += 1
        if return_count:
            return text[pos:], i
        else:
            return text[pos:]
 Get the last specified number of lines of text (like `tail -n`).
        If return_count is True, returns a tuple of clipped text and the
        number of lines in the clipped text.
        
angrmanagement/vendor/qtconsole/console_widget.py