Cli Animations

Notifications are used to keep users aware of the current state of an executed command. They help users to have a clear understanding of what is going on. For example, there could be notifications for when a code successfully executes or when an error is encountered. The Cli class provides some useful methods for setting responses. These method have a predefined text prefixes assigned to messages. The text prefixes also use similarly related color codes to quickly call console users to awareness. The following are notification related methods.

Cli::textYield()
This method is used to yield a particular text. Yielding here means that text will first be printed while a loading animation will run after.

Syntax
    Cli::textYield($text, $yield, $pause);
    
      where:

        $text     : test to be displayed 
        $yield    : Integer number of times the animation must run
        $pause    : An optional delay that is added after the loading animation is completed.
    
                                            


Cli::play()
This method is used to run animations

Syntax
    Cli::play($yield, $indent, $message, $break, $pause); 
    
      where: 
    
        $yield   : Number of times animation must run
        $indent  : Number of left space indents to be added before text is printed
        $message : Animation text to be printed
        $break   : Number of line breaks to be added after animation is done.
        $pause   : Delay in seconds to be added after animation is done.
    
                                    

Cli::pause() or Cli::wait()
These method are used to set delay before an operation is executed.

Syntax
    Cli::pause($seconds); 
    
      where: $seconds is delay in seconds
    
                                    

Cli::animeTest()
The animeTest() method is used to test the response of animations

Example: animeTest
  yield from Cli::animeText(); //tries to run animation using a long (or heavy) loading strategy.
                                    

Cli::animate()
The animate() method is used to view the different loading animations and their behaviour when used.

Syntax
    Cli::animate($yield, $delay); 
    
      where: 
    
        $yield   : Number of times animation must run.
        $delay   : Delay in seconds to be added after animation is done.
    
                                    

Cli::endAnime()
The endAnime() method is designed to print a text after animation is completed.

Syntax
    Cli::endAnime($pause, $break1, string $message, $break2, $indent); 
    
      where: 
    
        $pause   : Delay in seconds to before text is printed.
        $break1  : Line breaks before text is printed. Default is zero (0).
        $message : Message to be printed
        $break2  : Line breaks after text is printed. Default is one (1).
        $indent  : Left margin on printed text. Default is two (2).
    
                                    

Cli::loadTime()
This method is designed to increase or decrease the amount of time needed for an animation to successfully complete. It can be declared before the Cli::runAnime() method is called or at any point before a yield generator function is declared.

Syntax
    Cli::loadTime($time); 
    
      where: 
    
        $time  : Animation time in seconds
    
                                    

Cli::runAnime()
This method is specially designed to run animations based on whether a function or public method is iterable. It uses special syntaxes to determine whether an iterable item is function related or object related, making it possible to run animations from functions or methods. An iterable item means a generator function or method.

Syntax
    Cli::runAnime($function, $callback); 
    
      where: 
    
        $function  : A function name or an array of function (or object) and its arguments.
        $callback  : An optional final callback to be executed when animation is complete.
    
                                    


Example: functions without arguments
    function animate(){

        yield from 100;

    }

    Cli::runAnime('animate');  //run animation 100 times.
                                    


Example: function with arguments
    function animate($text){

        yield from 100;

        print $text[0];

    }

    Cli::runAnime(['animate', ['completed']]);  //run animation 100 times, then prints "completed".
                                    


Example: Class without arguments
    class Anime($text){

        public static function load() {

            yield 100;

        }

    }

    Cli::runAnime([Anime::class, 'load']);  //run animation 100 times.
                                    


Example: Class with arguments
    class Anime($text){

        public static function load($args) {

            yield 100;

            print $args[0];

        }

    }

    Cli::runAnime([[Anime::class, 'load'], ['completed']]);  //run animation 100 times, then prints "completed".
                                    


Example: Running animation in classes
    class Anime($text){

        public function load() {

            Cli::runAnime([[$this, 'generator'], ['completed']]);

        }

        public function generator($args) {

            yield 100;

            print $args[0];

        }

    }

    $Anime = new Anime; 
    $Anime->load();  //run animation 100 times, then prints "completed".
                                    


Example: Stopping animations
    class Anime($text){

        public function load() {

            Cli::runAnime([[$this, 'generator'], ['completed']]);

        }

        public function generator($args) {

            yield 100; 
            
            print $args[0];

            yield false; //stop animation here.
            
            print "something"; //this will not run.

        }

    }

    $Anime = new Anime; 
    $Anime->load();
                                    

Animations can be stopped using the key words yield false or yield true. In the example above, the last message "something" will not execute because the stop keyword yield false was used.

Cli::loadType()
This method selects the type of animation to be used. In spoova Cli, there are currently 10 types of animations which includes normal, roller, dotted, arrows, forward, timer, circle, angles,steps and braill. Animation type can be declared or switched at any point before or during an animation runtime.

Syntax
    Cli::loadTime($type); 
    
      where: $type defines the loading type.