import pprint


def pformat_truncate(o, width=50):
    """Convert the object to printable representation and truncate it if too long

    Note: If the object is a multiline string or pformat returns a multiline
          string, only the first line of the string will be returned

    Args:
        o (object): Object to be displayed
        width (int): Maximum length for the resulting string

    Returns:
        str: String containing the formatted object
    """
    s = pprint.pformat(o)
    split = '\n' in s
    if split:
        s = s.splitlines()[0]
    if len(s) > width:
        s = s[:width-3] + '...'
    elif split:
        # If the line wasn't truncated but was the first line
        # in a multi-line string then add a marker so we know
        # that the result was modified
        s = s + '...'
    return s