def _fit_text(text, length, filling=True):
    """裁剪或者填补字符串，控制其显示的长度

    >>> _fit_text('12345', 6)
    '12345 '
    >>> _fit_text('哈哈哈哈哈s', 6)  # doctest: -ELLIPSIS
    '哈哈 …'
    >>> _fit_text('哈s哈哈哈哈s', 6)  # doctest: -ELLIPSIS
    '哈s哈…'
    >>> _fit_text('sssss', 5)
    'sssss'

    FIXME: 这样可能会截断一些英文词汇
    """
    assert 80 >= length >= 5
    text_len = 0
    len_index_map = {}
    for i, c in enumerate(text):
        if ord(c) < 19968:
            text_len += 1
            len_index_map[text_len] = i
        else:
            text_len += 2
            len_index_map[text_len] = i
    if text_len <= length:
        if filling:
            return text + (length - text_len) * ' '
        return text
    remain = length - 1
    if remain in len_index_map:
        return text[:len_index_map[remain] + 1] + '…'
    else:
        return text[:len_index_map[remain - 1] + 1] + ' …'
