mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-21 22:58:24 +00:00
Fix text truncation for full-width characters (#4278)
* Fix text truncation for full-width characters * Add test for TruncatedText
This commit is contained in:
parent
6d67a405a9
commit
0454f63e98
@ -18,6 +18,8 @@
|
||||
([#5217](https://github.com/mitmproxy/mitmproxy/issues/5217), @randomstuff)
|
||||
* Improve cut addon to better handle binary contents
|
||||
([#3965](https://github.com/mitmproxy/mitmproxy/issues/3965), @mhils)
|
||||
* Fix text truncation for full-width characters
|
||||
([#4278](https://github.com/mitmproxy/mitmproxy/issues/4278), @kjy00302)
|
||||
|
||||
## 19 March 2022: mitmproxy 8.0.0
|
||||
|
||||
|
@ -191,7 +191,7 @@ class TruncatedText(urwid.Widget):
|
||||
text = text[::-1]
|
||||
attr = attr[::-1]
|
||||
|
||||
text_len = len(text) # TODO: unicode?
|
||||
text_len = urwid.util.calc_width(text, 0, len(text))
|
||||
if size is not None and len(size) > 0:
|
||||
width = size[0]
|
||||
else:
|
||||
@ -206,8 +206,10 @@ class TruncatedText(urwid.Widget):
|
||||
c_text = text
|
||||
c_attr = attr
|
||||
else:
|
||||
visible_len = width - len(SYMBOL_ELLIPSIS)
|
||||
visible_text = text[0:visible_len]
|
||||
trim = urwid.util.calc_trim_text(text, 0, width - 1, 0, width - 1)
|
||||
visible_text = text[0:trim[1]]
|
||||
if trim[3] == 1:
|
||||
visible_text += ' '
|
||||
c_text = visible_text + SYMBOL_ELLIPSIS
|
||||
c_attr = (urwid.util.rle_subseg(attr, 0, len(visible_text.encode())) +
|
||||
[('focus', len(SYMBOL_ELLIPSIS.encode()))])
|
||||
|
@ -36,3 +36,10 @@ def test_format_keyvals():
|
||||
("aa", wrapped)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_truncated_text():
|
||||
half_width_text = common.TruncatedText("Half-width", [])
|
||||
full_width_text = common.TruncatedText("FULL-WIDTH", [])
|
||||
assert half_width_text.render((10,))
|
||||
assert full_width_text.render((10,))
|
||||
|
Loading…
Reference in New Issue
Block a user