tmt/utils.py
def format(
        key, value=None,
        indent=12, width=72, wrap=True,
        key_color='green', value_color='black'):
    """ Nicely format and indent a key-value pair """
    indent_string = (indent + 1) * ' '
    # Key
    output = '{} '.format(str(key).rjust(indent, ' '))
    if key_color is not None:
        output = style(output, fg=key_color)
    # Bool
    if isinstance(value, bool):
        output += ('yes' if value else 'no')
    # List
    elif isinstance(value, list):
        listed_text = fmf.utils.listed(value)
        has_spaces = any([item.find(' ') > -1 for item in value])
        # Use listed output only for short lists without spaces
        if len(listed_text) < width - indent and not has_spaces:
            output += listed_text
        # Otherwise just place each item on a new line
        else:
            output += ('\n' + indent_string).join(value)
    # Text
    elif isinstance(value, str):
        if wrap:
            output += (wrap_text(
                value, width=width,
                preserve_paragraphs=True,
                initial_indent=indent_string,
                subsequent_indent=indent_string).lstrip())
        else:
            output += (('\n' + indent_string).join(
                value.rstrip().split('\n')))
    else:
        output += str(value)
    return output
 Nicely format and indent a key-value pair 
Nicely format and indent a key-value pair
Nicely format and indent a key - value pair
def format(
        key, value=None,
        indent=12, width=72, wrap=True,
        key_color='green', value_color='black'):
    indent_string = (indent + 1) * ' '
    output = '{} '.format(str(key).rjust(indent, ' '))
    if key_color is not None:
        output = style(output, fg=key_color)
    if isinstance(value, bool):
        output += ('yes' if value else 'no')
    elif isinstance(value, list):
        listed_text = fmf.utils.listed(value)
        has_spaces = any([item.find(' ') > -1 for item in value])
        if len(listed_text) < width - indent and not has_spaces:
            output += listed_text
        else:
            output += ('\n' + indent_string).join(value)
    elif isinstance(value, str):
        if wrap:
            output += (wrap_text(
                value, width=width,
                preserve_paragraphs=True,
                initial_indent=indent_string,
                subsequent_indent=indent_string).lstrip())
        else:
            output += (('\n' + indent_string).join(
                value.rstrip().split('\n')))
    else:
        output += str(value)
    return output
def format ( key , value = None , indent = 12 , width = 72 , wrap = True , key_color = 'green' , value_color = 'black' ) : indent_string = ( indent + 1 ) * ' ' output = '{} ' . format ( str ( key ) . rjust ( indent , ' ' ) ) if key_color is not None : output = style ( output , fg = key_color ) if isinstance ( value , bool ) : output += ( 'yes' if value else 'no' ) elif isinstance ( value , list ) : listed_text = fmf . utils . listed ( value ) has_spaces = any ( [ item . find ( ' ' ) > - 1 for item in value ] ) if len ( listed_text ) < width - indent and not has_spaces : output += listed_text else : output += ( '\n' + indent_string ) . join ( value ) elif isinstance ( value , str ) : if wrap : output += ( wrap_text ( value , width = width , preserve_paragraphs = True , initial_indent = indent_string , subsequent_indent = indent_string ) . lstrip ( ) ) else : output += ( ( '\n' + indent_string ) . join ( value . rstrip ( ) . split ( '\n' ) ) ) else : output += str ( value ) return output
Nicely format and indent a key-value pair
Nicely format and indent a key - value pair
""" Nicely format and indent a key-value pair """ # Key # Bool # List # Use listed output only for short lists without spaces # Otherwise just place each item on a new line # Text
key
value
indent
width
wrap
key_color
value_color