|
35 | 35 | from asyncio_for_ynab import TransactionDetail |
36 | 36 | from asyncio_for_ynab import TransactionsApi |
37 | 37 | from rich.progress import BarColumn |
38 | | -from rich.progress import MofNCompleteColumn |
39 | 38 | from rich.progress import Progress |
40 | 39 | from rich.progress import TaskID |
41 | 40 | from rich.progress import TextColumn |
|
50 | 49 | from collections.abc import Iterator |
51 | 50 | from collections.abc import Sequence |
52 | 51 |
|
| 52 | +try: |
| 53 | + from rich.progress import MofNCompleteColumn |
| 54 | +# https://github.com/benleb/surepy/issues/240 |
| 55 | +except ImportError: # pragma: no cover |
| 56 | + from rich.progress import ProgressColumn |
| 57 | + from rich.progress import Task |
| 58 | + from rich.text import Text |
| 59 | + |
| 60 | + if TYPE_CHECKING: |
| 61 | + from rich.table import Column |
| 62 | + |
| 63 | + class MofNCompleteColumn(ProgressColumn): # type:ignore[no-redef] |
| 64 | + def __init__(self, separator: str = "/", table_column: Column | None = None): |
| 65 | + self.separator = separator |
| 66 | + super().__init__(table_column=table_column) |
| 67 | + |
| 68 | + def render(self, task: Task) -> Text: |
| 69 | + """Show completed/total.""" |
| 70 | + completed = int(task.completed) |
| 71 | + total = int(task.total) if task.total is not None else "?" |
| 72 | + total_width = len(str(total)) |
| 73 | + return Text( |
| 74 | + f"{completed:{total_width}d}{self.separator}{total}", |
| 75 | + style="progress.download", |
| 76 | + ) |
| 77 | + |
53 | 78 |
|
54 | 79 | _EntryTable = ( |
55 | 80 | Literal["accounts"] |
|
0 commit comments