mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Handle no_color flag in formats with colored titles
This commit is contained in:
parent
6c5d0484ba
commit
761c846583
@ -84,11 +84,13 @@ class Command(BaseCommand):
|
|||||||
url_patterns.sort()
|
url_patterns.sort()
|
||||||
|
|
||||||
# Apply colors
|
# Apply colors
|
||||||
if (
|
self.is_color_enabled = (
|
||||||
color.supports_color()
|
color.supports_color()
|
||||||
and (not no_color)
|
and (not no_color)
|
||||||
and (format not in COLORLESS_FORMATS)
|
and (format not in COLORLESS_FORMATS)
|
||||||
):
|
)
|
||||||
|
|
||||||
|
if self.is_color_enabled:
|
||||||
url_patterns = self.apply_color(url_patterns=url_patterns)
|
url_patterns = self.apply_color(url_patterns=url_patterns)
|
||||||
|
|
||||||
# Apply formatting
|
# Apply formatting
|
||||||
@ -140,11 +142,10 @@ class Command(BaseCommand):
|
|||||||
widths.append(len(max(columns, key=len)) + margin)
|
widths.append(len(max(columns, key=len)) + margin)
|
||||||
|
|
||||||
# Headers
|
# Headers
|
||||||
headers = (
|
headers = ["Route", "View", "Name"]
|
||||||
self.style.HEADER("Route"),
|
|
||||||
self.style.HEADER("View"),
|
if self.is_color_enabled:
|
||||||
self.style.HEADER("Name"),
|
headers = [self.style.HEADER(header) for header in headers]
|
||||||
)
|
|
||||||
|
|
||||||
header_parts = []
|
header_parts = []
|
||||||
for width, header in zip(widths, headers, strict=False):
|
for width, header in zip(widths, headers, strict=False):
|
||||||
@ -189,9 +190,18 @@ class Command(BaseCommand):
|
|||||||
formatted_str = StringIO()
|
formatted_str = StringIO()
|
||||||
|
|
||||||
for route, view, name in url_patterns:
|
for route, view, name in url_patterns:
|
||||||
route_str = f"{self.style.HEADER('Route:')} {route}"
|
route_title = "Route:"
|
||||||
view_str = f"{self.style.HEADER('View:')} {view}"
|
view_title = "View:"
|
||||||
name_str = f"{self.style.HEADER('Name:')} {name}" if name else ""
|
name_title = "Name:"
|
||||||
|
|
||||||
|
if self.is_color_enabled:
|
||||||
|
route_title = self.style.HEADER(route_title)
|
||||||
|
view_title = self.style.HEADER(view_title)
|
||||||
|
name_title = self.style.HEADER(name_title)
|
||||||
|
|
||||||
|
route_str = f"{route_title} {route}"
|
||||||
|
view_str = f"{view_title} {view}"
|
||||||
|
name_str = f"{name_title} {name}" if name else ""
|
||||||
|
|
||||||
separator = "-" * 20 + "\n"
|
separator = "-" * 20 + "\n"
|
||||||
parts = (
|
parts = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user