Module reference for clanimtk

clanimtk.decorator.animate(func=None, *, animation=<clanimtk.core.Animation object>, step=0.1)[source]

Wrapper function for the _Animate wrapper class.

Parameters:
  • func (Optional[Callable[…, Any]]) – A function to run while animation is showing.
  • animation (Generator[str, None, None]) – An AnimationGenerator that yields animation frames.
  • step (float) – Approximate timestep (in seconds) between frames.
Return type:

Callable[…, Any]

Returns:

An animated version of func if func is not None. Otherwise, a function that takes a function and returns an animated version of that.

clanimtk.decorator.animation(frame_function)[source]

Turn a FrameFunction into an Animation.

Parameters:frame_function (Callable[…, Generator[str, None, None]]) – A function that returns a FrameGenerator.
Return type:Callable[…, Generator[str, None, None]]
Returns:an Animation decorator function.
clanimtk.decorator.annotate(*, start_msg=None, end_msg=None, start_no_nl=False)[source]

A decorator meant for decorating functions that are decorated with the animate decorator. It prints a message to stdout before and/or after the function has finished.

Danger

This decorator can also be used standalone, but you should NOT decorate a function that is decorated with annotate with animate. That is to say, the decorator order must be like this:

@annotate
@animate
def some_function()
    pass
Return type:Callable[…, Any]
clanimtk.decorator.multiline_frame_function(frame_function, height, offset=0, *args, **kwargs)[source]

Multiline a singlelined frame function. Simply chains several frame generators together, and applies the specified offset to each one.

Parameters:
  • frame_function (Callable[…, Generator[str, None, None]]) – A function that returns a singleline FrameGenerator.
  • height (int) – The amount of frame generators to stack vertically (determines
  • height in characters) (the) –
  • offset (int) – An offset to apply to each successive generator. If the offset
  • 2, then the first generator starts at frame 0, the second at frame (is) –
  • the third at frame 4, and so on. (2,) –
Return type:

Generator[str, None, None]

Returns:

a multiline version fo the generator returned by frame_function

clanimtk.util.concatechain(*generators, separator='')[source]

Return a generator that in each iteration takes one value from each of the supplied generators, joins them together with the specified separator and yields the result. Stops as soon as any iterator raises StopIteration and returns the value contained in it.

Primarily created for chaining string generators, hence the name.

Parameters:
  • generators (Generator[str, None, None]) – Any number of generators that yield types that can be
  • together with the separator string. (joined) –
  • separator (str) – A separator to insert between each value yielded by
  • different generators. (the) –
Returns:

A generator that yields strings that are the concatenation of one value from each of the generators, joined together with the separator string.

clanimtk.util.get_supervisor(func)[source]

Get the appropriate supervisor to use and pre-apply the function.

Parameters:func (Callable[…, Any]) – A function.
Return type:Callable[[Generator[str, None, None], float, Any, Any], Any]
clanimtk.cli.animate_cli(animation_, step, event)[source]

Print out the animation cycle to stdout. This function is for use with synchronous functions and must be run in a thread.

Parameters:
  • animation (generator) – A generator that produces strings for the
  • Should be endless. (animation.) –
  • step (float) – Seconds between each animation frame.
clanimtk.cli.erase(status)[source]

Erases the given status message from stdout by backspacing as many times as the status is long.

Parameters:status (str) – A status message that is already printed to stdout.

Core functionality for clanimtk. This module is only intended to be used as an internal part of clanimtk. The relevant, public functionality in this module is exposed in the :py:module:: clanimtk.decorator module.

class clanimtk.core.Animate(func=None, *, animation_gen, step=0.1)[source]

A wrapper class for adding a CLI animation to a slow-running function. Animate uses introspection to figure out if the function it decorates is synchronous (defined with ‘def’) or asynchronous (defined with ‘async def’), and works with both.

Danger

This class is not intended to be used directly, but rather through the animate function.

class clanimtk.core.Animation(frame_function, current_generator=None, back_up_generator=None, animation_args=None, animation_kwargs=None)[source]

A wrapper class for FrameFunctions. It automatically backs up the cursor after each frame, and provides reset and erase functionality.

Danger

Do not use directly, use the animation function instead.

get_erase_frame()[source]

Return a frame that completely erases the current frame, and then backs up.

Assumes that the current frame is of constant width.

reset()[source]

Reset the current animation generator.

class clanimtk.core.Annotate(*, start_msg=None, end_msg=None, start_no_nl=False)[source]

A decorator meant for decorating functions that are decorated with the animation decorator. It prints a message to stdout before and/or after the function has finished.

Danger

This decorator can also be used standalone, but you should NOT decorate a function that is decorated with Annotate with Animate. That is to say, the decorator order must be like this:

@Annotate
@Animate
def some_function()
    pass