Skip to content

Commit

Permalink
fix: Restore printing archived during progress (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
janw authored Jan 1, 2025
1 parent 758e9c4 commit 5e5bd1d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Podcast-Archiver configuration
## Generated using podcast-archiver v2.0.0
## Generated using podcast-archiver v2.0.1

# Field 'feeds': Feed URLs to archive.
#
Expand Down
11 changes: 5 additions & 6 deletions podcast_archiver/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def successful(cls) -> set[QueueCompletionType]:
}

def __rich__(self) -> RenderableType:
return Text(str(self), style=self.style, end="")
return Text(self.value, style=self.style, end="")


class DownloadResult(StrEnum):
Expand All @@ -60,12 +60,11 @@ def successful(cls) -> set[DownloadResult]:
cls.COMPLETED_SUCCESSFULLY,
}

@classmethod
def max_length(cls) -> int:
return max(len(v) for v in cls)

def render_padded(self, padding: str = " ") -> RenderableType:
return Text(f"{self:{self.max_length()}s}{padding}", style=self.style, end="")
return Text(f"{self.value:{RESULT_MAX_LEN}s}{padding}", style=self.style, end="")

def __rich__(self) -> RenderableType:
return self.render_padded()


RESULT_MAX_LEN = max(len(result.value) for result in DownloadResult)
4 changes: 3 additions & 1 deletion podcast_archiver/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from threading import Event
from typing import TYPE_CHECKING

from rich.console import Group, NewLine

from podcast_archiver import constants
from podcast_archiver.config import Settings
from podcast_archiver.database import get_database
Expand Down Expand Up @@ -155,7 +157,7 @@ def _handle_results(self, episode_results: EpisodeResultsList) -> tuple[int, int
else:
failures += 1

rprint(episode_result, new_line_start=False)
rprint(Group(episode_result, NewLine()), new_line_start=False)
return success, failures

def shutdown(self) -> None:
Expand Down
7 changes: 3 additions & 4 deletions podcast_archiver/utils/pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rich.console import Group, NewLine, group
from rich.text import Text

from podcast_archiver.enums import DownloadResult
from podcast_archiver.enums import RESULT_MAX_LEN, DownloadResult
from podcast_archiver.logging import rprint

if TYPE_CHECKING:
Expand All @@ -16,7 +16,6 @@
from podcast_archiver.models.episode import BaseEpisode


_PREFIX_LEN = DownloadResult.max_length()
NEWLINE = NewLine()


Expand Down Expand Up @@ -49,12 +48,12 @@ def render(self) -> Iterator[RenderableType]:
yield NEWLINE

if self.length > 2:
yield text(" " * _PREFIX_LEN + " │ ")
yield text(" " * RESULT_MAX_LEN + " │ ")
yield text(" ︙", style="dim")
yield NEWLINE

if self.length > 1 and self.last:
yield text(" " * _PREFIX_LEN + " ╰╴")
yield text(" " * RESULT_MAX_LEN + " ╰╴")
yield self.last
yield NEWLINE
yield NEWLINE
Expand Down
9 changes: 4 additions & 5 deletions podcast_archiver/utils/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rich.table import Column

from podcast_archiver.console import console
from podcast_archiver.enums import DownloadResult
from podcast_archiver.enums import RESULT_MAX_LEN
from podcast_archiver.logging import REDIRECT_VIA_LOGGING

if TYPE_CHECKING:
Expand All @@ -24,7 +24,6 @@
highlight=False,
)

_TIME_REMAINING_WIDTH = DownloadResult.max_length()

PROGRESS_COLUMNS: list[rp.ProgressColumn] = [
rp.SpinnerColumn(
Expand All @@ -33,9 +32,9 @@
rp.TimeRemainingColumn(
compact=True,
table_column=_Column(
width=_TIME_REMAINING_WIDTH,
min_width=_TIME_REMAINING_WIDTH,
max_width=_TIME_REMAINING_WIDTH,
width=RESULT_MAX_LEN,
min_width=RESULT_MAX_LEN,
max_width=RESULT_MAX_LEN,
justify="center",
),
),
Expand Down

0 comments on commit 5e5bd1d

Please sign in to comment.