Ejemplo n.º 1
0
    def render(self, size, focus=False):
        from pudb.debugger import CONFIG
        render_line_nr = CONFIG["line_numbers"]

        maxcol = size[0]
        hscroll = self.dbg_ui.source_hscroll_start
        attrs = []
        if self.is_current:
            crnt = ">"
            attrs.append("current")
        else:
            crnt = " "

        if self.has_breakpoint:
            bp = "*"
            attrs.append("breakpoint")
        else:
            bp = " "

        if focus:
            attrs.append("focused")
        elif self.highlight:
            if not self.has_breakpoint:
                attrs.append("highlighted")

        if render_line_nr:
            line_nr_len = len(self.line_nr)
        else:
            line_nr_len = 0

        text = self.text
        if not attrs and self.attr is not None:
            attr = self.attr
        else:
            attr = [(" ".join(attrs+["source"]), hscroll+maxcol-2-line_nr_len)]

        from urwid.util import rle_subseg, rle_len

        if hscroll:
            text = text[hscroll:]
            attr = rle_subseg(attr, hscroll, rle_len(attr))

        if render_line_nr:
            attr = [("line number", len(self.line_nr))] + attr
            text = self.line_nr + text

        text = crnt+bp+text
        attr = [("source", 1), ("bp_star", 1)] + attr

        # clipping ------------------------------------------------------------
        if len(text) > maxcol:
            text = text[:maxcol]
            attr = rle_subseg(attr, 0, maxcol)

        # shipout -------------------------------------------------------------
        from urwid.util import apply_target_encoding
        txt, cs = apply_target_encoding(text)

        return urwid.TextCanvas([txt], [attr], [cs], maxcol=maxcol)
Ejemplo n.º 2
0
def make_canvas(txt, attr, maxcol, fill_attr=None):
    processed_txt = []
    processed_attr = []
    processed_cs = []

    for line, line_attr in zip(txt, attr):
        # filter out zero-length attrs
        line_attr = [(aname, l) for aname, l in line_attr if l > 0]

        diff = maxcol - len(line)
        if diff > 0:
            line += " "*diff
            line_attr.append((fill_attr, diff))
        else:
            from urwid.util import rle_subseg
            line = line[:maxcol]
            line_attr = rle_subseg(line_attr, 0, maxcol)

        from urwid.util import apply_target_encoding
        line, line_cs = apply_target_encoding(line)

        processed_txt.append(line)
        processed_attr.append(line_attr)
        processed_cs.append(line_cs)

    return urwid.TextCanvas(
            processed_txt,
            processed_attr,
            processed_cs,
            maxcol=maxcol)
Ejemplo n.º 3
0
def make_canvas(txt, attr, maxcol, fill_attr=None):
    processed_txt = []
    processed_attr = []
    processed_cs = []

    for line, line_attr in zip(txt, attr):
        # filter out zero-length attrs
        line_attr = [(aname, l) for aname, l in line_attr if l > 0]

        diff = maxcol - len(line)
        if diff > 0:
            line += " "*diff
            line_attr.append((fill_attr, diff))
        else:
            from urwid.util import rle_subseg
            line = line[:maxcol]
            line_attr = rle_subseg(line_attr, 0, maxcol)

        from urwid.util import apply_target_encoding
        line, line_cs = apply_target_encoding(line)

        processed_txt.append(line)
        processed_attr.append(line_attr)
        processed_cs.append(line_cs)

    return urwid.TextCanvas(
            processed_txt,
            processed_attr,
            processed_cs,
            maxcol=maxcol)
