diff options
author | Toluwaleke Ogundipe <anonymoux47@gmail.com> | 2023-04-24 11:13:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-24 12:13:41 +0200 |
commit | 6bf74be23f3179d87d4f40d45d2a4e8718ab26f5 (patch) | |
tree | a3288fbe494d1145a2f3f0a76f9760db5983743f | |
parent | 350ee5c47ff565d3b0d25b1c3cbddbfb2a0a2a4f (diff) | |
download | urwid-6bf74be23f3179d87d4f40d45d2a4e8718ab26f5.tar.gz |
Fix text layout for `align="center", wrap="clip"` when `maxcol` == `line_width - 1` (#543)
* Fix text layout for `align="center", wrap="clip"`
- Fix: Prevent zero run length in text layout.
Refs: urwid#542
* Add test for "clip" text layout fix
Refs: #542
-rw-r--r-- | urwid/tests/test_text_layout.py | 17 | ||||
-rw-r--r-- | urwid/text_layout.py | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/urwid/tests/test_text_layout.py b/urwid/tests/test_text_layout.py index 77bd27d..c87d12c 100644 --- a/urwid/tests/test_text_layout.py +++ b/urwid/tests/test_text_layout.py @@ -292,6 +292,23 @@ class CalcTranslateClipTest(CalcTranslateTest, unittest.TestCase): [(7, None), (0, 35)], [(14, 36, 50), (0, 50)]] +class CalcTranslateClipTest2(CalcTranslateTest, unittest.TestCase): + text = "Hello!\nto\nWorld!" + mode = 'clip' + width = 5 # line width (of first and last lines) minus one + result_left = [ + [(6, 0, 6), (0, 6)], + [(2, 7, 9), (0, 9)], + [(6, 10, 16), (0, 16)]] + result_right = [ + [(-1, None), (6, 0, 6), (0, 6)], + [(3, None), (2, 7, 9), (0, 9)], + [(-1, None), (6, 10, 16), (0, 16)]] + result_center = [ + [(6, 0, 6), (0, 6)], + [(2, None), (2, 7, 9), (0, 9)], + [(6, 10, 16), (0, 16)]] + class CalcTranslateCantDisplayTest(CalcTranslateTest, unittest.TestCase): text = b'Hello\xe9\xa2\x96' mode = 'space' diff --git a/urwid/text_layout.py b/urwid/text_layout.py index aacb36d..8813cd9 100644 --- a/urwid/text_layout.py +++ b/urwid/text_layout.py @@ -139,7 +139,8 @@ class StandardTextLayout(TextLayout): out.append([(width-sc, None)] + l) continue assert align == 'center' - out.append([((width-sc+1) // 2, None)] + l) + pad_trim_left = (width-sc+1) // 2 + out.append([(pad_trim_left, None)] + l if pad_trim_left else l) return out def calculate_text_segments( |