def format_terminal_output(result, stdout_key='stdout', stderr_key='stderr'):
    """
    Output a formatted version of the terminal
    output (std{out,err}), if the result contains
    either.

    :param stdout_key: where stdout is recorded
    :param stderr_key: where stderr is recorded
    :param result: result to inspect
    :return: formatted output message
    """
    output_message = ''
    if stdout_key in result:
        # this is most likely a shell/command/raw failure
        if len(result[stdout_key]) > 0:
            output_message += '{}\n{}\n'.format('Output to stdout:', result[stdout_key])

    if stderr_key in result:
        if len(result[stderr_key]) > 0:
            output_message += '{}\n{}\n'.format('Output to stderr:', result[stderr_key])

    if stdout_key in result and len(result[stdout_key]) == 0 and stderr_key in result and len(result[stderr_key]) == 0:
        output_message = 'No output was written to stdout or stderr!'

    return output_message