Cli Texts Control

There are different cli methods for adding texts to the terminal in the manner which is desirable to console users. Hence, features like text margins and line breaks becomes easier to control. Most of these methods achieve their functions by shifting the console pointer to desired positions while other methods only makes it easier to print text to console in a specific desired format. These methods and their descriptions are listed below.

  • textIndent
  • textView
  • List
  • dots
  • backspace
  • cls
  • clearLine
  • clearUp
  • upLine
  • br
  • break
Cli::textIndent()

This method is used to only apply indents on supplied text value. Once the indent is applied, the resulting text will be returned as a string.

Syntax
    Cli::textIndent($text, $spaces);
    
      where: 
        
        $text   : text to be indented
        $spaces : number of indents to be applied
    
                                            


Cli::textView()

This method is used to display text contents on the command line. It is capable of applying features like spaces, indents, breaks and delays on text to be display.

Syntax
    Cli::textView($text, $spacing, $break, $pause);
    
      where: 
        
        $text    : text to be displayed
        $spacing : An optional string format that applies spaces before and after the supplied text using a pipe divider
        $break   : An optional string format that applies breaks before and after the supplied text using a pipe divider
        $pause   : An optional string format that applies delays before and after a string is displayed.
    
                                            

Example 1
    Cli::textView("Hello text", 2, 3, 1);
    
    In the code above, the text "Hello text" will be printed on the cli using specific features:

        1. The 2 defines that 2 spaces should be applied before the text is printed
        
        2. The 3 defines that 3 line breaks should be added before text is printed

        3. The 1 defines a 1 second delay before text is printed.
    
                                            

Example 2
    Cli::textView("Hello text", "2|2", "3|2", '2|1');
     
    The code above reveals that pipes are used to specify the position before and after when an event should be applied.

        1. The "2|2" defines that 2 spaces before and 2 spaces after should be applied on the text
        
        2. The "3|2" defines that 3 line breaks before and 2 breaks after should be applied on the text

        3. The "2|1" defines that 2 seconds delay before and 1 delay after should be applied on the text.
    
                                            



Cli::List()

The List method is used to display an array of strings with numbers. The numbering starts from zero upward. However, associative arrays will use ther specific array keys

Syntax
    Cli::list($array, $spacing, $break, $interval);
    
      where:

        $array      : array of strings to be displayed 
        $spacing    : An optional spacing format that applies spacing on each text to be displayed 
        $break      : An optional line breaking format that applies spacing on each text to be displayed 
        $interval   : An optional delay format that applies delay in seconds on each text to be displayed 
    
                                            

Example 1
    Cli::List(['Foo','Bar', 'Baz'], 0, "|1");
    
     The response will be as below: 

     1. Foo
     2. Bar
     3. Baz
    
                                            

Example 2
    Cli::List(['a'=>'Foo','b'=>'Bar', 'c' => 'Baz'], 0, "|1");
    
     The response will be as below: 

     a. Foo
     b. Bar
     c. Baz
    
                                            


Cli::dots()

This method is used to repeat a defined character in the number of required number of chracter to to generated. The number of character generated depends on the maximum number of character expected to be generated in a given text. This ensures that a defined character fills up the spaces left if the defined maximum length of characters for a given text is not reached.

Syntax
    Cli::dots($max, $text, $char); 
    
      where: 
    
        $max  : The expected length of text characters that must be generated. 
        $text : A given text whose length of characters is measured
        $char : A character that fills up left over space. Default is dots "."
    
                                    

Cli::backspace()

The backspace() method is used to delete the text characters starting from the right towards the left side.

Syntax
    Cli::backspace($times); 
    
      where: $times is the number of times a backspace must be applied. The default value is "1".
    
                                    

Cli::cls()
The cls() method is used to clear the terminal screen.

Cli::clearLine()
The clearLine() method is used to delete the entire character on a line. This method takes no arguments.

Syntax
    Cli::backspace($times); 
    
      where: $times is the number of times a backspace must be applied. The default value is "1".
    
                                    

Cli::clearUp()
The clearUp() method is used to delete a line before a text is printed. It shifts the positon of the cli pointer up by deleting all characters found along the way to its destination point.

Syntax
    Cli::clearUp($times); 
    
      where: $times is the number of times a the pointer must move up. The default value is "1".
    
                                    

Cli::upLine()
The upLine() method is used to shift the position of the command line pointer upwards without deleting any character.

Syntax
    Cli::upLine($times); 
    
      where: $times is the number of times a cursor must be shifted upwards.
    
                                    

Cli::br()
The br() method is used to apply text line breaks after a text has been printed.

Syntax
    Cli::br($times); 
    
      where: $times is the number of times a line break must be applied. Default value is "1".
    
                                    

Cli::break()
The break() method is also used to apply text line breaks after a text has been printed. The difference between Cli::br() and Cli::break() is that the latter prints directly by default while the former returns line breaks. However, the Cli::break() can also be modified to return line breaks rather than printing them. This can be done by setting the second argument to false.

Syntax
    Cli::break($times, $print); 
    
      where: 
        
        $times : The number of times a line break must be applied. Default value is "1".
        $print : When set as false, line breaks will only be returned as a string