@@ -483,17 +483,18 @@ def _afterpoint(string):
483
483
else :
484
484
return - 1 # not a number
485
485
486
-
487
486
def _padleft (width , s ):
488
487
"""Flush right.
489
488
490
489
>>> _padleft(6, '\u044f \u0439 \u0446 \u0430 ') == ' \u044f \u0439 \u0446 \u0430 '
491
490
True
492
491
493
492
"""
494
- fmt = "{0:>%ds}" % width
495
- return fmt .format (s )
496
-
493
+ vis = _strip_invisible (s )
494
+ pad = width - len (vis )
495
+ if pad > 0 :
496
+ s = " " * pad + s
497
+ return s
497
498
498
499
def _padright (width , s ):
499
500
"""Flush left.
@@ -502,9 +503,11 @@ def _padright(width, s):
502
503
True
503
504
504
505
"""
505
- fmt = "{0:<%ds}" % width
506
- return fmt .format (s )
507
-
506
+ vis = _strip_invisible (s )
507
+ pad = width - len (vis )
508
+ if pad > 0 :
509
+ s = s + " " * pad
510
+ return s
508
511
509
512
def _padboth (width , s ):
510
513
"""Center string.
@@ -513,8 +516,12 @@ def _padboth(width, s):
513
516
True
514
517
515
518
"""
516
- fmt = "{0:^%ds}" % width
517
- return fmt .format (s )
519
+ vis = _strip_invisible (s )
520
+ pad = width - len (vis )
521
+ if pad > 0 :
522
+ pad_l = pad // 2
523
+ s = " " * pad_l + s + " " * (pad - pad_l )
524
+ return s
518
525
519
526
520
527
def _padnone (ignore_width , s ):
@@ -614,7 +621,7 @@ def _align_column(strings, alignment, minwidth=0,
614
621
for ms in strings ]
615
622
else :
616
623
# enable wide-character width corrections
617
- s_lens = [max ((len (s ) for s in re .split ("[\r \n ]" , ms ))) for ms in strings ]
624
+ s_lens = [max ((width_fn (s ) for s in re .split ("[\r \n ]" , ms ))) for ms in strings ]
618
625
visible_widths = [maxwidth - (w - l ) for w , l in zip (s_widths , s_lens )]
619
626
# wcswidth and _visible_width don't count invisible characters;
620
627
# padfn doesn't need to apply another correction
@@ -625,7 +632,7 @@ def _align_column(strings, alignment, minwidth=0,
625
632
padded_strings = [padfn (maxwidth , s ) for s in strings ]
626
633
else :
627
634
# enable wide-character width corrections
628
- s_lens = list (map (len , strings ))
635
+ s_lens = list (map (width_fn , strings ))
629
636
visible_widths = [maxwidth - (w - l ) for w , l in zip (s_widths , s_lens )]
630
637
# wcswidth and _visible_width don't count invisible characters;
631
638
# padfn doesn't need to apply another correction
0 commit comments