Ejemplo n.º 4
0
def make_canvas(txt, attr, maxcol, fill_attr=None):
    processed_txt = []
    processed_attr = []
    processed_cs = []

    for line, line_attr in zip(txt, attr):
        # filter out zero-length attrs
        line_attr = [(aname, l) for aname, l in line_attr if l > 0]

        diff = maxcol - calc_width(line, 0, len(line))
        if diff > 0:
            line += " " * diff
            line_attr.append((fill_attr, diff))
        else:
            from urwid.util import rle_subseg
            line = line[:maxcol]
            line_attr = rle_subseg(line_attr, 0, maxcol)

        from urwid.util import apply_target_encoding
        encoded_line, line_cs = apply_target_encoding(line)

        # line_cs contains byte counts as requested by TextCanvas, but
        # line_attr still contains column counts at this point: let's fix this.
        def get_byte_line_attr(line, line_attr):
            i = 0
            for label, column_count in line_attr:
                byte_count = len(line[i:i +
                                      column_count].encode(_target_encoding))
                i += column_count
                yield label, byte_count

        line_attr = list(get_byte_line_attr(line, line_attr))

        processed_txt.append(encoded_line)
        processed_attr.append(line_attr)
        processed_cs.append(line_cs)

    return urwid.TextCanvas(processed_txt,
                            processed_attr,
                            processed_cs,
                            maxcol=maxcol)
Ejemplo n.º 5
0
def make_canvas(txt, attr, maxcol, fill_attr=None):
    processed_txt = []
    processed_attr = []
    processed_cs = []

    for line, line_attr in zip(txt, attr):
        # filter out zero-length attrs
        line_attr = [(aname, l) for aname, l in line_attr if l > 0]

        diff = maxcol - len(line)
        if diff > 0:
            line += " "*diff
            line_attr.append((fill_attr, diff))
        else:
            from urwid.util import rle_subseg
            line = line[:maxcol]
            line_attr = rle_subseg(line_attr, 0, maxcol)

        from urwid.util import apply_target_encoding
        encoded_line, line_cs = apply_target_encoding(line)

        # line_cs contains byte counts as requested by TextCanvas, but
        # line_attr still contains column counts at this point: let's fix this.
        def get_byte_line_attr(line, line_attr):
            i = 0
            for label, column_count in line_attr:
                byte_count = len(line[i:i+column_count].encode(_target_encoding))
                i += column_count
                yield label, byte_count

        line_attr = list(get_byte_line_attr(line, line_attr))

        processed_txt.append(encoded_line)
        processed_attr.append(line_attr)
        processed_cs.append(line_cs)

    return urwid.TextCanvas(
            processed_txt,
            processed_attr,
            processed_cs,
            maxcol=maxcol)
Ejemplo n.º 6
0
    def render(self, size, focus=False):
        from pudb.ui_tools import make_canvas

        maxcol = size[0]
        if focus:
            apfx = "focused "+self.attr_prefix+" "
        else:
            apfx = self.attr_prefix+" "

        var_label = self.var_label or ''

        if self.wrap:
            text = self._get_text(size)

            extralabel_full, extralabel_rem = divmod(
                    text_width(var_label[maxcol:]), maxcol)
            totallen = sum([text_width(i) for i in text])
            labellen = (
                    len(self.prefix)  # Padding of first line

                    + (len(self.prefix) + 2)  # Padding of subsequent lines
                    * (extralabel_full + bool(extralabel_rem))

                    + text_width(var_label)

                    + 2  # for ": "
                    )

            _attr = [(apfx+"label", labellen), (apfx+"value", totallen - labellen)]
            from urwid.util import rle_subseg

            fullcols, rem = divmod(totallen, maxcol)

            attr = [rle_subseg(_attr, i*maxcol, (i + 1)*maxcol)
                for i in xrange(fullcols + bool(rem))]

            return make_canvas(text, attr, maxcol, apfx+"value")

        lprefix = len(self.prefix)

        if self.value_str is not None:
            if self.var_label is not None:
                if len(self.prefix) + text_width(self.var_label) > self.SIZE_LIMIT:
                    # label too long? generate separate value line
                    text = [self.prefix + self.var_label,
                            self.prefix+"  " + self.value_str]

                    attr = [
                        [(apfx+"label", lprefix+text_width(self.var_label))],
                        [(apfx+"value", lprefix+2+text_width(self.value_str))]
                        ]
                else:
                    text = [self.prefix + self.var_label + ": " + self.value_str]

                    attr = [[
                            (apfx+"label", lprefix+text_width(self.var_label)+2),
                            (apfx+"value", text_width(self.value_str)),
                            ]]
            else:
                text = [self.prefix + self.value_str]

                attr = [[
                        (apfx+"label", len(self.prefix)),
                        (apfx+"value", text_width(self.value_str)),
                        ]]
        else:
            text = [self.prefix + self.var_label]

            attr = [[(apfx+"label", lprefix + text_width(self.var_label)), ]]

        # Ellipses to show text was cut off
        #encoding = urwid.util.detected_encoding

        if False:  # encoding[:3] == "UTF":
            # Unicode is supported, use single character ellipsis
            for i in xrange(len(text)):
                if len(text[i]) > maxcol:
                    text[i] = (unicode(text[i][:maxcol-1])  # noqa: F821
                            + ELLIPSIS + unicode(text[i][maxcol:]))  # noqa: F821
                    # XXX: This doesn't work.  It just gives a ?
                    # Strangely, the following does work (it gives the …
                    # three characters from the right):
                    #
                    # text[i] = (unicode(text[i][:maxcol-3])
                    # + unicode(u'…')) + unicode(text[i][maxcol-2:])
        else:
            for i in xrange(len(text)):
                if text_width(text[i]) > maxcol:
                    text[i] = text[i][:maxcol-3] + "..."

        return make_canvas(text, attr, maxcol, apfx+"value")
Ejemplo n.º 7
0
    def render(self, size, focus=False):
        from pudb.ui_tools import make_canvas

        maxcol = size[0]
        if focus:
            apfx = "focused " + self.attr_prefix + " "
        else:
            apfx = self.attr_prefix + " "

        var_label = self.var_label or ''

        if self.wrap:
            text = self._get_text(size)

            extralabel_full, extralabel_rem = divmod(
                text_width(var_label[maxcol:]), maxcol)
            totallen = sum([text_width(i) for i in text])
            labellen = (
                len(self.prefix)  # Padding of first line
                + (len(self.prefix) + 2)  # Padding of subsequent lines
                * (extralabel_full + bool(extralabel_rem)) +
                text_width(var_label) + 2  # for ": "
            )

            _attr = [(apfx + "label", labellen),
                     (apfx + "value", totallen - labellen)]
            from urwid.util import rle_subseg

            fullcols, rem = divmod(totallen, maxcol)

            attr = [
                rle_subseg(_attr, i * maxcol, (i + 1) * maxcol)
                for i in xrange(fullcols + bool(rem))
            ]

            return make_canvas(text, attr, maxcol, apfx + "value")

        lprefix = len(self.prefix)

        if self.value_str is not None:
            if self.var_label is not None:
                if len(self.prefix) + text_width(
                        self.var_label) > self.SIZE_LIMIT:
                    # label too long? generate separate value line
                    text = [
                        self.prefix + self.var_label,
                        self.prefix + "  " + self.value_str
                    ]

                    attr = [[(apfx + "label",
                              lprefix + text_width(self.var_label))],
                            [(apfx + "value",
                              lprefix + 2 + text_width(self.value_str))]]
                else:
                    text = [
                        self.prefix + self.var_label + ": " + self.value_str
                    ]

                    attr = [[
                        (apfx + "label",
                         lprefix + text_width(self.var_label) + 2),
                        (apfx + "value", text_width(self.value_str)),
                    ]]
            else:
                text = [self.prefix + self.value_str]

                attr = [[
                    (apfx + "label", len(self.prefix)),
                    (apfx + "value", text_width(self.value_str)),
                ]]
        else:
            text = [self.prefix + self.var_label]

            attr = [[
                (apfx + "label", lprefix + text_width(self.var_label)),
            ]]

        # Ellipses to show text was cut off
        #encoding = urwid.util.detected_encoding

        if False:  # encoding[:3] == "UTF":
            # Unicode is supported, use single character ellipsis
            for i in xrange(len(text)):
                if len(text[i]) > maxcol:
                    text[i] = (
                        unicode(text[i][:maxcol - 1])  # noqa: F821
                        + ELLIPSIS + unicode(text[i][maxcol:]))  # noqa: F821
                    # XXX: This doesn't work.  It just gives a ?
                    # Strangely, the following does work (it gives the …
                    # three characters from the right):
                    #
                    # text[i] = (unicode(text[i][:maxcol-3])
                    # + unicode(u'…')) + unicode(text[i][maxcol-2:])
        else:
            for i in xrange(len(text)):
                if text_width(text[i]) > maxcol:
                    text[i] = text[i][:maxcol - 3] + "..."

        return make_canvas(text, attr, maxcol, apfx + "value")
