File tree Expand file tree Collapse file tree 3 files changed +30
-29
lines changed Expand file tree Collapse file tree 3 files changed +30
-29
lines changed Original file line number Diff line number Diff line change 11import logging
2- from os import get_terminal_size
3- from typing import List , Union
42
53from django_utils_lib .constants import PACKAGE_NAME
64
75pkg_logger = logging .getLogger (PACKAGE_NAME )
86pkg_logger .setLevel (logging .INFO )
9-
10-
11- def build_heading_block (heading : Union [str , List [str ]], border_width = 2 ) -> str :
12- """
13- Generate a heading, like:
14- ```
15- ===============
16- == Hello ==
17- ===============
18- ```
19- """
20- terminal_width = get_terminal_size ().columns
21- heading_delim = "" .ljust (terminal_width , "=" )
22- heading_lines = [heading_delim ]
23-
24- # Leave space for border, plus one space on each side
25- border = "=" * border_width
26- border_width_total = border_width + 1
27-
28- for line in heading if isinstance (heading , list ) else heading .splitlines ():
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 } " )
32- heading_lines .append (heading_delim )
33-
34- return "\n " .join (heading_lines )
Original file line number Diff line number Diff line change 1+ from os import get_terminal_size
2+ from typing import List , Union
3+
4+
5+ def build_heading_block (heading : Union [str , List [str ]], border_width = 2 ) -> str :
6+ """
7+ Generate a heading, like:
8+ ```
9+ ===============
10+ == Hello ==
11+ ===============
12+ ```
13+ """
14+ terminal_width = get_terminal_size ().columns
15+ heading_delim = "" .ljust (terminal_width , "=" )
16+ heading_lines = [heading_delim ]
17+
18+ # Leave space for border, plus one space on each side
19+ border = "=" * border_width
20+ border_width_total = border_width + 1
21+
22+ for line in heading if isinstance (heading , list ) else heading .splitlines ():
23+ left_inner_padding = int ((terminal_width - len (line ) - (border_width_total * 2 )) / 2 )
24+ right_inner_padding = int (terminal_width - left_inner_padding - len (line ) - (border_width_total * 2 ))
25+ heading_lines .append (f"{ border } { ' ' * left_inner_padding } { line } { ' ' * right_inner_padding } { border } " )
26+ heading_lines .append (heading_delim )
27+
28+ return "\n " .join (heading_lines )
Original file line number Diff line number Diff line change 2525from typing_extensions import NotRequired , TypedDict
2626
2727from django_utils_lib .constants import PACKAGE_NAME
28- from django_utils_lib .logger import build_heading_block , pkg_logger
28+ from django_utils_lib .logger import pkg_logger
29+ from django_utils_lib .logging_utils import build_heading_block
2930from django_utils_lib .testing .utils import PytestNodeID , is_main_pytest_runner , validate_requirement_tagging
3031
3132BASE_DIR = Path (__file__ ).resolve ().parent
You can’t perform that action at this time.
0 commit comments