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($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($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($seconds);
where: $seconds is delay in seconds
animeTest() method is used to test the response of animations
yield from Cli::animeText(); //tries to run animation using a long (or heavy) loading strategy.
animate() method is used to view the different loading animations and their behaviour when used.
Cli::animate($yield, $delay);
where:
$yield : Number of times animation must run.
$delay : Delay in seconds to be added after animation is done.
endAnime() method is designed to print a text after animation is completed.
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::runAnime() method is called or at any point before a yield generator function is
declared.
Cli::loadTime($time);
where:
$time : Animation time in seconds
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.
function animate(){
yield from 100;
}
Cli::runAnime('animate'); //run animation 100 times.
function animate($text){
yield from 100;
print $text[0];
}
Cli::runAnime(['animate', ['completed']]); //run animation 100 times, then prints "completed".
class Anime($text){
public static function load() {
yield 100;
}
}
Cli::runAnime([Anime::class, 'load']); //run animation 100 times.
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".
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".
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();
yield false or yield true. In the example above, the
last message "something" will not execute because the stop keyword yield false was used.
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.
Cli::loadTime($type);
where: $type defines the loading type.