Skip to content

Commit c435303

Browse files
Fix button width when non English characters are displayed
1 parent 3374ae9 commit c435303

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/prompt_toolkit/widgets/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ def get_style() -> str:
438438
def _get_text_fragments(self) -> StyleAndTextTuples:
439439
width = self.width - (
440440
get_cwidth(self.left_symbol) + get_cwidth(self.right_symbol)
441+
) + (
442+
len(self.text) - get_cwidth(self.text)
441443
)
442-
text = (f"{{:^{width}}}").format(self.text)
444+
text = (f"{{:^{max(0,width)}}}").format(self.text)
443445

444446
def handler(mouse_event: MouseEvent) -> None:
445447
if (

0 commit comments

Comments
 (0)