from __future__ import annotations

import math


class Spinner:
    """A simple spinner."""

    def __init__(
        self,
        chars: str = "/-\\|",
        width: int = 4,
        index: int = 0,
    ) -> None:
        """Initailizes the spinner."""
        self.chars = chars
        self.width = width
        self.index = index % len(chars)

    def __iter__(self) -> Spinner:
        """Returns the iterator (self)."""
        return self

    def __next__(self) -> str:
        """Returns the next iteration of the spinner."""
        index, width = self.index, self.width
        chars = self.chars * (math.ceil((2 * width) / len(self.chars)))
        result = chars[index : index + width]
        self.index = (index + 1) % len(self.chars)
        return result
