1
1
import logging
2
2
from os import get_terminal_size
3
- from typing import List
3
+ from typing import List , Union
4
4
5
5
from django_utils_lib .constants import PACKAGE_NAME
6
6
7
7
pkg_logger = logging .getLogger (PACKAGE_NAME )
8
8
pkg_logger .setLevel (logging .INFO )
9
9
10
10
11
- def build_heading_block (heading : str | List [str ], border_width = 2 ) -> str :
11
+ def build_heading_block (heading : Union [ str , List [str ] ], border_width = 2 ) -> str :
12
12
"""
13
13
Generate a heading, like:
14
14
```
@@ -26,15 +26,9 @@ def build_heading_block(heading: str | List[str], border_width=2) -> str:
26
26
border_width_total = border_width + 1
27
27
28
28
for line in heading if isinstance (heading , list ) else heading .splitlines ():
29
- left_inner_padding = int (
30
- (terminal_width - len (line ) - (border_width_total * 2 )) / 2
31
- )
32
- right_inner_padding = int (
33
- terminal_width - left_inner_padding - len (line ) - (border_width_total * 2 )
34
- )
35
- heading_lines .append (
36
- f"{ border } { ' ' * left_inner_padding } { line } { ' ' * right_inner_padding } { border } "
37
- )
29
+ left_inner_padding = int ((terminal_width - len (line ) - (border_width_total * 2 )) / 2 )
30
+ right_inner_padding = int (terminal_width - left_inner_padding - len (line ) - (border_width_total * 2 ))
31
+ heading_lines .append (f"{ border } { ' ' * left_inner_padding } { line } { ' ' * right_inner_padding } { border } " )
38
32
heading_lines .append (heading_delim )
39
33
40
34
return "\n " .join (heading_lines )
0 commit comments