Ejemplo n.º 8
0
                attrs.append("highlighted")

        if not attrs and self.attr is not None:
            attr = self.attr
            if render_line_nr:
                attr = [("line number", len(self.line_nr))] + attr
        else:
            attr = [(" ".join(attrs+["source"]), hscroll+maxcol-2)]

        from urwid.util import rle_subseg, rle_len

        text = self.text
        if self.dbg_ui.source_hscroll_start:
            text = text[hscroll:]
            attr = rle_subseg(attr,
                    self.dbg_ui.source_hscroll_start,
                    rle_len(attr))

        if render_line_nr:
            text = self.line_nr + text

        text = crnt+bp+text
        attr = [("source", 1), ("bp_star", 1)] + attr

        # clipping ------------------------------------------------------------
        if len(text) > maxcol:
            text = text[:maxcol]
            attr = rle_subseg(attr, 0, maxcol)

        # shipout -------------------------------------------------------------
        from urwid.util import apply_target_encoding
Ejemplo n.º 9
0
    def render(self, size: Tuple[int], focus: bool = False) -> urwid.Canvas:
        """
        :param size: (maxcol,) the number of columns available to this widget
        :param focus: True if this widget or one of its children is in focus
        :return: A Canvas subclass instance containing the rendered content of
            this widget
        """
        from pudb.ui_tools import make_canvas

        maxcol = size[0]
        if focus:
            apfx = "focused " + self.attr_prefix + " "
        else:
            apfx = self.attr_prefix + " "

        var_label = self.var_label or ""

        if self.wrap:
            text = self._get_wrapped_lines(maxcol)

            extralabel_full, extralabel_rem = divmod(
                text_width(var_label[maxcol:]), maxcol)
            totallen = sum([text_width(i) for i in text])
            labellen = (
                len(self.prefix)  # Padding of first line
                + (len(self.prefix) + 2)  # Padding of subsequent lines
                * (extralabel_full + bool(extralabel_rem)) +
                text_width(var_label) + 2  # for ": "
            )

            _attr = [(apfx + "label", labellen),
                     (apfx + "value", totallen - labellen)]
            from urwid.util import rle_subseg

            fullcols, rem = divmod(totallen, maxcol)

            attr = [
                rle_subseg(_attr, i * maxcol, (i + 1) * maxcol)
                for i in xrange(fullcols + bool(rem))
            ]

            return make_canvas(text, attr, maxcol, apfx + "value")

        lprefix = len(self.prefix)

        if self.value_str is not None:
            if self.var_label is not None:
                if len(self._get_wrapped_lines(maxcol)) > 1:
                    # label too long? generate separate value line
                    text = [
                        self.prefix + self.var_label + ":",
                        self.prefix + "  " + self.value_str
                    ]

                    attr = [[(apfx + "label",
                              lprefix + text_width(self.var_label) + 1)],
                            [(apfx + "value",
                              lprefix + 2 + text_width(self.value_str))]]
                else:
                    text = [
                        self.prefix + self.var_label + ": " + self.value_str
                    ]

                    attr = [[
                        (apfx + "label",
                         lprefix + text_width(self.var_label) + 2),
                        (apfx + "value", text_width(self.value_str)),
                    ]]
            else:
                text = [self.prefix + self.value_str]

                attr = [[
                    (apfx + "label", len(self.prefix)),
                    (apfx + "value", text_width(self.value_str)),
                ]]
        else:
            text = [self.prefix + self.var_label]

            attr = [[
                (apfx + "label", lprefix + text_width(self.var_label)),
            ]]

        # Ellipses to show text was cut off
        #encoding = urwid.util.detected_encoding

        if False:  # encoding[:3] == "UTF":
            # Unicode is supported, use single character ellipsis
            for i in xrange(len(text)):
                if len(text[i]) > maxcol:
                    text[i] = (
                        unicode(text[i][:maxcol - 1])  # noqa: F821
                        + ELLIPSIS + unicode(text[i][maxcol:]))  # noqa: F821
                    # XXX: This doesn't work.  It just gives a ?
                    # Strangely, the following does work (it gives the …
                    # three characters from the right):
                    #
                    # text[i] = (unicode(text[i][:maxcol-3])
                    # + unicode(u'…')) + unicode(text[i][maxcol-2:])
        else:
            for i in xrange(len(text)):
                if text_width(text[i]) > maxcol:
                    text[i] = text[i][:maxcol - 3] + "..."

        return make_canvas(text, attr, maxcol, apfx + "value")
