mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 02:21:46 +04:00
fix CJK characters width in output
This commit is contained in:
parent
528c7afd18
commit
11e02c71b4
1 changed files with 7 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
from unicodedata import east_asian_width
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Collection
|
from typing import Collection
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
@ -33,8 +34,12 @@ from pre_commit.util import EnvironT
|
||||||
logger = logging.getLogger('pre_commit')
|
logger = logging.getLogger('pre_commit')
|
||||||
|
|
||||||
|
|
||||||
|
def _len_cjk(msg: str) -> int:
|
||||||
|
return len(msg) + len([c for c in msg if east_asian_width(c) in 'FW'])
|
||||||
|
|
||||||
|
|
||||||
def _start_msg(*, start: str, cols: int, end_len: int) -> str:
|
def _start_msg(*, start: str, cols: int, end_len: int) -> str:
|
||||||
dots = '.' * (cols - len(start) - end_len - 1)
|
dots = '.' * (cols - _len_cjk(start) - end_len - 1)
|
||||||
return f'{start}{dots}'
|
return f'{start}{dots}'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -47,7 +52,7 @@ def _full_msg(
|
||||||
use_color: bool,
|
use_color: bool,
|
||||||
postfix: str = '',
|
postfix: str = '',
|
||||||
) -> str:
|
) -> str:
|
||||||
dots = '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1)
|
dots = '.' * (cols - _len_cjk(start) - len(postfix) - len(end_msg) - 1)
|
||||||
end = color.format_color(end_msg, end_color, use_color)
|
end = color.format_color(end_msg, end_color, use_color)
|
||||||
return f'{start}{dots}{postfix}{end}\n'
|
return f'{start}{dots}{postfix}{end}\n'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue