manrajgrover / halo

💫 Beautiful spinners for terminal, IPython and Jupyter
MIT License
2.86k stars 148 forks source link

Bug: Bounce animation is not displaying full characters #91

Closed Lilja closed 5 years ago

Lilja commented 5 years ago

Description

The last character of a bounce animation is never visible. Consider the case where the terminal width is 78 and the text width is 82. Animating with bounce will not show the last character.

System settings

Error

N/A

Expected behaviour

The last character should be shown.

Steps to recreate

I've written a test case that demonstrates the fault

    def test_bounce_animation(self):
        def filler_text(n_chars: int):
            return "_" * n_chars

        text = "{}abc".format(filler_text(80))

        expected_frames_without_appended_spinner = [
            "{}".format(filler_text(78)),
            "{}".format(filler_text(78)),
            "{}".format(filler_text(78)),
            "{}a".format(filler_text(77)),
            "{}ab".format(filler_text(76)),
            "{}abc".format(filler_text(75)),
            "{}abc".format(filler_text(75)),
            "{}ab".format(filler_text(76)),
            "{}a".format(filler_text(77)),
            "{}".format(filler_text(78)),
            "{}".format(filler_text(78)),
            "{}".format(filler_text(78)),
        ]
        # Prepend the actual spinner
        expected_frames = [
            "{0} {1}".format(frames[idx % frames.__len__()], frame)
            for idx, frame in enumerate(expected_frames_without_appended_spinner)
        ]
        spinner = Halo(text, animation="bounce", stream=self._stream)
        spinner.start()
        # Sleep a full bounce cycle
        time.sleep(1.2)
        spinner.stop()
        output = self._get_test_output()

        zippped_expected_and_actual_frame = zip(expected_frames, output)
        for multiple_frames in zippped_expected_and_actual_frame:
            expected_frame, actual_frame = multiple_frames
            self.assertEquals(expected_frame, actual_frame)

This will fail. However, changing https://github.com/manrajgrover/halo/blob/0767ac1d6e827cbe53347d9141eb3667b7b61019/halo/halo.py#L280

to

for x in range(0, text_length - terminal_width + 1):

resolves the test.

People to notify