@@ -637,21 +637,21 @@ class TextAlignment(Enum):
637
637
RIGHT = 3
638
638
639
639
640
- def align_text (text : str , * , fill_char : str = ' ' , width : Optional [ int ] = None , tab_width : int = 4 ,
641
- alignment : TextAlignment ) -> str :
640
+ def align_text (text : str , alignment : TextAlignment , * , fill_char : str = ' ' ,
641
+ width : Optional [ int ] = None , tab_width : int = 4 ) -> str :
642
642
"""
643
643
Align text for display within a given width. Supports characters with display widths greater than 1.
644
644
ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
645
645
supported. If text has line breaks, then each line is aligned independently.
646
646
647
- There are convenience wrappers around this function: ljustify_text (), center_text (), and rjustify_text ()
647
+ There are convenience wrappers around this function: align_left (), align_center (), and align_right ()
648
648
649
- :param text: text to align (Can contain multiple lines)
649
+ :param text: text to align (can contain multiple lines)
650
+ :param alignment: how to align the text
650
651
:param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
651
652
:param width: display width of the aligned text. Defaults to width of the terminal.
652
653
:param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
653
654
be converted to a space.
654
- :param alignment: how to align the text
655
655
:return: aligned text
656
656
:raises: TypeError if fill_char is more than one character
657
657
ValueError if text or fill_char contains an unprintable character
@@ -725,32 +725,31 @@ def align_text(text: str, *, fill_char: str = ' ', width: Optional[int] = None,
725
725
return text_buf .getvalue ()
726
726
727
727
728
- def ljustify_text (text : str , * , fill_char : str = ' ' , width : Optional [int ] = None , tab_width : int = 4 ) -> str :
728
+ def align_left (text : str , * , fill_char : str = ' ' , width : Optional [int ] = None , tab_width : int = 4 ) -> str :
729
729
"""
730
- Left justify text for display within a given width. Supports characters with display widths greater than 1.
730
+ Left align text for display within a given width. Supports characters with display widths greater than 1.
731
731
ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
732
732
supported. If text has line breaks, then each line is aligned independently.
733
733
734
- :param text: text to left justify (Can contain multiple lines)
734
+ :param text: text to left align (can contain multiple lines)
735
735
:param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
736
736
:param width: display width of the aligned text. Defaults to width of the terminal.
737
737
:param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
738
738
be converted to a space.
739
- :return: left-justified text
739
+ :return: left-aligned text
740
740
:raises: TypeError if fill_char is more than one character
741
741
ValueError if text or fill_char contains an unprintable character
742
742
"""
743
- return align_text (text , fill_char = fill_char , width = width ,
744
- tab_width = tab_width , alignment = TextAlignment .LEFT )
743
+ return align_text (text , TextAlignment .LEFT , fill_char = fill_char , width = width , tab_width = tab_width )
745
744
746
745
747
- def center_text (text : str , * , fill_char : str = ' ' , width : Optional [int ] = None , tab_width : int = 4 ) -> str :
746
+ def align_center (text : str , * , fill_char : str = ' ' , width : Optional [int ] = None , tab_width : int = 4 ) -> str :
748
747
"""
749
748
Center text for display within a given width. Supports characters with display widths greater than 1.
750
749
ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
751
750
supported. If text has line breaks, then each line is aligned independently.
752
751
753
- :param text: text to center (Can contain multiple lines)
752
+ :param text: text to center (can contain multiple lines)
754
753
:param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
755
754
:param width: display width of the aligned text. Defaults to width of the terminal.
756
755
:param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
@@ -759,24 +758,22 @@ def center_text(text: str, *, fill_char: str = ' ', width: Optional[int] = None,
759
758
:raises: TypeError if fill_char is more than one character
760
759
ValueError if text or fill_char contains an unprintable character
761
760
"""
762
- return align_text (text , fill_char = fill_char , width = width ,
763
- tab_width = tab_width , alignment = TextAlignment .CENTER )
761
+ return align_text (text , TextAlignment .CENTER , fill_char = fill_char , width = width , tab_width = tab_width )
764
762
765
763
766
- def rjustify_text (text : str , * , fill_char : str = ' ' , width : Optional [int ] = None , tab_width : int = 4 ) -> str :
764
+ def align_right (text : str , * , fill_char : str = ' ' , width : Optional [int ] = None , tab_width : int = 4 ) -> str :
767
765
"""
768
- Right justify text for display within a given width. Supports characters with display widths greater than 1.
766
+ Right align text for display within a given width. Supports characters with display widths greater than 1.
769
767
ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
770
768
supported. If text has line breaks, then each line is aligned independently.
771
769
772
- :param text: text to right justify (Can contain multiple lines)
770
+ :param text: text to right align (can contain multiple lines)
773
771
:param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
774
772
:param width: display width of the aligned text. Defaults to width of the terminal.
775
773
:param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
776
774
be converted to a space.
777
- :return: right-justified text
775
+ :return: right-aligned text
778
776
:raises: TypeError if fill_char is more than one character
779
777
ValueError if text or fill_char contains an unprintable character
780
778
"""
781
- return align_text (text , fill_char = fill_char , width = width ,
782
- tab_width = tab_width , alignment = TextAlignment .RIGHT )
779
+ return align_text (text , TextAlignment .RIGHT , fill_char = fill_char , width = width , tab_width = tab_width )
0 commit comments