Fits a piece of text to ``width`` characters by truncating too long text and
    padding too short text with spaces. Defaults to terminal width. Truncation
    is indicated by a customizable suffix. ``align`` specifies the alignment of
    the contents if it is padded, and can be:

    * ``<`` - Left aligned (default)
    * ``^`` - Centered
    * ``>`` - Right aligned

def format_fit(text, width=None, align='<', suffix="..."):
    """
    Fits a piece of text to ``width`` characters by truncating too long text and
    padding too short text with spaces. Defaults to terminal width. Truncation
    is indicated by a customizable suffix. ``align`` specifies the alignment of
    the contents if it is padded, and can be:

    * ``<`` - Left aligned (default)
    * ``^`` - Centered
    * ``>`` - Right aligned
    """

    if width==None:
        width = get_terminal_size().columns

    if len(text)>width:
        if len(suffix)>width:
            return suffix[len(suffix)-width:]
        else:
            return text[:width-len(suffix)]+suffix
    else:
        return "{{:{}{{w}}}}".format(align).format(text,w=width)