Ejemplo n.º 10
0
            if not self.has_breakpoint:
                attrs.append("highlighted")

        if not attrs and self.attr is not None:
            attr = self.attr
            if render_line_nr:
                attr = [("line number", len(self.line_nr))] + attr
        else:
            attr = [(" ".join(attrs + ["source"]), hscroll + maxcol - 2)]

        from urwid.util import rle_subseg, rle_len

        text = self.text
        if self.dbg_ui.source_hscroll_start:
            text = text[hscroll:]
            attr = rle_subseg(attr, self.dbg_ui.source_hscroll_start,
                              rle_len(attr))

        if render_line_nr:
            text = self.line_nr + text

        text = crnt + bp + text
        attr = [("source", 1), ("bp_star", 1)] + attr

        # clipping ------------------------------------------------------------
        if len(text) > maxcol:
            text = text[:maxcol]
            attr = rle_subseg(attr, 0, maxcol)

        # shipout -------------------------------------------------------------
        from urwid.util import apply_target_encoding
        txt, cs = apply_target_encoding(text)
Ejemplo n.º 11
0
    def render(self, size: Tuple[int], focus: bool = False) -> urwid.Canvas:
        """
        :param size: (maxcol,) the number of columns available to this widget
        :param focus: True if this widget or one of its children is in focus
        :return: A Canvas subclass instance containing the rendered content of
            this widget
        """
        from pudb.ui_tools import make_canvas

        maxcol = size[0]
        if focus:
            apfx = "focused " + self.attr_prefix + " "
        else:
            apfx = self.attr_prefix + " "

        var_label = self.var_label or ""

        if self.wrap:
            text = self._get_wrapped_lines(maxcol)

            extralabel_full, extralabel_rem = divmod(
                text_width(var_label[maxcol:]), maxcol)
            totallen = sum([text_width(i) for i in text])
            labellen = (
                len(self.prefix)  # Padding of first line
                + (len(self.prefix) + 2)  # Padding of subsequent lines
                * (extralabel_full + bool(extralabel_rem)) +
                text_width(var_label) + 2  # for ": "
            )

            _attr = [(apfx + "label", labellen),
                     (apfx + "value", totallen - labellen)]
            from urwid.util import rle_subseg

            fullcols, rem = divmod(totallen, maxcol)

            attr = [
                rle_subseg(_attr, i * maxcol, (i + 1) * maxcol)
                for i in range(fullcols + bool(rem))
            ]

            return make_canvas(text, attr, maxcol, apfx + "value")

        lprefix = len(self.prefix)

        if self.value_str is not None:
            if self.var_label is not None:
                if len(self._get_wrapped_lines(maxcol)) > 1:
                    # label too long? generate separate value line
                    text = [
                        self.prefix + self.var_label + ":",
                        self.prefix + "  " + self.value_str
                    ]

                    attr = [[(apfx + "label",
                              lprefix + text_width(self.var_label) + 1)],
                            [(apfx + "value",
                              lprefix + 2 + text_width(self.value_str))]]
                else:
                    text = [
                        self.prefix + self.var_label + ": " + self.value_str
                    ]

                    attr = [[
                        (apfx + "label",
                         lprefix + text_width(self.var_label) + 2),
                        (apfx + "value", text_width(self.value_str)),
                    ]]
            else:
                text = [self.prefix + self.value_str]

                attr = [[
                    (apfx + "label", len(self.prefix)),
                    (apfx + "value", text_width(self.value_str)),
                ]]
        else:
            text = [self.prefix + self.var_label]

            attr = [[
                (apfx + "label", lprefix + text_width(self.var_label)),
            ]]

        # Ellipses to show text was cut off
        #encoding = urwid.util.detected_encoding

        for i in range(len(text)):
            if text_width(text[i]) > maxcol:
                text[i] = text[i][:maxcol - 3] + "..."

        return make_canvas(text, attr, maxcol, apfx + "value")