def terminal_lines(data, cols=80):
    """Returns the number of lines of a terminal with 'cols' columns that the
string will consume."""
    l = n = i = 0
    while n >= 0:
        n = data.find("\n", i)
        l += 1 + ((((n<0 and len(data)) or n)-i)/cols)
        i = n + 1
    return l