def format_var_info(tok, _dict, _global=''):
    """Formats the variable information so that it fits on a single line
       for each variable.

       The format we want is something like the following:

       [global] name: repr(name)

       However, if repr(name) exceeds a certain value, it is truncated.
       When that is the case, if len(name) is defined, as is the case for
       lists, tuples, dicts, etc., then len(name) is shown on a separate line.
       This can be useful information in case of IndexError and possibly
       others.
    """
    MAX_LENGTH = 50
    length_info = ''
    if _global:
        _global = 'global '
    name = tok.string
    obj = _dict[name]
    try:
        value = repr(obj)
    except Exception:
        return ''
    if value.startswith('<') and value.endswith('>') and ' at ' in value:
        value = value.split(' at ')[0] + '>'
    if len(value) > MAX_LENGTH:
        value = value[0:MAX_LENGTH - 5] + '...' + value[-1]
        try:
            length_info = len(obj)
        except TypeError:
            pass
    result = f'    {_global}{name}: {value}'
    if length_info:
        result += f'  | len({name}): {length_info}'
    return result
