|
10 | 10 | import logging |
11 | 11 | from typing import Union |
12 | 12 |
|
13 | | -from rich.progress import Progress, TextColumn, BarColumn, TimeRemainingColumn, TimeElapsedColumn |
| 13 | +from rich.live import Live |
| 14 | +from rich.panel import Panel |
| 15 | +from rich.console import Group |
| 16 | +from rich.progress import Progress, TaskID, SpinnerColumn, TextColumn, BarColumn, TimeRemainingColumn, TimeElapsedColumn |
14 | 17 | from .utils import DebugOption, VerboseOption, QuietOption, verbose_args_processor, kwargs_processor |
15 | 18 |
|
16 | 19 | logger = logging.getLogger('base') |
@@ -148,22 +151,66 @@ def process( |
148 | 151 | logger.info('Started parallel processes') |
149 | 152 | typer.echo('Waiting for parallel processes to complete, this may take a while...') |
150 | 153 |
|
151 | | - with Progress( |
152 | | - TextColumn('[bold blue]{task.description}', justify = 'right'), |
153 | | - BarColumn(bar_width = None), |
154 | | - '[progress.percentage]{task.percentage:>3.1f}%', |
| 154 | + |
| 155 | + # Progress bar :D |
| 156 | + threadCount = len(newProcess._threads) |
| 157 | + |
| 158 | + thread_progress = Progress( |
| 159 | + SpinnerColumn(), |
| 160 | + TextColumn('{task.description}'), |
155 | 161 | '•', |
156 | 162 | TimeRemainingColumn(), |
157 | | - '•', |
158 | | - TimeElapsedColumn() |
159 | | - ) as progress: |
160 | | - percentage = 0 |
161 | | - job = progress.add_task('Working...', total = 100) |
162 | | - |
163 | | - while percentage < 100: |
164 | | - percentage = round(sum(i.progress for i in newProcess._threads) / (len(newProcess._threads) or 8), 2) * 100 |
165 | | - progress.update(job, completed = percentage) |
| 163 | + BarColumn(bar_width = 80), |
| 164 | + TextColumn('{task.percentage:>3.1f}%') |
| 165 | + ) |
| 166 | + overall_progress = Progress( |
| 167 | + TimeElapsedColumn(), |
| 168 | + BarColumn(bar_width = 110), |
| 169 | + TextColumn('{task.description}') |
| 170 | + ) |
| 171 | + |
| 172 | + workerjobs: list[TaskID] = [ |
| 173 | + thread_progress.add_task( |
| 174 | + f'[bold blue][T {threadNum}]', |
| 175 | + total = 100 |
| 176 | + ) |
| 177 | + for threadNum in range(threadCount) |
| 178 | + ] |
| 179 | + overalljob = overall_progress.add_task('(0 of ?)', total = 100) |
| 180 | + |
| 181 | + |
| 182 | + with Live( |
| 183 | + Group( |
| 184 | + Panel(thread_progress), |
| 185 | + overall_progress, |
| 186 | + ), |
| 187 | + refresh_per_second = 10 |
| 188 | + ): |
| 189 | + completed = 0 |
| 190 | + while completed != threadCount: |
| 191 | + i = 0 |
| 192 | + completed = 0 |
| 193 | + progressAvg = 0 |
| 194 | + |
| 195 | + for jobID in workerjobs: |
| 196 | + jobProgress = newProcess._threads[i].progress |
| 197 | + thread_progress.update(jobID, completed = round(jobProgress * 100, 2)) |
| 198 | + if jobProgress == 1: |
| 199 | + thread_progress.stop_task(jobID) |
| 200 | + thread_progress.update(jobID, description = '[bold green]Completed') |
| 201 | + completed += 1 |
| 202 | + |
| 203 | + progressAvg += jobProgress |
| 204 | + i += 1 |
| 205 | + |
| 206 | + # Update overall |
| 207 | + overall_progress.update( |
| 208 | + overalljob, |
| 209 | + description = f'[bold {"green" if completed == threadCount else "#AAAAAA"}]({completed} of {threadCount})', |
| 210 | + completed = round((progressAvg / threadCount) * 100, 2) |
| 211 | + ) |
166 | 212 | time.sleep(0.1) |
| 213 | + |
167 | 214 |
|
168 | 215 | result = newProcess.get_return_values() |
169 | 216 |
|
|
0 commit comments