@@ -560,14 +560,37 @@ def pad_right(self, count: int, character: str = " ") -> Content:
560560 )
561561 return self
562562
563- def center (self , width : int , overflow : OverflowMethod = "fold" ) -> Content :
564- content = self .rstrip ().truncate (width , overflow = overflow )
565- content = content .pad_left ((width - content .cell_length ) // 2 )
566- content = content .pad_right (width - content .cell_length )
563+ def center (self , width : int , ellipsis : bool = False ) -> Content :
564+ """Align a line to the center.
565+
566+ Args:
567+ width: Desired width of output.
568+ ellipsis: Insert ellipsis if content is truncated.
569+
570+ Returns:
571+ New line Content.
572+ """
573+ content = self .rstrip ().truncate (
574+ width , overflow = "ellipsis" if ellipsis else "fold"
575+ )
576+ left = (content .cell_length - width ) // 2
577+ right = width = left
578+ content = content .pad_left (left ).pad_right (right )
567579 return content
568580
569- def right (self , width : int , overflow : OverflowMethod = "fold" ) -> Content :
570- content = self .rstrip ().truncate (width , overflow = overflow )
581+ def right (self , width : int , ellipsis : bool = False ) -> Content :
582+ """Align a line to the right.
583+
584+ Args:
585+ width: Desired width of output.
586+ ellipsis: Insert ellipsis if content is truncated.
587+
588+ Returns:
589+ New line Content.
590+ """
591+ content = self .rstrip ().truncate (
592+ width , overflow = "ellipsis" if ellipsis else "fold"
593+ )
571594 content = content .pad_left (width - content .cell_length )
572595 return content
573596
0 commit comments