Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Disable animation looping #75

Closed
masaeedu opened this issue Nov 1, 2018 · 6 comments
Closed

Disable animation looping #75

masaeedu opened this issue Nov 1, 2018 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@masaeedu
Copy link

masaeedu commented Nov 1, 2018

Hi there. Thanks for a very useful utility. I'm trying to add some recordings to a presentation, but can't figure out how to get the animation to simply stop once it reaches the end of the recording (instead of immediately looping back around). I tried poking around in the generated SVG but couldn't figure out how to get this to work (not very skilled at SMIL or SVG).

Deleting the anim_last.end+... hooks from all the begin attributes seemed to be what I'd need, but this simply makes everything disappear at the end of the animation rather than stopping at the final state of the screen.

@nbedos
Copy link
Owner

nbedos commented Nov 3, 2018

Unfortunately I don't think it can easily be done by tweaking the SVG file.

termtosvg uses animate elements to show lines of the terminal by changing display="none" to display="inline" at a specific time (animate.begin) and for a specific duration (animate.dur). Once the duration set for an animate element has elapsed, the corresponding lines are hidden.

So in order to keep the last frame of the animation on the screen we would need to identify which lines are displayed last and then add a fill="freeze" attribute to the corresponding animate tag. Unless you've got a very simple animation it's probably a pain to do by hand.

@masaeedu
Copy link
Author

masaeedu commented Nov 3, 2018

@nbedos Do you think there's a way to change the SVG output that's getting interpolated into the templates in such a way that it's possible to recognize which elements are part of a single "frame"?

@nbedos
Copy link
Owner

nbedos commented Nov 4, 2018

@masaeedu No, sorry, I'd rather not add more information in the SVG output. As of today the ouput of termtosvg is kind of messy and it needs to be reworked. I'll keep in mind that you're interested in getting an animation that does not loop.

@nbedos nbedos changed the title Stop at end of recording Disable animation looping Dec 2, 2018
@rob-smallshire
Copy link

I needed this non-looping behaviour for similar reasons, namely incorporating SVG animations in presentation.

It turns out that this is possible with an SVG template, by including Javascript which pauses (i.e. stops forever) the animation at the "end". This solution is definitely hacky, but it works without needing to modify termtosvg.

The script to include in the template is as follows:

    <script type="text/javascript">
        <![CDATA[
            var terminal = document.getElementById('terminal');
            var screen = terminal.getElementById('screen');
            var style = getComputedStyle(terminal);
            var animationDuration = parseInt(style.getPropertyValue('--animation-duration')) / 1000;

            function stop() {
                terminal.pauseAnimations();
                screen.pauseAnimations();
            }

            let now = screen.getCurrentTime();
            let remainingTime = animationDuration - now;

            setTimeout(stop, remainingTime * 1000);
        ]]>
    </script>

nbedos added a commit that referenced this issue Jun 30, 2019
Switch from SMIL animations to CSS or WAAPI animations
This should address #75, #86, #94 and #95
@nbedos
Copy link
Owner

nbedos commented Jun 30, 2019

With c9a3ecb I've changed the way animations are created by termtosvg. This makes it possible to disable looping without using javascript.

See https://github.com/nbedos/termtosvg/blob/develop/man/termtosvg-templates.md#restricting-the-animation-to-a-single-loop

@nbedos nbedos added this to the 0.9.0 milestone Jun 30, 2019
@nbedos nbedos added the enhancement New feature or request label Jun 30, 2019
@nbedos
Copy link
Owner

nbedos commented Jul 6, 2019

Feature included in version 0.9.0

@nbedos nbedos closed this as completed Jul 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants