def truncate(text, width=80):
    """
    Return text truncate to given width with ellipsis if other length.

    The builting textwrap.shortern does not work here if the value is a single
    long word (e.g. a URL) as the entire URL is replaced with '[...]'.

    https://stackoverflow.com/questions/2872512/python-truncate-a-long-string/34993870
    """
    if not text:
        return None

    placeholder = "[...]"
    if width < len(placeholder):
        raise ValueError("width must at least be as long as the placeholder"
                         f" length: {len(placeholder)}")

    if len(text) > width:
        return f"{text[:width - len(placeholder)]}{placeholder}"

    return text