def wrapped_string(text, screen_width, prefix=0):
    """This function will take a string and make sure it can fit within the
    given screen_width.

    If the string is too long to fit, it will be broken on word boundaries
    (specifically the ' ' character) if it can or the word will be split with
    a '-' character and the second half moved to the next line.

    If a prefix is given, the line(s) will be prefixed with that many ' '
    characters, including any wrapped lines.

    If the given string includes embeded newline characters, then each line
    will be evaluated according to the rules above including breaking on word
    boundaries and injecting a prefix.
    """

    if not text:
        return ''
    new_text = ''

    # if we have multiple paragraphs, then wrap each one as if it were a single line
    lines = text.split('\n')
    if len(lines) > 1:
        for index, line in enumerate(lines):
            if index > 0:
                new_text += ' ' * prefix
            new_text += wrapped_string(line, screen_width, prefix=prefix) + '\n'
        return new_text.rstrip()

    if len(text) + prefix < screen_width:
        return text
    words = text.split(' ')
    current_line = ''
    for word in words:
        if prefix + len(current_line) + len(word) + 1 < screen_width:
            # if word fits on line, just add it
            current_line += word + ' '
        else:
            space_left = screen_width - (prefix + len(current_line))
            if space_left < 3 or len(word) - space_left < 3:
                # if not much room, move whole word to the next line
                new_text += '%s\n' % current_line.rstrip()
                current_line = '%s%s ' % (' ' * prefix, word)
            else:
                # split the word across lines with a hyphen
                current_line += word[:space_left - 1] + '-'
                new_text += current_line.rstrip() + "\n"
                current_line = ' ' * prefix + word[space_left - 1:] + ' '
    new_text += current_line.rstrip()
    return new_text