def ellipsize(text, limit, ellipsis=".."):
    """Returns text ellipsized if beyond limit."""
    if limit <= 0 or len(text) < limit:
        return text
    return text[:max(0, limit - len(ellipsis))] + ellipsis