Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kristuff committed May 21, 2020
2 parents 907ff6d + e84e268 commit ee34bdb
Show file tree
Hide file tree
Showing 24 changed files with 472 additions and 423 deletions.
112 changes: 63 additions & 49 deletions README.md
Expand Up @@ -10,7 +10,7 @@
[![Latest Stable Version](https://poser.pugx.org/kristuff/mishell/v/stable)](https://packagist.org/packages/kristuff/mishell)
[![License](https://poser.pugx.org/kristuff/mishell/license)](https://packagist.org/packages/kristuff/mishell)

![sample](doc/screenshots/sample-colors.png)
![sample](doc/screenshots/loading.png)

- [Features](#features)
- [Requirements](#requirements)
Expand Down Expand Up @@ -43,14 +43,14 @@ Deploy with your project (in `composer.json`):
{
...
"require": {
"kristuff/mishell": ">=1.1-stable"
"kristuff/mishell": ">=1.2-stable"
}
}
```

Run the sample
--------
![demo](doc/screenshots/index.png)
![demo](doc/screenshots/demo.gif)

- clone this repo on github (*demo* and *doc* folders are excluded from dist)
```bash
Expand All @@ -72,13 +72,13 @@ Run the sample
Documentation
--------

*in progress...*
*still in progress...*

1. [Overview](#1-overview)
1.1 [Working with styles](#11-working-with-styles)
1.2 [Known foreground colors](#12-known-foreground-colors)
1.3 [Known background colors](#13-known-background-colors)
1.4 [Known options](#14-known-options)
1.4 [Known formats](#14-known-formats)
2. [Api methods](#2-api-methods)
2.1 [Writing methods](#21-writing-methods)
2.2 [Text/layout builder methods](#22-text-layout-builder-methods)
Expand All @@ -96,7 +96,11 @@ The lib consists of one class `\Kristuff\Mishell\Console` that contains mainly 3
Basic Example:
```php
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') . ']');
}
Expand All @@ -108,78 +112,88 @@ The arguments are analyzed as follows:

- First argument that matchs to a known foreground color is taken as foreground color.
- First argument that matchs to a known background color (when a foreground color is already defined) is taken as background color (you cannot use a background color without set explicitly foreground color before).
- Other arguments that match to a known option are taken as options.
- Other arguments that match to a known format are taken as formats.

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
<?php
Use Kristuff\Mishell\Console;

Console::print('some text', 'blue'); // prints a blue text
Console::print('some text', 'bold'); // prints a text style bold
Console::print('some text', 'blue', 'underline'); // prints a blue underlined text
Console::print('some text', 'blue', 'white'); // prints a blue text on white
Console::print('some text', 'blue', 'white', 'underline'); // prints a blue text on white and style underline
Console::print('some text', 'blue', 'white', 'underline', 'bold'); // prints a blue text on white and styles underline+bold
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::print('some text', 'blue', 'white', 'reverse');
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::print('some text', 'blue', 'white', 'underline');
Console::print('some text', 'underline', 'blue', 'white');
Console::print('some text', 'blue', 'underline', 'white');
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::print('some text', 'blue', 'underline', 'none');
Console::log('some text', 'lightblue', 'underlined', 'none');
[...]
//Got it?
```

### 1.2 Known foreground colors

Name | ANSI Code
--------------- | --------
normal | \033[39m
black | \033[30m
grey | \033[1;30m
lightgrey | \033[37m
white | \033[1;37m
blue | \033[34m
lightblue | \033[1;34m
green | \033[32m
lightgreen | \033[1;32m
cyan | \033[36m
lightcyan | \033[1;36m
red | \033[31m
lightred | \033[1;31m
magenta | \033[35m
lightmagenta | \033[1;35m
brown | \033[33m
yellow | \033[1;33m
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

### 1.3 Known background colors

Name | ANSI Code
--------------- | --------
black | \033[40m
red | \033[41m
green | \033[42m
yellow | \033[43m
blue | \033[44m
magenta | \033[45m
cyan | \033[46m
white | \033[47m

### 1.4 Known options
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

### 1.4 Known formats

Name | ANSI Code
--------------- | --------
none | \033[0m
bold | \033[1m
underline | \033[4m
underlined | \033[4m
blink | \033[5m
reverse | \033[7m

Expand Down
49 changes: 0 additions & 49 deletions demo/demo.allstyles.php

This file was deleted.

36 changes: 21 additions & 15 deletions demo/demo.ask.php
Expand Up @@ -3,21 +3,27 @@
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;

Console::log('Overview:', 'underline', 'bold');
Console::log(" - Use " . Console::text("string Console::ask ( string \$str [, \$styles] )", 'blue', 'white') . "to ask something to user in the console.");
Console::log('');
Console::log('Tips:', 'underline', 'bold');
Console::log(" - you can customize colors (foreground and background) and some styles in same way than with Console::text()", 'lightmagenta');
Console::log(" and Console::log() methods.", 'lightmagenta');
Console::log('');
Console::log('Usage:', 'underline', 'bold');
Console::log(' '. Console::text(Console::pad("\$value1 = Console::ask('Please enter something > ');", 90), 'blue', 'white'));
Console::log(' '. Console::text(Console::pad("// or);", 90), 'green', 'white'));
Console::log(' '. Console::text(Console::pad("\$value2 = Console::ask('Please enter something > ', 'red', 'white', 'underline');", 90), 'blue', 'white'));
Console::log('');
Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(' '. Console::text(" - Use ") . Console::text("string ", 'blue'). Console::text("Console::ask()", 'lightblue', 'underlined') . " to ask something to user in the console.");
Console::log();
Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
Console::log(" - You can customize colors (foreground and background) and some styles in same way than ");
Console::log(' with ' . Console::text("Console::text()", 'lightblue', 'underlined') .
' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.');
Console::log();
Console::log(' '. Console::text('Usage:', 'underlined', 'bold'));
Console::log(' '. Console::text("\$value = Console::ask('Please enter something > ');", 'lightmagenta'));
Console::log(' '. Console::text("// or", 'green'));
Console::log(' '. Console::text("\$value = Console::ask('Please enter something > ', 'white', 'blue);", 'lightmagenta'));
Console::log();

// -----------------
// sample start here
// -----------------
$value = Console::ask('Please enter something > ');
Console::log('=> the value you entered is [' . Console::text($value, 'yellow') . ']');
Console::log('=> the value you entered is [' . Console::text($value, 'lightyellow') . ']');

$value2 = Console::ask('Please enter something > ', 'red', 'white', 'underline');
Console::log('=> the value you entered is [' . Console::text($value2, 'yellow') . ']');
$value2 = Console::ask('Please enter something > ', 'magenta', 'underlined');
Console::log('=> the value you entered is [' . Console::text($value2, 'lightyellow') . ']');

?>
56 changes: 25 additions & 31 deletions demo/demo.askint.php
@@ -1,38 +1,32 @@
<?php

require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;

Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(" - Use " . Console::text("int|bool ", 'blue') . Console::text("Console::askInt()", 'lightblue', 'underlined') . " to ask user to enter a number in the console.");
Console::log();
Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
Console::log(" - The method returns " . Console::text("int", 'blue') . " value or " . Console::text("false", 'blue'). " if the entered value is not a valid int number.");
Console::log(" - You can customize colors (foreground and background) and some styles in same way than ");
Console::log(' with ' . Console::text("Console::text()", 'lightblue', 'underlined') .
' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.');
Console::log();
Console::log(' '. Console::text('Usage:', 'underlined', 'bold'));
Console::log(' ' . Console::text("\$value = Console::askInt('Please enter a number > ');", 'lightmagenta'));
Console::log(' ' . Console::text("if (\$value !== false) {", 'lightmagenta'));
Console::log(' ' . Console::text("// Do something with \$value", 'green'));
Console::log();
Console::log(' '. Console::text('Sample:', 'underlined', 'bold'));

Console::log('Overview:', 'underline', 'bold');
Console::log(" - Use " . Console::text("Console::askInt(\$str [\$styles])", 'blue', 'white') . " to ask user to enter a number in the console.");
Console::log('');
Console::log('Tips:', 'underline', 'bold');
Console::log(" - The method returns Int value or False if the entered value is not a valid int number.", 'lightmagenta');
Console::log(" - You can customize colors (foreground and background) and some styles in same way than with Console::text()", 'lightmagenta');
Console::log(" and Console::log() methods..", 'lightmagenta');
Console::log('');
Console::log('Usage:', 'underline', 'bold');
Console::log(' ' . Console::text(Console::pad("\$value = Console::askInt('Please enter a number > ');", 80), 'blue', 'white'));
Console::log(' ' . Console::text(Console::pad("if (\$value !== false) {", 80), 'blue', 'white'));
Console::log(' ' . Console::text(Console::pad(" [...]", 80), 'blue', 'white'));
Console::log('');
Console::log('Sample:', 'underline', 'bold');

function askNumber()
{
$value = Console::askInt('Please enter a number > ');

if ($value !== false){
Console::log('=> The value you entered is [' . Console::text($value, 'yellow') . ']');

} else {
Console::log(Console::text('Error:', 'red'));
Console::log(Console::text('=> the value you entered is not a valid number.', 'red'));
// retry...
askNumber();
}
// -----------------
// sample start here
// -----------------
$value = Console::askInt(' Please enter a number > ');
if ($value !== false){
Console::log(' => The value you entered is [' . Console::text($value, 'yellow') . ']');
} else {
Console::log(Console::text(' Error:', 'red'));
Console::log(Console::text(' => the value you entered is not a valid number.', 'red'));
}

// ask
askNumber();
?>
44 changes: 25 additions & 19 deletions demo/demo.askpassword.php
@@ -1,24 +1,30 @@
<?php

require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;

Console::log('Overview:', 'underline', 'bold');
Console::log(" Use " . Console::text("Console::askPassword(\$str [\$styles])", 'blue', 'white') . " to ask user to enter a value and return this value.", 'white');
Console::log('');
Console::log('Tips:', 'underline', 'bold');
Console::log(" - you can customize colors (foreground and background) and some styles in same way than with Console::text()", 'green');
Console::log(" and Console::log() methods.", 'green');
Console::log('');
Console::log('Warning:', 'underline', 'bold');
Console::log(" - User input are not hidden on windows platform (not supported)", 'red', 'yellow');
Console::log('');
Console::log('Usage:', 'underline', 'bold');
Console::log(' ' . Console::text(Console::pad("\$value = Console::askPassword('Please Enter something (We wont display it, for now...) > ');", 80), 'blue', 'white'));
Console::log(' ' . Console::text(Console::pad("Console::log();", 80), 'blue', 'white'));
Console::log(' ' . Console::text(Console::pad("Console::log('=> the value you entered is [' . Console::text(\$value, 'red') . ']');", 80), 'blue', 'white'));
Console::log('');
Console::log('Sample:', 'underline', 'bold');
$value = Console::askPassword('Please Enter something (We wont display it, for now...) > ');
Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(' Use ' . Console::text("string ", 'blue'). Console::text("Console::askPassword()", 'lightblue', 'underlined') . " to ask user to enter a value and return this value.", 'white');
Console::log();
Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
Console::log(" - You can customize colors (foreground and background) and some styles in same way than ");
Console::log(' with ' . Console::text("Console::text()", 'lightblue', 'underlined') .
' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.');
Console::log();
Console::log(' '. Console::text('Warning:', 'underlined', 'bold'));
Console::log(' '. Console::text("User input are not hidden on windows platform (not supported)", 'red', 'yellow'));
Console::log();
Console::log(' '. Console::text('Usage:', 'underlined', 'bold'));
Console::log(' ' . Console::text("\$value = Console::askPassword('Please Enter something (We wont display it, for now...) > ');", 'lightmagenta'));
Console::log(' ' . Console::text("Console::log();", 'lightmagenta'));
Console::log(' ' . Console::text("Console::log('=> the value you entered is [' . Console::text(\$value, 'red') . ']');", 'lightmagenta'));
Console::log();
Console::log('=> the value you entered is [' . Console::text($value, 'red') . ']');
Console::log(' '. Console::text('Sample:', 'underlined', 'bold'));

// -----------------
// sample start here
// -----------------
$value = Console::askPassword(' Please Enter something (We wont display it, for now... (except on windows) > ');
Console::log();
Console::log(' => the value you entered is [' . Console::text($value, 'red') . ']');

?>

0 comments on commit ee34bdb

Please sign in to comment.