Repository: Textualize/textual
File: src/textual/widgets/_progress_bar.py (Python)

Code before:
        &> .bar--indeterminate {
            color: $error;
            background: $surface;
        }
        &> .bar--complete {
            color: $success;
            background: $surface;
        }
    }
    """

    percentage: reactive[float | None] = reactive[Optional[float]](None)
    """The percentage of progress that has been completed."""

    gradient: reactive[Gradient | None] = reactive(None)
    """An optional gradient."""

    def __init__(
        self,
        name: str | None = None,
        id: str | None = None,
        classes: str | None = None,
        disabled: bool = False,
        clock: Clock | None = None,
        gradient: Gradient | None = None,
        bar_renderable: BarRenderable = BarRenderable,
    ):
        """Create a bar for a [`ProgressBar`][textual.widgets.ProgressBar]."""
        self._clock = (clock or Clock()).clone()
        super().__init__(name=name, id=id, classes=classes, disabled=disabled)
        self.set_reactive(Bar.gradient, gradient)
        self.bar_renderable = bar_renderable

    def _validate_percentage(self, percentage: float | None) -> float | None:
        """Avoid updating the bar, if the percentage increase is too small to render."""
        width = self.size.width * 2
        return (
            None
            if percentage is None
            else (int(percentage * width) / width if width else percentage)
        )

    def watch_percentage(self, percentage: float | None) -> None:
        """Manage the timer that enables the indeterminate bar animation."""
        if percentage is not None:
            self.auto_refresh = None
        else:
            self.auto_refresh = 1 / 15

    def render(self) -> RenderResult:
        """Render the bar with the correct portion filled."""

Review comment (suggestion):
Not convinced this is something that warrants being in the constructor. It feels more like an internal detail than configuration.

How about we expose the bar renderable as a classvar?

Something like this:

```python
class FancyProgress(ProgressBar):
    BAR_RENDERABLE_CLASS = FancyBar
```

Then you wouldn't have to specify it everywhere you use the progress bar.

Code after:
        &> .bar--indeterminate {
            color: $error;
            background: $surface;
        }
        &> .bar--complete {
            color: $success;
            background: $surface;
        }
    }
    """

    percentage: reactive[float | None] = reactive[Optional[float]](None)
    """The percentage of progress that has been completed."""

    gradient: reactive[Gradient | None] = reactive(None)
    """An optional gradient."""

    def __init__(
        self,
        name: str | None = None,
        id: str | None = None,
        classes: str | None = None,
        disabled: bool = False,
        clock: Clock | None = None,
        gradient: Gradient | None = None,
        bar_renderable: Type[BarRenderable] = BarRenderable,
    ):
        """Create a bar for a [`ProgressBar`][textual.widgets.ProgressBar]."""
        self._clock = (clock or Clock()).clone()
        super().__init__(name=name, id=id, classes=classes, disabled=disabled)
        self.set_reactive(Bar.gradient, gradient)
        self.bar_renderable = bar_renderable

    def _validate_percentage(self, percentage: float | None) -> float | None:
        """Avoid updating the bar, if the percentage increase is too small to render."""
        width = self.size.width * 2
        return (
            None
            if percentage is None
            else (int(percentage * width) / width if width else percentage)
        )

    def watch_percentage(self, percentage: float | None) -> None:
        """Manage the timer that enables the indeterminate bar animation."""
        if percentage is not None:
            self.auto_refresh = None
        else:
            self.auto_refresh = 1 / 15

    def render(self) -> RenderResult:
        """Render the bar with the correct portion filled."""