mirror of
https://github.com/ihabunek/toot.git
synced 2025-10-21 19:44:16 -04:00
Fix left column padding in timeline with wide characters
When the left column contains wide characters (which occupy more than
one cell when printed to screen), padding to 30-characters with
"{:30}".format() does not work well. This happens for instance when the
display name contains unicode characters such as emojis.
We fix this by introducing a pad() function in utils module which uses
the wcwidth library (https://pypi.org/project/wcwidth/) to compute the
length of the text for the column. trunc() function is also adjusted to
optionally compute the length of the text to be truncated since, when
called from pad(), we now pre-compute this value.
We update test for timeline rendering so that the display name now
includes an emoji. (Without the fix, the test would not pass as left
column would be misaligned.)
This commit is contained in:
committed by
Ivan Habunek
parent
9d6cd87202
commit
0bf4b2a21a
14
tests/test_utils.py
Normal file
14
tests/test_utils.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from toot import utils
|
||||
|
||||
|
||||
def test_pad():
|
||||
text = 'Frank Zappa 🎸'
|
||||
padded = utils.pad(text, 14)
|
||||
assert padded == 'Frank Zappa 🎸'
|
||||
# guitar symbol will occupy two cells, so padded text should be 1
|
||||
# character shorter
|
||||
assert len(padded) == 13
|
||||
# when truncated, … occupies one cell, so we get full length
|
||||
padded = utils.pad(text, 13)
|
||||
assert padded == 'Frank Zappa …'
|
||||
assert len(padded) == 13
|
||||
Reference in New Issue
Block a user