예제 #1
0
 def _process_keystroke_commands(self, inp):
     """Process keystrokes that issue commands (side effects)."""
     if inp in ('1', '2') and self.screen.wide != int(inp):
         # change between 1 or 2-character wide mode.
         self.screen.wide = int(inp)
         self.initialize_page_data()
         self.on_resize(None, None)
     elif inp == 'c':
         # switch on/off combining characters
         self.character_factory = (
             WcWideCharacterGenerator
             if self.character_factory != WcWideCharacterGenerator else
             WcCombinedCharacterGenerator)
         self.initialize_page_data()
         self.on_resize(None, None)
     elif inp in ('_', '-'):
         # adjust name length -2
         nlen = max(1, self.screen.style.name_len - 2)
         if nlen != self.screen.style.name_len:
             self.screen.style.name_len = nlen
             self.on_resize(None, None)
     elif inp in ('+', '='):
         # adjust name length +2
         nlen = min(self.term.width - 8, self.screen.style.name_len + 2)
         if nlen != self.screen.style.name_len:
             self.screen.style.name_len = nlen
             self.on_resize(None, None)
     elif inp == 'v':
         with self.term.location(x=0, y=self.term.height - 2):
             print(self.term.clear_eos())
             input_selection_msg = (
                 "--> Enter unicode version [{versions}] ("
                 "current: {self.unicode_version}):".format(
                     versions=', '.join(list_versions()), self=self))
             echo('\n'.join(
                 self.term.wrap(input_selection_msg,
                                subsequent_indent='    ')))
             echo(' ')
             flushout()
             inp = readline(self.term, width=max(map(len, list_versions())))
             if inp.strip() and inp != self.unicode_version:
                 # set new unicode version -- page data must be
                 # re-initialized. Any version is legal, underlying
                 # library performs best-match (with warnings)
                 self.unicode_version = _wcmatch_version(inp)
                 self.initialize_page_data()
                 self.on_resize(None, None)
예제 #2
0
def test_nearest_999_unicode():
    """wcwidth._wcmatch_version(u'999.0') returns nearest (latest)."""
    # given
    given, expected = u'999.0', wcwidth.list_versions()[-1]

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected
예제 #3
0
def test_latest():
    """wcwidth._wcmatch_version('latest') returns tail item."""
    # given,
    expected = wcwidth.list_versions()[-1]

    # exercise,
    result = wcwidth._wcmatch_version('latest')

    # verify.
    assert result == expected
예제 #4
0
def test_nonint_str():
    """wcwidth._wcmatch_version(u'x.y.z') returns latest (str)."""
    # given
    given, expected = 'x.y.z', wcwidth.list_versions()[-1]
    warnings.resetwarnings()
    wcwidth._wcmatch_version.cache_clear()

    # exercise
    with pytest.warns(UserWarning):
        # warns that given version is not valid
        result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected
예제 #5
0
    def __init__(self, width=1):
        """
        Class constructor.

        :param int width: generate characters of given width.
        :param str unicode_version: Unicode version.
        """
        self.characters = []
        letters_o = ('o' * width)
        last_version = list_versions()[-1]
        for (begin, end) in ZERO_WIDTH[last_version].items():
            for val in [
                    _val for _val in range(begin, end + 1) if _val <= LIMIT_UCS
            ]:
                self.characters.append(letters_o[:1] + chr(val) +
                                       letters_o[wcwidth(chr(val)) + 1:])
        self.characters.reverse()