MCPcopy
hub / github.com/mitmproxy/mitmproxy / render

Method render

mitmproxy/tools/console/common.py:184–219  ·  view source on GitHub ↗
(self, size, focus=False)

Source from the content-addressed store, hash-verified

182 return 1
183
184 def render(self, size, focus=False):
185 text = self.text
186 attr = self.attr
187 if self.align == "right":
188 text = text[::-1]
189 attr = attr[::-1]
190
191 text_len = urwid.calc_width(text, 0, len(text))
192 if size is not None and len(size) > 0:
193 width = size[0]
194 else:
195 width = text_len
196
197 if width >= text_len:
198 remaining = width - text_len
199 if remaining > 0:
200 c_text = text + " " * remaining
201 c_attr = attr + [("text", remaining)]
202 else:
203 c_text = text
204 c_attr = attr
205 else:
206 trim = urwid.util.calc_trim_text(text, 0, width - 1, 0, width - 1)
207 visible_text = text[0 : trim[1]]
208 if trim[3] == 1:
209 visible_text += " "
210 c_text = visible_text + SYMBOL_ELLIPSIS
211 c_attr = urwid.util.rle_subseg(attr, 0, len(visible_text.encode())) + [
212 ("focus", len(SYMBOL_ELLIPSIS.encode()))
213 ]
214
215 if self.align == "right":
216 c_text = c_text[::-1]
217 c_attr = c_attr[::-1]
218
219 return urwid.TextCanvas([c_text.encode()], [c_attr], maxcol=width)
220
221
222def truncated_plain(text, attr, align="left"):

Callers 6

test_truncated_textFunction · 0.95
test_format_keyvalsFunction · 0.45
test_cycle_completionMethod · 0.45
screen_contentsMethod · 0.45
mqFunction · 0.45

Calls 1

encodeMethod · 0.45

Tested by 4

test_truncated_textFunction · 0.76
test_format_keyvalsFunction · 0.36
test_cycle_completionMethod · 0.36
screen_contentsMethod · 0.36