Skip to content

Commit

Permalink
Merge pull request #18 from kristuff/develop
Browse files Browse the repository at this point in the history
1.6
  • Loading branch information
kristuff authored Jan 19, 2024
2 parents 7c23c17 + 6a44e7b commit b88c584
Show file tree
Hide file tree
Showing 53 changed files with 2,532 additions and 273 deletions.
15 changes: 8 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
doc/ export-ignore
demo/ export-ignore
tests/ export-ignore
vendor/ export-ignore
demo/ export-ignore
doc/ export-ignore
.gitattributes export-ignore
README.* export-ignore
composer.* export-ignore
.gitignore export-ignore
.codeclimate.yml export-ignore
.travis.yml export-ignore
composer.* export-ignore
phpunit.xml export-ignore
README.* export-ignore
CHANGELOG.* export-ignore
CHANGELOG.* export-ignore
.gitattributes export-ignore
.codeclimate.yml export-ignore

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2021 kristuff
Copyright (c) 2017-2024 Kr157uff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
[![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/loading.png)
![sample](doc/screenshots/mishell1.6.png)
*See also mp4 in doc/screenshots directory*



- [Features](#features)
- [Requirements](#requirements)
Expand All @@ -33,21 +36,26 @@ Features
Requirements
------------
- PHP >= 5.6
- PHP mbstring module


Install
--------

Deploy with your project (in `composer.json`):


```
{
...
"require": {
"kristuff/mishell": ">=1.5-stable"
"kristuff/mishell": ">=1.6-stable"
}
}
```

> Composer is (technically) required to build autoloader files. You should be able to run the demo "as is" (with the `vendor` directory included) when you clone the project. There is no other dependencies.

Documentation
--------
Expand Down Expand Up @@ -80,15 +88,19 @@ Run the sample
Bonus
-----
You can also do unuseful things like the blue screen of the death^^ Check the demo
![blue-screen](doc/screenshots/blue-screen.png)

![blue-screen](doc/screenshots/blue-screen.png)

Update ::1.6

![blue-screen-1.6](doc/screenshots/blue-screen-1.5.9.png)

License
-------

The MIT License (MIT)

Copyright (c) 2017-2021 Kristuff
Copyright (c) 2017-2024 Kristuff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kristuff/mishell",
"description": "A mini PHP library to build beautiful CLI apps and reports",
"homepage": "https://kristuff.fr/projects/mishell",
"homepage": "https://github.com/kristuff/mishell",
"keywords": ["cli", "table", "color"],
"type": "library",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.ask.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

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

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.");
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.askint.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
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.");
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.askpassword.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

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');
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.bell.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(' - Use ' . Console::text("Console::bell()", 'lightblue', 'underlined') . ' to play a bell sound in console (if available).', 'white');
Expand Down
4 changes: 2 additions & 2 deletions demo/demo.bgcolors.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

$rowHeaders = ['Color name' => 15, ' ANSI Code' => 15, ' Sample ouput' => 51];
$rowHeaders = ['Color name' => 15, ' ANSI Code' => 15, ' Sample output' => 51];
Console::log(' '.Console::tableRowSeparator($rowHeaders));
Console::log(' '.Console::tableRow($rowHeaders));
Console::log(' '.Console::tableRowSeparator($rowHeaders));
Expand Down
31 changes: 16 additions & 15 deletions demo/demo.bluescreen.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

// *open* new window
Console::newWindow();
Expand All @@ -10,26 +10,27 @@
$cols = Console::getColumns();
$middle = round($lines/2);

for ($i= 0; $i <= $lines ; $i++){
for ($i= 1; $i <= $lines ; $i++){

switch($i){
case $middle -1:
Console::log(Console::pad(":( Houston, we've had a problem...", $cols, ' ', STR_PAD_BOTH), 'white', 'blue');
break;
case $middle :
Console::log(Console::pad('an error occurred in my head,', $cols, ' ', STR_PAD_BOTH), 'white', 'blue');
break;
case $middle +1:
Console::log(Console::pad('I really want you to see the blue screen of the death', $cols, ' ', STR_PAD_BOTH), 'white', 'blue');
break;
default:
Console::log(Console::pad(' ', $cols), 'white', 'blue');
case $middle -10: Console::log(Console::pad(" /", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -9: Console::log(Console::pad(" /", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -8: Console::log(Console::pad(" /", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -7: Console::log(Console::pad(" | o", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -6: Console::log(Console::pad(" |", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -5: Console::log(Console::pad(" | o", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -4: Console::log(Console::pad(" \\", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -3: Console::log(Console::pad(" \\", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle -2: Console::log(Console::pad(" \\", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle +1: Console::log(Console::pad(" Houston, we've had a problem...", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle +2: Console::log(Console::pad(" The screen is blue. The screen is blue. The screen is blue. The screen is blue. The screen is blue. ", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $middle +3: Console::log(Console::pad(" The screen is blue. The screen is blue. The screen is blue. The screen is blue. The screen is blue. ", $cols, ' ', STR_PAD_RIGHT), 'white', 'blue'); break;
case $lines: Console::askInt(Console::pad('Press something to stop damage your eyes > ', $cols, ' ', STR_PAD_LEFT), 'white', 'blue'); break;
default: Console::log(Console::pad(' ', $cols), 'white', 'blue');
}
}
Console::askInt(Console::pad('Press something to stop damage your eyes > ', $cols, ' ', STR_PAD_LEFT), 'white', 'blue');

// restore window
Console::restoreWindow();
Console::log('Any resemblance to a lived situation is a pure coincidence.');

?>
4 changes: 2 additions & 2 deletions demo/demo.colors.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

// headers
$rowHeaders = ['#Num' => 7, 'Color name' => 15, ' ANSI Code' => 15, ' Sample ouput' => 50];
$rowHeaders = ['#Num' => 7, 'Color name' => 15, ' ANSI Code' => 15, ' Sample output' => 50];
Console::log(' '.Console::tableRowSeparator($rowHeaders));
Console::log(' '.Console::tableRow($rowHeaders));
Console::log(' '.Console::tableRowSeparator($rowHeaders));
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.pad.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(" - Use " . Console::text("string ", 'blue'). Console::text("Console::pad()", 'lightblue', 'underlined') . "to get a text with given padding.");
Expand Down
9 changes: 5 additions & 4 deletions demo/demo.progress.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;
use Kristuff\Mishell\Console;

Console::log();
Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(" - Use " . Console::text("Console::relog()", 'lightblue', 'underlined') . " to overwrite the current line.", 'white');
Console::log(" - Use " . Console::text("Console::relog()", 'lightblue', 'underlined') . " to write temporary output to be overwritten later.", 'white');
Console::log();

Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
Console::log(" - you may need to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method to be sure all previous text is overwitted.");
Console::log(" - you may need to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method to be sure all previous text is overwritten.");
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.');
Expand Down Expand Up @@ -52,7 +53,7 @@
// Overwrite progress message.
// note: we can customize colors and some styles like with Console::text() and
// Console::log() methods.
Console::relog(' -- wOopssssssss!! something was wrong?!%?!!? Wait a momemt.... --', 'red', 'yellow');
Console::relog(' -- wOopssssssss!! something was wrong?!%?!!? Wait a moment.... --', 'red', 'yellow');

// wait for a while, so we see the animation
usleep(2000000);
Expand Down
24 changes: 24 additions & 0 deletions demo/demo.progress2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;

Console::log();
Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(" - Use " . Console::text("Console::overwrite()", 'lightblue', 'underlined') . " to overwrite the last printed line.", 'white');
Console::log();

Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
Console::log(" - " . Console::text('No need', 'underlined', 'bold') ." to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method like with " .Console::text("Console::relog()", 'lightblue', 'underlined') );
Console::log(" - You can customize colors (foreground and background) and some styles in same way than ");
Console::log(' ' .Console::text("Console::text()", 'lightblue', 'underlined') .
' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.');
Console::log();
Console::log(' '. Console::text('Basic usage:', 'underlined', 'bold'));
Console::log();
Console::log(" Console::log('I am a real log line, with \\n, but I will be erased');");
Console::log(" Console::overwrite('I am new real line.');");
Console::log();
Console::log(' ' .Console::text('Sample code:', 'underlined', 'bold'));
Console::log();

?>
44 changes: 44 additions & 0 deletions demo/demo.progress2.sample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;

// temporary message
Console::log(' I am a temporary message... I will be erased :(', 'red');

// wait for a while, so we see the animation
sleep(3);

for ($i=1 ; $i<=100 ; $i++) {

// progress message
Console::overwrite(' I am a progress text... ('.Console::text($i.'%', 'green') .' completed)');

// wait for a while, so we see the animation
usleep(100000);
}

// Overwrite message again
Console::overwrite(' '.Console::text('Process complete.', 'white', 'green', 'underlined'));

// wait for a while, so we see the animation
usleep(2000000);

// Overwrite message again
Console::overwrite(' Oh wait, I forgot something...', 'red');

// wait for a while, so we see the animation
usleep(2000000);

// Overwrite message again
Console::overwrite(' '.Console::text('StandWith', 'yellow', 'blue').Console::text('Ukraine', 'blue', 'yellow'));

// wait for a while, so we see the animation
usleep(2000000);

// Overwrite message again (last time).
Console::overwrite(' Process complete', 'green', 'bold');

// new blank line
Console::log();

?>
81 changes: 81 additions & 0 deletions demo/demo.progress3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
require_once __DIR__ .'/../vendor/autoload.php';
use Kristuff\Mishell\Console;


Console::log(' '. Console::text('Overview:', 'underlined', 'bold'));
Console::log(' '. Console::text('- Using ','white').Console::text("Console::overwrite()", 'lightblue', 'underlined').Console::text('you can overwrite more than one row.', 'white'));
Console::log(' '. Console::text('To overwrite the 2 last printed rows, you need to pass an array of 2 ','white').Console::text("string", 'lightblue', '').' '. Console::text('.', 'white'));
Console::log();

Console::log(' '. Console::text('Tips:', 'underlined', 'bold'));
Console::log(" - " . Console::text('No need', 'underlined', 'bold') ." to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method like with " .Console::text("Console::relog()", 'lightblue', 'underlined') );
Console::log(" - You can customize colors (foreground and background) and some styles in same way than ");
Console::log(' ' .Console::text("Console::text()", 'lightblue', 'underlined') .
' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.');
Console::log();
Console::log(' '. Console::text('Basic usage:', 'underlined', 'bold'));
Console::log();
Console::log(" Console::log('I am a real log line, with \\n, but I will be erased');");
Console::log(" Console::log('I am another real log line, with \\n, but I will be erased');");
Console::log(" Console::overwrite('I am new real line.');");
Console::log();
Console::log(' ' .Console::text('Sample code:', 'underlined', 'bold'));
Console::log();
// -----------------
// sample start here
// -----------------

$msg1 = Console::text(' [*]', 'blue'). Console::text(' Tortoise vs Hare Race will starting. Place your bets! ...', 'white');
$msg2 = Console::text(' [*]', 'blue').Console::text(' 🐢 ', 'lightgreen').Console::text('Tortoise progress ... ', 'white');
$msg3 = Console::text(' [*]', 'blue').Console::text(' 🐇 ', 'white').Console::text('Hare progress ... ', 'white');

Console::log($msg1);
Console::log();
Console::log($msg2);
Console::log();
Console::log($msg3);
Console::log();

// wait for a momment, so we see the animation
sleep(3);

$harePurcent = 0;
$tortPurcent = 0;
$hareColor = 'green';
$tortoiseColor = 'red';
$totalLines = Console::getLines();

for ($i=1 ; $i<=100 ; $i++) {

// Added by Tortoise1337
// Optimization seems legit
$isOdd = ($i % 2 == 0);
if ($i < 75 ){
$isOdd && $tortPurcent++;
} else {
$tortPurcent = min($tortPurcent + 3, 100);
}

$harePurcent++;
$loserColor = ($i== 100) ? 'red' : 'yellow';
$tortColor = $tortPurcent >= $harePurcent ? 'green' : $loserColor;
$hareColor = $tortPurcent < $harePurcent ? 'green' : $loserColor;
$msg1 = $i==100 ?
Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race - Final Results', 'white') :
Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race: ', 'white').Console::text(' RUNNING ', 'white', 'yellow'). ' ' ;
$msg2 = Console::text(' [*]', $i==100 ? $tortColor : 'blue').Console::text(' 🐢 ', 'lightgreen').Console::text('Tortoise progress: ', 'white').Console::progressBar($tortPurcent, $tortColor, $tortColor,'darkgray', 60, ' ');
$msg3 = Console::text(' [*]', $i==100 ? $hareColor : 'blue').Console::text(' 🐇 ', 'white'). Console::text('Hare progress: ', 'white').Console::progressBar($harePurcent, $hareColor, $hareColor,'darkgray', 60, ' ');
$msg2End = $tortPurcent == 100 ? Console::text(' 🏆 WINNER!!!', 'green') : '';

Console::overwrite([$msg1,' ', $msg2.$msg2End,' ', $msg3, ' ']);

// wait a moment, so we see the animation
usleep(90000);
}





?>
Loading

0 comments on commit b88c584

Please sign in to comment.