def test_byte_boundary(): text = u'aaaaaaé' canvas = make_canvas( txt=[text], attr=[[('var value', len(text))]], maxcol=len(text) ) assert list(canvas.content()) == [[('var value', None, b'aaaaaa\xc3\xa9')]]
def test_simple(): text = u'aaaaaa' canvas = make_canvas( txt=[text], attr=[[('var value', len(text))]], maxcol=len(text) + 5 ) content = list(canvas.content()) assert content == [ [('var value', None, b'aaaaaa'), (None, None, b' ' * 5)] ]
def test_multiple(): canvas = make_canvas( txt=[u'Return: None'], attr=[[('return label', 8), ('return value', 4)]], maxcol=100 ) content = list(canvas.content()) assert content == [ [('return label', None, b'Return: '), ('return value', None, b'None'), (None, None, b' ' * 88)] ]
def render(self, size, focus=False): maxcol = size[0] if focus: apfx = "focused " + self.attr_prefix + " " else: apfx = self.attr_prefix + " " if self.value_str is not None: if self.var_label is not None: if len(self.prefix) + len(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", len(self.prefix) + len(self.var_label))], [(apfx + "value", len(self.prefix) + 2 + len(self.value_str))], ] else: text = [self.prefix + self.var_label + ": " + self.value_str] attr = [ [ (apfx + "label", len(self.prefix) + len(self.var_label) + 2), (apfx + "value", len(self.value_str)), ] ] else: text = [self.prefix + self.value_str] attr = [[(apfx + "label", len(self.prefix)), (apfx + "value", len(self.value_str))]] else: text = [self.prefix + self.var_label] attr = [[(apfx + "label", len(self.prefix) + len(self.var_label))]] from pudb.ui_tools import make_canvas return make_canvas(text, attr, maxcol, apfx + "value")
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")
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")