This commit is contained in:
Jörn-Michael Miehe 2021-11-27 18:25:38 +01:00
parent 973468be6a
commit 3e52ba6e12

View file

@ -44,34 +44,29 @@ class WParagraph:
def __str__(self) -> str: def __str__(self) -> str:
return "\n".join( return "\n".join(
str(line) str(line)
for line for line in self.lines
in self.lines
) )
@classmethod @classmethod
def from_strings(cls, *source: str) -> "WParagraph": def from_strings(cls, *source: str) -> "WParagraph":
return cls([ return cls([
WString(line) WString(line)
for line for line in source
in source
]) ])
def align(self, alignment: WAlignment = WAlignment.CENTER, padding: int = 0, char: str = " ") -> "WParagraph": def align(self, alignment: WAlignment = WAlignment.CENTER, padding: int = 0, char: str = " ") -> "WParagraph":
total_length = max( total_length = max(
len(line) len(line)
for line for line in self.lines
in self.lines
) + padding ) + padding
pad_lengths = ( pad_lengths = (
total_length - len(line) total_length - len(line)
for line for line in self.lines
in self.lines
) )
return WParagraph([ return WParagraph([
line.pad(alignment, wlen, char) line.pad(alignment, wlen, char)
for line, wlen for line, wlen in zip(self.lines, pad_lengths)
in zip(self.lines, pad_lengths)
]) ])
def surround(self, char: str, padding: int = 1) -> "WParagraph": def surround(self, char: str, padding: int = 1) -> "WParagraph":
@ -82,8 +77,7 @@ class WParagraph:
lines = [ lines = [
WString(f"{l_border}{line}{r_border}") WString(f"{l_border}{line}{r_border}")
for line for line in self.lines
in self.lines
] ]
extra_line = char * len(lines[0]) extra_line = char * len(lines[0])
@ -99,6 +93,5 @@ class WParagraph:
return WParagraph([ return WParagraph([
WString(f"{l_border}{line}{r_border}") WString(f"{l_border}{line}{r_border}")
for line for line in self.lines
in self.lines
]) ])