def get_text_width(text):
    "Function that utilizes ``wcswidth`` or ``wcwidth`` to determine the\n    number of columns used to display a text string.\n\n    We try first with ``wcswidth``, and fallback to iterating each\n    character and using wcwidth individually, falling back to a value of 0\n    for non-printable wide characters\n\n    On Py2, this depends on ``locale.setlocale(locale.LC_ALL, '')``,\n    that in the case of Ansible is done in ``bin/ansible``\n    "
    if (not isinstance(text, text_type)):
        raise TypeError(('get_text_width requires text, not %s' % type(text)))
    if _LOCALE_INITIALIZATION_ERR:
        Display().warning(('An error occurred while calling ansible.utils.display.initialize_locale (%s). This may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths' % _LOCALE_INITIALIZATION_ERR))
    elif (not _LOCALE_INITIALIZED):
        Display().warning('ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths')
    try:
        width = _LIBC.wcswidth(text, _MAX_INT)
    except ctypes.ArgumentError:
        width = (- 1)
    if (width != (- 1)):
        return width
    width = 0
    counter = 0
    for c in text:
        counter += 1
        if (c in (u'\x08', u'\x7f', u'\x94', u'\x1b')):
            width -= 1
            counter -= 1
            continue
        try:
            w = _LIBC.wcwidth(c)
        except ctypes.ArgumentError:
            w = (- 1)
        if (w == (- 1)):
            w = 0
        width += w
    if ((width == 0) and counter and (not _LOCALE_INITIALIZED)):
        raise EnvironmentError(('ansible.utils.display.initialize_locale has not been called, and get_text_width could not calculate text width of %r' % text))
    return (width if (width >= 0) else 0)
Function that utilizes ``wcswidth`` or ``wcwidth`` to determine the
number of columns used to display a text string.

We try first with ``wcswidth``, and fallback to iterating each
character and using wcwidth individually, falling back to a value of 0
for non-printable wide characters

On Py2, this depends on ``locale.setlocale(locale.LC_ALL, '')``,
that in the case of Ansible is done in ``bin/ansible``
def get_text_width(text):
    "Function that utilizes ``wcswidth`` or ``wcwidth`` to determine the\n    number of columns used to display a text string.\n\n    We try first with ``wcswidth``, and fallback to iterating each\n    character and using wcwidth individually, falling back to a value of 0\n    for non-printable wide characters\n\n    On Py2, this depends on ``locale.setlocale(locale.LC_ALL, )``,\n    that in the case of Ansible is done in ``bin/ansible``\n    "
    if (not isinstance(text, text_type)):
        raise TypeError(('get_text_width requires text, not %s' % type(text)))
    if _LOCALE_INITIALIZATION_ERR:
        Display().warning(('An error occurred while calling ansible.utils.display.initialize_locale (%s). This may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths' % _LOCALE_INITIALIZATION_ERR))
    elif (not _LOCALE_INITIALIZED):
        Display().warning('ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths')
    try:
        width = _LIBC.wcswidth(text, _MAX_INT)
    except ctypes.ArgumentError:
        width = (- 1)
    if (width != (- 1)):
        return width
    width = 0
    counter = 0
    for c in text:
        counter += 1
        if (c in (u'\x08', u'\x7f', u'\x94', u'\x1b')):
            width -= 1
            counter -= 1
            continue
        try:
            w = _LIBC.wcwidth(c)
        except ctypes.ArgumentError:
            w = (- 1)
        if (w == (- 1)):
            w = 0
        width += w
    if ((width == 0) and counter and (not _LOCALE_INITIALIZED)):
        raise EnvironmentError(('ansible.utils.display.initialize_locale has not been called, and get_text_width could not calculate text width of %r' % text))
    return (width if (width >= 0) else 0)