def _wc_hard_wrap(line, length):
    """
    Wrap text to length characters, breaking when target length is reached,
    taking into account character width.

    Used to wrap lines which cannot be wrapped on whitespace.
    """
    chars = []
    chars_len = 0
    for char in line:
        char_len = wcwidth(char)
        if chars_len + char_len > length:
            yield "".join(chars)
            chars = []
            chars_len = 0

        chars.append(char)
        chars_len += char_len

    if chars:
        yield "".join(chars)
def _wc_hard_wrap ( line , length ) : chars = [ ] chars_len = 0 for char in line : char_len = wcwidth ( char ) if chars_len + char_len > length : yield "" . join ( chars ) chars = [ ] chars_len = 0 chars . append ( char ) chars_len += char_len if chars : yield "" . join ( chars )
Wrap text to length characters, breaking when target length is reached,
    taking into account character width.

    Used to wrap lines which cannot be wrapped on whitespace.