def surround_text(text, left='>>', right='<<', pad=2, preserve_whitespace=True):
    """
    Surround ``text`` string with the characters from `left` and `right` - if color is not enabled this is
    a good way to draw attention to a particular block of text.

    :param text: the text to surround
    :type text: str
    :param left: text that goes to the left of ``text``
    :type left: str
    :param right: text that goes to the right of ``text``
    :type right: str
    :param pad: whitespace padding to place between ``left``, ``right`` and ``text``
    :type pad: int
    :param preserve_whitespace: preserve existing whitespace before and after text, such that indenting would
           remain unchanged.
    :type preserve_whitespace: bool
    :return: formatted string
    :rtype: str
    """
    ltext = left + (' ' * pad)
    rtext = (' ' * pad) + right
    if preserve_whitespace:
        lspace = len(text) - len(text.lstrip())  # 10
        rspace = len(text) - len(text.rstrip())
        lpad = max((lspace - len(ltext), 0))  # 6
        rpad = max((rspace - len(rtext), 0))
        ltext = (' ' * lpad) + ltext
        rtext = rtext + (' ' * rpad)
        return '{}{}{}'.format(ltext, text.strip(), rtext)
    else:
        return '{}{}{}'.format(ltext, text.strip(), rtext)