@@ -637,21 +637,21 @@ class TextAlignment(Enum):
637637 RIGHT = 3
638638
639639
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 :
642642 """
643643 Align text for display within a given width. Supports characters with display widths greater than 1.
644644 ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
645645 supported. If text has line breaks, then each line is aligned independently.
646646
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 ()
648648
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
650651 :param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
651652 :param width: display width of the aligned text. Defaults to width of the terminal.
652653 :param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
653654 be converted to a space.
654- :param alignment: how to align the text
655655 :return: aligned text
656656 :raises: TypeError if fill_char is more than one character
657657 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,
725725 return text_buf .getvalue ()
726726
727727
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 :
729729 """
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.
731731 ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
732732 supported. If text has line breaks, then each line is aligned independently.
733733
734- :param text: text to left justify (Can contain multiple lines)
734+ :param text: text to left align (can contain multiple lines)
735735 :param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
736736 :param width: display width of the aligned text. Defaults to width of the terminal.
737737 :param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
738738 be converted to a space.
739- :return: left-justified text
739+ :return: left-aligned text
740740 :raises: TypeError if fill_char is more than one character
741741 ValueError if text or fill_char contains an unprintable character
742742 """
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 )
745744
746745
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 :
748747 """
749748 Center text for display within a given width. Supports characters with display widths greater than 1.
750749 ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
751750 supported. If text has line breaks, then each line is aligned independently.
752751
753- :param text: text to center (Can contain multiple lines)
752+ :param text: text to center (can contain multiple lines)
754753 :param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
755754 :param width: display width of the aligned text. Defaults to width of the terminal.
756755 :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,
759758 :raises: TypeError if fill_char is more than one character
760759 ValueError if text or fill_char contains an unprintable character
761760 """
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 )
764762
765763
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 :
767765 """
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.
769767 ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is
770768 supported. If text has line breaks, then each line is aligned independently.
771769
772- :param text: text to right justify (Can contain multiple lines)
770+ :param text: text to right align (can contain multiple lines)
773771 :param fill_char: character that fills the alignment gap. Defaults to space. (Cannot be a line breaking character)
774772 :param width: display width of the aligned text. Defaults to width of the terminal.
775773 :param tab_width: any tabs in the text will be replaced with this many spaces. if fill_char is a tab, then it will
776774 be converted to a space.
777- :return: right-justified text
775+ :return: right-aligned text
778776 :raises: TypeError if fill_char is more than one character
779777 ValueError if text or fill_char contains an unprintable character
780778 """
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