still in progress...
The lib consists of one class \Kristuff\Mishell\Console
that contains mainly 3 types of methods:
Basic Example:
Use Kristuff\Mishell\Console;
Console::log(' I will ask you something', 'red');
$value = Console::askInt('Please enter a number > ');
if ($value !== false){
Console::log('=> The value you entered is [' . Console::text($value, 'yellow') . ']');
}
To be more flexible, most printing/text/layout builder methods take an indefinite number of arguments called [styles]
in this documentation.
The arguments are analyzed as follows:
So except for background that should be after foreground, style arguments order does not matter. Just note that the 'none'
argument will reset any previous style arguments.
Examples:
<?php
Use Kristuff\Mishell\Console;
Console::log('some text', 'blue'); // prints a blue text
Console::log('some text', 'bold'); // prints a text style bold
Console::log('some text', 'lightblue', 'underlined'); // prints a blue underlined text
Console::log('some text', 'blue', 'white'); // prints a blue text on white
Console::log('some text', 'blue', 'white', 'underlined'); // prints a blue text on white and style underline
Console::log('some text', 'blue', 'white', 'underlined', 'bold'); // prints a blue text on white and styles underline+bold
// prints a blue text on white and style reverse (so => white on blue...)
Console::log('some text', 'blue', 'white', 'reverse');
// prints a blue text on white and style underline
// (except background after foreground, args order does not matter)
Console::log('some text', 'blue', 'white', 'underlined');
Console::log('some text', 'underlined', 'blue', 'white');
Console::log('some text', 'lightblue', 'underlined', 'white');
// Prints a text with no style at all (note the 'none' argument at the end...)
Console::log('some text', 'lightblue', 'underlined', 'none');
[...]
//Got it?
Name | ANSI Code |
---|---|
black | \033[30m |
red | \033[31m |
green | \033[32m |
yellow | \033[33m |
blue | \033[34m |
magenta | \033[35m |
cyan | \033[36m |
lightgray | \033[37m |
default | \033[39m |
darkgray | \033[90m |
lightred | \033[91m |
lightgreen | \033[92m |
lightyellow | \033[93m |
lightblue | \033[94m |
lightmagenta | \033[95m |
lightcyan | \033[96m |
white | \033[97m |
Name | ANSI Code |
---|---|
black | \033[40m |
red | \033[41m |
green | \033[42m |
yellow | \033[43m |
blue | \033[44m |
magenta | \033[45m |
cyan | \033[46m |
lightgray | \033[47m |
default | \033[49m |
darkgray | \033[100m |
lightred | \033[101m |
lightgreen | \033[102m |
lightyellow | \033[103m |
lightblue | \033[104m |
lightmagenta | \033[105m |
lightcyan | \033[106m |
white | \033[107m |
Name | ANSI Code |
---|---|
none | \033[0m |
bold | \033[1m |
underlined | \033[4m |
blink | \033[5m |
reverse | \033[7m |
Method | Description | Return | Note |
---|---|---|---|
Console::print($str, [styles]) |
Prints a [formatted] string in the console. | void |
- |
Console::log($str, [styles]) |
Prints a [formatted] string in the console with new line. | void |
- |
Console::reLog($str, [styles]) |
Prints or overwites the current line with a [formatted] string. | void |
- |
Console::ask($str, [styles]) |
Prints a [formatted] string in the console and waits for an input. Returns that input. | string |
- |
Console::askInt($str, [styles]) |
Prints a [formatted] string in the console and waits for an int input. | int |bool |
- |
Console::askPassword($str, [styles]) |
Prints a [formatted] string in the console and waits for an input. Returns but does not print user input. | string |
Not supported on windows platform |
Method | Description | Return | Note |
---|---|---|---|
Console::pad(TODO) |
TODO | string |
|
Console::tableRow(TODO) |
TODO | string |
|
Console::tableRowStart(TODO) |
TODO | string |
|
Console::tableRowEmpty(TODO) |
TODO | string |
|
Console::tableRowSeparator(TODO) |
TODO | string |
|
Console::tableRowCell(TODO) |
TODO | string |
|
Console::tableResetDefaults(TODO) |
TODO | void |
Method | Description | Return | Note |
---|---|---|---|
Console::clear() |
Clear the console. | void |
|
Console::bell() |
Play the bell if available. | void |
|
Console::newWindow() |
Switch to a new window | void |
|
Console::restoreWindow() |
Restore the previous window | void |
|
Console::HideInput() |
Hide user input in window | void |
Not supported on windows platform |
Console::restoreInput() |
Restore user input window | void |
Not supported on windows platform |
Console::getLines() |
Get the number of lines in terminal | int |
Not supported on windows platform |
Console::getColumns() |
Get the number of colums in terminal | int |
Not supported on windows platform |
[...] TODO + tables methods + enum styles ...