Skip to content

Add support for Unicode wide characters #85

Description

@keatonLiu

Modify MenuComponent class:

def _format_content(self, content='', align='left'):
    # remove color str which is invisible and get the actual len of content(wide char counts for 2)
    len_visible_chars = sum(get_width(ord(ch)) for ch in strip_color(content))
    len_invisible_chars = len(content) - len_visible_chars
    return '{lp}{text:{al}{width}}{rp}'.format(lp=' ' * self.padding.left,
                                               rp=' ' * self.padding.right,
                                               text=content, al=self._alignment_char(align),
                                               width=(self.calculate_border_width() - self.padding.left -
                                                      self.padding.right - 2 + len_invisible_chars))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions