mirror of https://github.com/pypa/pip
Use custom renderable object
This allows control over where to place newline
This commit is contained in:
parent
8574e9af31
commit
5e2c07ddf7
|
@ -14,7 +14,6 @@ from typing import (
|
||||||
from pip._vendor.rich.console import (
|
from pip._vendor.rich.console import (
|
||||||
Console,
|
Console,
|
||||||
ConsoleOptions,
|
ConsoleOptions,
|
||||||
Group,
|
|
||||||
RenderableType,
|
RenderableType,
|
||||||
RenderResult,
|
RenderResult,
|
||||||
)
|
)
|
||||||
|
@ -56,7 +55,19 @@ class RenderableLine:
|
||||||
if isinstance(seg, Segment) and seg.text != "\n"
|
if isinstance(seg, Segment) and seg.text != "\n"
|
||||||
]
|
]
|
||||||
yield from segments
|
yield from segments
|
||||||
|
|
||||||
|
|
||||||
|
class RenderableLines:
|
||||||
|
def __init__(self, lines: List[RenderableLine]):
|
||||||
|
self.lines = lines
|
||||||
|
|
||||||
|
def __rich_console__(
|
||||||
|
self, console: Console, options: ConsoleOptions
|
||||||
|
) -> RenderResult:
|
||||||
|
for idx, line in enumerate(self.lines):
|
||||||
|
if idx != 0:
|
||||||
yield Segment.line()
|
yield Segment.line()
|
||||||
|
yield from line.__rich_console__(console, options)
|
||||||
|
|
||||||
|
|
||||||
class PipProgress(Progress):
|
class PipProgress(Progress):
|
||||||
|
@ -111,13 +122,13 @@ class PipProgress(Progress):
|
||||||
"""
|
"""
|
||||||
Get the renderable representation of the progress bars of all tasks
|
Get the renderable representation of the progress bars of all tasks
|
||||||
"""
|
"""
|
||||||
renderables = [
|
renderables: List[RenderableLine] = []
|
||||||
self.make_task_group(task) for task in self.tasks if task.visible
|
for task in self.tasks:
|
||||||
]
|
if task.visible:
|
||||||
renderable = Group(*renderables)
|
renderables.extend(self.make_task_group(task))
|
||||||
return renderable
|
return RenderableLines(renderables)
|
||||||
|
|
||||||
def make_task_group(self, task: Task) -> Group:
|
def make_task_group(self, task: Task) -> Iterable[RenderableLine]:
|
||||||
"""
|
"""
|
||||||
Create a representation for a task, including both the description line
|
Create a representation for a task, including both the description line
|
||||||
and the progress line.
|
and the progress line.
|
||||||
|
@ -133,9 +144,9 @@ class PipProgress(Progress):
|
||||||
description_row = self.make_task_row(self.get_description_columns(), task)
|
description_row = self.make_task_row(self.get_description_columns(), task)
|
||||||
# Only print description if download isn't large enough
|
# Only print description if download isn't large enough
|
||||||
if task.total is not None and not task.total > (40 * 1000):
|
if task.total is not None and not task.total > (40 * 1000):
|
||||||
return Group(description_row)
|
return (description_row,)
|
||||||
progress_row = self.make_task_row(columns, task)
|
progress_row = self.make_task_row(columns, task)
|
||||||
return Group(description_row, progress_row)
|
return (description_row, progress_row)
|
||||||
|
|
||||||
def make_task_row(
|
def make_task_row(
|
||||||
self, columns: Tuple[Union[str, ProgressColumn], ...], task: Task
|
self, columns: Tuple[Union[str, ProgressColumn], ...], task: Task
|
||||||
|
|
Loading…
Reference in New Issue