Skip to content

Commit aca1fce

Browse files
add: formatting support.
1 parent 5aae89c commit aca1fce

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/inscriptis/html_properties.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,32 @@ class HorizontalAlignment(Enum):
4646
center = "^"
4747
"""Center the block's content."""
4848

49+
def format(self, text: str, width: int) -> str:
50+
"""Format the given text to the specified width using the alignment.
51+
52+
Args:
53+
text: The text to format.
54+
width: The width to format the text to.
55+
56+
Returns:
57+
The formatted text.
58+
59+
"""
60+
match self:
61+
case HorizontalAlignment.left:
62+
return text.ljust(width)
63+
case HorizontalAlignment.right:
64+
return text.rjust(width)
65+
case HorizontalAlignment.center:
66+
return text.center(width)
67+
4968

5069
class VerticalAlignment(Enum):
5170
"""Specify the content's vertical alignment."""
5271

53-
top = 1
72+
top = 0
5473
"""Align all content at the top."""
55-
middle = 2
74+
middle = 1
5675
"""Align all content in the middle."""
57-
bottom = 3
76+
bottom = 2
5877
"""Align all content at the bottom."""

0 commit comments

Comments
 (0)