Exemple #1
0
def utf8_width_chop(msg, chop=None):
    '''**Deprecated** Return a string chopped to a given :term:`textual width`

    Use :func:`~kitchen.text.display.textual_width_chop` and
    :func:`~kitchen.text.display.textual_width` instead::

        >>> msg = 'く ku ら ra と to み mi'
        >>> # Old way:
        >>> utf8_width_chop(msg, 5)
        (5, 'く ku')
        >>> # New way
        >>> from kitchen.text.converters import to_bytes
        >>> from kitchen.text.display import textual_width, textual_width_chop
        >>> (textual_width(msg), to_bytes(textual_width_chop(msg, 5)))
        (5, 'く ku')
    '''
    warnings.warn('kitchen.text.utf8.utf8_width_chop is deprecated.  Use'
        ' kitchen.text.display.textual_width_chop instead', DeprecationWarning,
        stacklevel=2)

    if chop == None:
        return textual_width(msg), msg

    as_bytes = not isunicodestring(msg)
 
    chopped_msg = textual_width_chop(msg, chop)
    if as_bytes:
        chopped_msg = to_bytes(chopped_msg)
    return textual_width(chopped_msg), chopped_msg
Exemple #2
0
def utf8_width(msg):
    '''**Deprecated** Get the :term:`textual width` of a :term:`utf-8` string

    Use :func:`kitchen.text.display.textual_width` instead.
    '''
    warnings.warn('kitchen.text.utf8.utf8_width is deprecated.  Use'
        ' kitchen.text.display.textual_width(msg) instead',
        DeprecationWarning, stacklevel=2)
    return textual_width(msg)
 def test_internal_textual_width_le(self):
     test_data = ''.join([self.u_mixed, self.u_spanish])
     tw = display.textual_width(test_data)
     tools.eq_(display._textual_width_le(68, self.u_mixed, self.u_spanish), (tw <= 68))
     tools.eq_(display._textual_width_le(69, self.u_mixed, self.u_spanish), (tw <= 69))
     tools.eq_(display._textual_width_le(137, self.u_mixed, self.u_spanish), (tw <= 137))
     tools.eq_(display._textual_width_le(138, self.u_mixed, self.u_spanish), (tw <= 138))
     tools.eq_(display._textual_width_le(78, self.u_mixed, self.u_spanish), (tw <= 78))
     tools.eq_(display._textual_width_le(79, self.u_mixed, self.u_spanish), (tw <= 79))
Exemple #4
0
 def test_internal_textual_width_le(self):
     test_data = ''.join([self.u_mixed, self.u_spanish])
     tw = display.textual_width(test_data)
     tools.eq_(display._textual_width_le(68, self.u_mixed, self.u_spanish), (tw <= 68))
     tools.eq_(display._textual_width_le(69, self.u_mixed, self.u_spanish), (tw <= 69))
     tools.eq_(display._textual_width_le(137, self.u_mixed, self.u_spanish), (tw <= 137))
     tools.eq_(display._textual_width_le(138, self.u_mixed, self.u_spanish), (tw <= 138))
     tools.eq_(display._textual_width_le(78, self.u_mixed, self.u_spanish), (tw <= 78))
     tools.eq_(display._textual_width_le(79, self.u_mixed, self.u_spanish), (tw <= 79))
Exemple #5
0
    def _draw_header(self):

        n_rows, n_cols = self._header_window.getmaxyx()

        self._header_window.erase()
        attr = curses.A_REVERSE | curses.A_BOLD | Color.CYAN
        self._header_window.bkgd(' ', attr)

        sub_name = self.content.name.replace('/r/front', 'Front Page ')
        add_line(self._header_window, sub_name, 0, 0)

        if self.reddit.user is not None:
            username = self.reddit.user.name
            s_col = (n_cols - textual_width(username) - 1)
            # Only print username if it fits in the empty space on the right
            if (s_col - 1) >= textual_width(sub_name):
                add_line(self._header_window, username, 0, s_col)

        self._header_window.refresh()
Exemple #6
0
    def _draw_header(self):

        n_rows, n_cols = self._header_window.getmaxyx()

        self._header_window.erase()
        attr = curses.A_REVERSE | curses.A_BOLD | Color.CYAN
        self._header_window.bkgd(' ', attr)

        sub_name = self.content.name.replace('/r/front', 'Front Page ')
        add_line(self._header_window, sub_name, 0, 0)

        if self.reddit.user is not None:
            username = self.reddit.user.name
            s_col = (n_cols - textual_width(username) - 1)
            # Only print username if it fits in the empty space on the right
            if (s_col - 1) >= textual_width(sub_name):
                add_line(self._header_window, username, 0, s_col)

        self._header_window.refresh()
Exemple #7
0
def utf8_width(msg):
    '''Deprecated

    Use :func:`~kitchen.text.utf8.textual_width` instead.
    '''
    warnings.warn(_('kitchen.text.utf8.utf8_width is deprecated.  Use'
                    ' kitchen.text.display.textual_width(msg) instead'),
                  DeprecationWarning,
                  stacklevel=2)
    return textual_width(msg)
 def test_textual_width(self):
     '''Test that we find the proper number of spaces that a utf8 string will consume'''
     tools.eq_(display.textual_width(self.u_japanese), 31)
     tools.eq_(display.textual_width(self.u_spanish), 50)
     tools.eq_(display.textual_width(self.u_mixed), 23)
 def test_textual_width(self):
     '''Test that we find the proper number of spaces that a utf8 string will consume'''
     tools.eq_(display.textual_width(self.u_japanese), 31)
     tools.eq_(display.textual_width(self.u_spanish), 50)
     tools.eq_(display.textual_width(self.u_mixed), 23)