Example #1
0
File: pager.py Project: hick/x84
 def append(self, ucs):
     """
     Update content buffer with additional line(s) of text.
     """
     from x84.bbs.output import decode_pipe
     self._content.extend(self.content_wrap(decode_pipe(ucs)))
     return self.move_end() or self.refresh(self.bottom)
Example #2
0
 def update(self, ucs):
     """
     Update content buffer with newline-delimited text.
     """
     from x84.bbs.output import decode_pipe
     self.content = self.content_wrap(decode_pipe(ucs))
     return self.refresh()
Example #3
0
    def refresh_row(self, row):
        """
        Return unicode byte sequence suitable for moving to location ypos of
        window-relative row, and displaying any valid entry there, or using
        glyphs['erase'] if out of bounds. Strings are ansi color safe, and
        will be trimmed using glyphs['strip'] if their displayed width is
        wider than window.
        """
        from x84.bbs.session import getterminal
        from x84.bbs.output import decode_pipe
        term = getterminal()

        pos = self.pos(self.ypadding + row, self.xpadding)
        entry = self.vitem_shift + row
        if entry >= len(self.content):
            # out-of-bounds;
            disp_erase = self.glyphs.get('erase', u' ') * self.visible_width
            return u''.join((pos, disp_erase,))

        def fit_row(ucs):
            """ Strip a unicode row to fit window boundry, if necessary """
            column = self.visible_width + 1
            wrapped = term.wrap(ucs, column)
            if len(wrapped) > 1:
                marker = self.glyphs.get('strip', u' $')
                marker_column = self.visible_width - len(marker)
                wrapped = term.wrap(ucs, marker_column)
                ucs = term.ljust(wrapped[0].rstrip(), marker_column) + marker
                return ucs
            return term.ljust(ucs, column)

        # allow ucs data with '\r\n', to accomidate soft and hardbreaks; just
        # don't display them, really wrecks up cusor positioning.
        ucs = self.content[entry][1].strip(u'\r\n')

        # highlighted entry; strip of ansi sequences, use color 'highlight'
        # trim and append '$ ' if it cannot fit,
        if entry == self.index:
            ucs = term.strip_seqs(ucs)
            if term.length(ucs) > self.visible_width:
                ucs = fit_row(ucs)
            return u''.join((pos,
                             term.normal,
                             self.colors.get('highlight', u''),
                             self.align(ucs),
                             term.normal,))
        # unselected entry; retain ansi sequences, decode any pipe characters,
        # trim and append '$ ' if it cannot fit
        ucs = decode_pipe(ucs)
        if term.length(ucs) > self.visible_width:
            ucs = fit_row(ucs)
        return u''.join((pos,
                         self.colors.get('lowlight', u''),
                         self.align(ucs),
                         term.normal,))
Example #4
0
    def append(self, ucs):
        """
        Update content buffer with additional line(s) of text.

        "pipe codes" in ``ucs`` are decoded by :func:`decode_pipe`.

        :param str ucs: unicode string to append-to content buffer.
        :rtype str
        :return: terminal sequence suitable for refreshing window.
        """
        self._content.extend(self._content_wrap(decode_pipe(ucs)))
        return self.move_end() or self.refresh(self.bottom)
Example #5
0
 def content(self, ucs_value):
     # pylint: disable=C0111
     #         Missing method docstring
     self._content = self._content_wrap(decode_pipe(ucs_value))
Example #6
0
    def refresh_row(self, row):
        """ Return string sequence suitable for refreshing current selection.

        Return unicode byte sequence suitable for moving to location ypos of
        window-relative row, and displaying any valid entry there, or using
        glyphs['erase'] if out of bounds. Strings are ansi color safe, and
        will be trimmed using glyphs['strip'] if their displayed width is
        wider than window.
        """
        term = getterminal()

        pos = self.pos(self.ypadding + row, self.xpadding)
        entry = self.vitem_shift + row
        if entry >= len(self.content):
            # out-of-bounds;
            disp_erase = self.glyphs.get('erase', u' ') * self.visible_width
            return u''.join((
                pos,
                disp_erase,
            ))

        def fit_row(ucs):
            """ Strip a unicode row to fit window boundry, if necessary """
            column = self.visible_width - 1
            wrapped = term.wrap(ucs, column)
            if len(wrapped) > 1:
                marker = self.glyphs.get('strip', u' $')
                marker_column = self.visible_width - len(marker)
                wrapped = term.wrap(ucs, marker_column)
                ucs = term.ljust(wrapped[0].rstrip(), marker_column) + marker
                return ucs
            return term.ljust(ucs, column)

        # allow ucs data with '\r\n', to accomidate soft and hardbreaks; just
        # don't display them, really wrecks up cusor positioning.
        ucs = self.content[entry][1].strip(u'\r\n')

        # highlighted entry; strip of ansi sequences, use color 'highlight'
        # trim and append '$ ' if it cannot fit,
        if entry == self.index:
            ucs = term.strip_seqs(ucs)
            if term.length(ucs) > self.visible_width:
                ucs = fit_row(ucs)
            return u''.join((
                pos,
                term.normal,
                self.colors.get('highlight', u''),
                self.align(ucs),
                term.normal,
            ))
        # unselected entry; retain ansi sequences, decode any pipe characters,
        # trim and append '$ ' if it cannot fit
        ucs = decode_pipe(ucs)
        if term.length(ucs) > self.visible_width:
            ucs = fit_row(ucs)
        return u''.join((
            pos,
            self.colors.get('lowlight', u''),
            self.align(ucs),
            term.normal,
        ))
Example #7
0
File: pager.py Project: hick/x84
 def content(self, ucs_value):
     from x84.bbs.output import decode_pipe
     self._content = self.content_wrap(decode_pipe(ucs_value))