Skip to content

fix CJK characters width in output - #1378

Merged
asottile merged 1 commit into
pre-commit:masterfrom
sophgn:master
Mar 28, 2020
Merged

fix CJK characters width in output#1378
asottile merged 1 commit into
pre-commit:masterfrom
sophgn:master

Conversation

@sophgn

@sophgn sophgn commented Mar 27, 2020

Copy link
Copy Markdown
Contributor

No description provided.

@asottile asottile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a test for this? there are other tests here:

def test_start_msg():
ret = _start_msg(start='start', end_len=5, cols=15)
# 4 dots: 15 - 5 - 5 - 1
assert ret == 'start....'
def test_full_msg():
ret = _full_msg(
start='start',
end_msg='end',
end_color='',
use_color=False,
cols=15,
)
# 6 dots: 15 - 5 - 3 - 1
assert ret == 'start......end\n'
def test_full_msg_with_color():
ret = _full_msg(
start='start',
end_msg='end',
end_color=color.RED,
use_color=True,
cols=15,
)
# 6 dots: 15 - 5 - 3 - 1
assert ret == f'start......{color.RED}end{color.NORMAL}\n'
def test_full_msg_with_postfix():
ret = _full_msg(
start='start',
postfix='post ',
end_msg='end',
end_color='',
use_color=False,
cols=20,
)
# 6 dots: 20 - 5 - 5 - 3 - 1
assert ret == 'start......post end\n'
def test_full_msg_postfix_not_colored():
ret = _full_msg(
start='start',
postfix='post ',
end_msg='end',
end_color=color.RED,
use_color=True,
cols=20,
)
# 6 dots: 20 - 5 - 5 - 3 - 1
assert ret == f'start......post {color.RED}end{color.NORMAL}\n'

another note since I've been looking into the same thing for a text editor, east_asian_width doesn't necessarily indicate how wide the rendered character is, just what that attribute is. there are some characters which on most terminal emulators render wide without having F/W and some which render narrow while having F/W. then there are some terminal emulators which render it differently than other terminal emulators. (there's also zero-width characters to consider as well!)

I'm ok adding this anyway as-is, just that it's still not perfect for all users / characters / use cases (but I agree it's an improvement)

lastly, please continue working in this PR, don't make a new one like the last two -- it's ok to not have everything right in the first push :)

Comment thread pre_commit/commands/run.py Outdated
Comment thread pre_commit/commands/run.py Outdated
Comment thread pre_commit/commands/run.py Outdated

@asottile asottile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile
asottile merged commit 34e9d11 into pre-commit:master Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants