def split_lines(fragments):
    """
    Take a single list of (style_str, text) tuples and yield one such list for each
    line. Just like str.split, this will yield at least one item.

    :param fragments: List of (style_str, text) or (style_str, text, mouse_handler)
                      tuples.
    """
    line = []
    for item in fragments:
        if len(item) == 2:
            style, string = item
            parts = string.split('\n')
            for part in parts[:-1]:
                if part:
                    line.append((style, part))
                yield line
                line = []
            line.append((style, parts[-1]))
        else:
            style, string, mouse_handler = item
            parts = string.split('\n')
            for part in parts[:-1]:
                if part:
                    line.append((style, part, mouse_handler))
                yield line
                line = []
            line.append((style, parts[-1], mouse_handler))
    yield line
