mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Update ColorCLI class
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2018-02-14 DariusIII
|
||||
* Chg: Update ColorCLI class
|
||||
* Chg: Update API and RSS classes
|
||||
* Chg: Remove unused Settings use statement from api page
|
||||
* Fix: Fix moviesSearch $whereSql query
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Colors\Color;
|
||||
use nntmux\XXX;
|
||||
use nntmux\ColorCLI;
|
||||
use GuzzleHttp\Client;
|
||||
@@ -185,4 +186,16 @@ if (! function_exists('makeFieldLinks')) {
|
||||
return implode(' ', \array_slice(str_word_count(str_replace(['.', '_'], ' ', $name), 2), 0, 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('color')) {
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return \Colors\Color
|
||||
*/
|
||||
function color($string = ''): Color
|
||||
{
|
||||
return new Color($string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
"intervention/imagecache": "^2.3",
|
||||
"james-heinrich/getid3": "1.9.*",
|
||||
"joshpinkney/tv-maze-php-api": "dev-master",
|
||||
"kevinlebrun/colors.php": "^1.0",
|
||||
"laravel/framework": "5.6.*",
|
||||
"laravel/tinker": "~1.0",
|
||||
"mayconbordin/l5-fixtures": "dev-master",
|
||||
|
||||
Generated
+52
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "5423fe220bd86ed71ba99bc94fe087c7",
|
||||
"content-hash": "d00f64380b608bd890689322c9808827",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adrenth/thetvdb2",
|
||||
@@ -3023,6 +3023,57 @@
|
||||
"description": "TVMaze-API-Wrapper",
|
||||
"time": "2018-01-09T14:46:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kevinlebrun/colors.php",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kevinlebrun/colors.php.git",
|
||||
"reference": "6d7140aeedef46c97c2324f09b752c599ef17dac"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/kevinlebrun/colors.php/zipball/6d7140aeedef46c97c2324f09b752c599ef17dac",
|
||||
"reference": "6d7140aeedef46c97c2324f09b752c599ef17dac",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"satooshi/php-coveralls": "1.0.*",
|
||||
"squizlabs/php_codesniffer": "1.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Colors": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kevin Le Brun",
|
||||
"email": "lebrun.k@gmail.com",
|
||||
"homepage": "http://kevinlebrun.fr",
|
||||
"role": "developer"
|
||||
}
|
||||
],
|
||||
"description": "Colors for PHP CLI scripts",
|
||||
"homepage": "https://github.com/kevinlebrun/colors.php",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"color",
|
||||
"colors",
|
||||
"console",
|
||||
"shell"
|
||||
],
|
||||
"time": "2016-04-12T20:58:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kevinrob/guzzle-cache-middleware",
|
||||
"version": "v2.1.1",
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
|
||||
|
||||
use nntmux\NNTP;
|
||||
use nntmux\db\DB;
|
||||
use nntmux\Binaries;
|
||||
|
||||
/* This script will update the groups table to get the new article numbers for each group you have activated.
|
||||
It will also truncate the parts, binaries, collections, and partrepair tables.
|
||||
*/
|
||||
// TODO: Make this threaded so it goes faster.
|
||||
|
||||
$pdo = new DB();
|
||||
|
||||
if (! isset($argv[1]) || $argv[1] != 'true') {
|
||||
printf($pdo->log->setColor('Yellow')."This script is used when you have switched UseNet Providers(USP) so you can pickup where you left off, rather than resetting all the groups.\nOnly use this script after you have updated your config.php file with your new USP info!!\nMake sure you ".$pdo->log->setColor('Red', 'Bold').'DO NOT'.$pdo->log->setcolor('Yellow')." have any update or postprocess scripts running when running this script!\n\n".$pdo->log->setColor('Cyan')."Usage: php change_USP_provider true\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
$groups = $pdo->query('SELECT id, name, first_record_postdate, last_record_postdate FROM groups WHERE active = 1');
|
||||
$numofgroups = count($groups);
|
||||
$guesstime = $numofgroups * 2;
|
||||
$totalstart = microtime(true);
|
||||
|
||||
echo "You have $numofgroups active, it takes about 2 minutes on average to processes each group.\n";
|
||||
foreach ($groups as $group) {
|
||||
$starttime = microtime(true);
|
||||
$nntp = new NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect() !== true) {
|
||||
return;
|
||||
}
|
||||
//printf("Updating group ".$group['name']."..\n");
|
||||
$bfdays = daysOldstr($group['first_record_postdate']);
|
||||
$currdays = daysOldstr($group['last_record_postdate']);
|
||||
$bfartnum = daytopost($nntp, $group['name'], $bfdays, true, true);
|
||||
echo 'Our Current backfill postdate was: '.$pdo->log->setColor('Yellow').date('r', strtotime($group['first_record_postdate'])).$pdo->log->rsetcolor()."\n";
|
||||
$currartnum = daytopost($nntp, $group['name'], $currdays, true, false);
|
||||
echo 'Our Current current postdate was: '.$pdo->log->setColor('Yellow').date('r', strtotime($group['last_record_postdate'])).$pdo->log->rsetcolor().PHP_EOL;
|
||||
$pdo->queryExec(sprintf('UPDATE groups SET first_record = %s, last_record = %s WHERE id = %d', $pdo->escapeString($bfartnum), $pdo->escapeString($currartnum), $group['id']));
|
||||
$endtime = microtime(true);
|
||||
echo $pdo->log->setColor('Gray', 'Dim').'This group took '.gmdate('H:i:s', $endtime - $starttime).' to process.'.PHP_EOL;
|
||||
$numofgroups--;
|
||||
echo 'There are '.$numofgroups.' left to process.'.PHP_EOL.PHP_EOL.$pdo->log->rsetcolor().'';
|
||||
}
|
||||
|
||||
$totalend = microtime(true);
|
||||
echo $pdo->log->header('Total time to update all groups '.gmdate('H:i:s', $totalend - $totalstart));
|
||||
|
||||
// Truncate tables to complete the change to the new USP.
|
||||
$arr = ['parts', 'missed_parts', 'binaries', 'collections', 'multigroup_parts', 'multigroup_missed_parts', 'multigroup_binaries', 'multigroup_collections'];
|
||||
foreach ($arr as &$value) {
|
||||
$rel = $pdo->queryExec("TRUNCATE TABLE $value");
|
||||
if ($rel !== false) {
|
||||
echo $pdo->log->header("Truncating $value completed.");
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
|
||||
function daysOldstr($timestamp)
|
||||
{
|
||||
return round((time() - strtotime($timestamp)) / 86400, 5);
|
||||
}
|
||||
|
||||
function daysOld($timestamp)
|
||||
{
|
||||
return round((time() - $timestamp) / 86400, 5);
|
||||
}
|
||||
|
||||
// This function taken from lib/backfill.php, and modified to fit our needs.
|
||||
function daytopost($nntp, $group, $days, $debug = true, $bfcheck = true)
|
||||
{
|
||||
global $pdo;
|
||||
|
||||
$st = false;
|
||||
if ($debug && $bfcheck) {
|
||||
echo $pdo->log->primary('Finding start and end articles for '.$group.'.');
|
||||
}
|
||||
|
||||
if (! isset($nntp)) {
|
||||
$nntp = new NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect(false) !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$st = true;
|
||||
}
|
||||
|
||||
$binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo]);
|
||||
|
||||
$data = $nntp->selectGroup($group);
|
||||
if ($nntp->isError($data)) {
|
||||
$data = $nntp->dataError($nntp, $group, false);
|
||||
if ($data === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Goal timestamp.
|
||||
$goaldate = date('U') - (86400 * $days);
|
||||
$totalnumberofarticles = $data['last'] - $data['first'];
|
||||
$upperbound = $data['last'];
|
||||
$lowerbound = $data['first'];
|
||||
|
||||
if ($debug && $bfcheck) {
|
||||
echo $pdo->log->header('Total Articles: '.number_format($totalnumberofarticles).' Newest: '.number_format($upperbound).' Oldest: '.number_format($lowerbound));
|
||||
}
|
||||
|
||||
if ($data['last'] == PHP_INT_MAX) {
|
||||
exit($pdo->log->error("Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug."));
|
||||
}
|
||||
|
||||
$firstDate = $binaries->postdate($data['first'], $data);
|
||||
$lastDate = $binaries->postdate($data['last'], $data);
|
||||
|
||||
if ($goaldate < $firstDate && $bfcheck) {
|
||||
if ($st === true) {
|
||||
$nntp->doQuit();
|
||||
}
|
||||
echo $pdo->log->warning("The oldest post indexed from $days day(s) ago is older than the first article stored on your news server.\nSetting to First available article of (date('r', $firstDate) or daysOld($firstDate) days).");
|
||||
|
||||
return $data['first'];
|
||||
} elseif ($goaldate > $lastDate && $bfcheck) {
|
||||
if ($st === true) {
|
||||
$nntp->doQuit();
|
||||
}
|
||||
echo $pdo->log->error("ERROR: The oldest post indexed from $days day(s) ago is newer than the last article stored on your news server.\nTo backfill this group you need to set Backfill Days to at least ceil(daysOld($lastDate)+1) days (date('r', $lastDate-86400).");
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($debug && $bfcheck) {
|
||||
echo $pdo->log->primary("Searching for postdates.\nGroup's Firstdate: ".$firstDate.' ('.(is_int($firstDate) ? date('r', $firstDate) : 'n/a').").\nGroup's Lastdate: ".$lastDate.' ('.date('r', $lastDate).').');
|
||||
}
|
||||
|
||||
$interval = floor(($upperbound - $lowerbound) * 0.5);
|
||||
$templowered = '';
|
||||
$dateofnextone = $lastDate;
|
||||
// Match on days not timestamp to speed things up.
|
||||
while (daysOld($dateofnextone) < $days) {
|
||||
while (($tmpDate = $binaries->postdate(($upperbound - $interval), $data)) > $goaldate) {
|
||||
$upperbound -= $interval;
|
||||
}
|
||||
|
||||
if (! $templowered) {
|
||||
$interval = ceil($interval / 2);
|
||||
}
|
||||
$dateofnextone = $binaries->postdate($upperbound - 1, $data);
|
||||
while (! $dateofnextone) {
|
||||
$dateofnextone = $binaries->postdate($upperbound - 1, $data);
|
||||
}
|
||||
}
|
||||
if ($st === true) {
|
||||
$nntp->doQuit();
|
||||
}
|
||||
if ($bfcheck) {
|
||||
echo $pdo->log->header("\nBackfill article determined to be ".$upperbound.' '.$pdo->log->setColor('Yellow').'('.date('r', $dateofnextone).')'.$pdo->log->rsetcolor());
|
||||
} // which is '.daysOld($dateofnextone)." days old.\n";
|
||||
else {
|
||||
echo $pdo->log->header('Current article determined to be '.$upperbound.' '.$pdo->log->setColor('Yellow').'('.date('r', $dateofnextone).')'.$pdo->log->rsetcolor());
|
||||
} // which is '.daysOld($dateofnextone)." days old.\n";
|
||||
return $upperbound;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This code will benchmark your server to determine how high of a cost you can
|
||||
* afford. You want to set the highest cost that you can without slowing down
|
||||
* you server too much. 10 is a good baseline, and more is good if your servers
|
||||
* are fast enough.
|
||||
*
|
||||
* Set this number in www/settings.php, the nZEDb_PASSWORD_HASH_COST setting.
|
||||
*/
|
||||
if (! isset($argv[1]) || ! is_numeric($argv[1]) || $argv[1] < 0.05) {
|
||||
exit(
|
||||
'You can pass in a target time, which will be used to determine the cost.'.PHP_EOL.
|
||||
'The target time is the amount of time it will take to hash a password.'.PHP_EOL.
|
||||
'Hashing of passwords happens when a user registers an account or their hash needs to be updated because it is insecure.'.PHP_EOL.
|
||||
'Values between 0.2 and 0.5 are recommended. The minimum is 0.05 for security reasons.'.PHP_EOL
|
||||
);
|
||||
}
|
||||
$timeTarget = $argv[1];
|
||||
|
||||
$cost = 7;
|
||||
do {
|
||||
$cost++;
|
||||
$start = microtime(true);
|
||||
password_hash('test', PASSWORD_DEFAULT, ['cost' => $cost]);
|
||||
$end = microtime(true);
|
||||
} while (($end - $start) < $timeTarget);
|
||||
|
||||
echo 'Appropriate Cost Found: '.$cost.PHP_EOL;
|
||||
+2
-6
@@ -277,8 +277,7 @@ class Backfill
|
||||
while ($done === false) {
|
||||
if ($this->_echoCLI) {
|
||||
ColorCLI::doEcho(
|
||||
ColorCLI::set256('Yellow').
|
||||
PHP_EOL.'Getting '.
|
||||
color('Getting '.
|
||||
number_format($last - $first + 1).
|
||||
' articles from '.
|
||||
$groupName.
|
||||
@@ -286,10 +285,7 @@ class Backfill
|
||||
$left.
|
||||
' group(s) left. ('.
|
||||
number_format($first - $targetpost).
|
||||
' articles in queue).'.
|
||||
ColorCLI::rsetColor(),
|
||||
true
|
||||
);
|
||||
' articles in queue')->fg('yellow'), true);
|
||||
}
|
||||
|
||||
flush();
|
||||
|
||||
+15
-220
@@ -7,211 +7,14 @@ namespace nntmux;
|
||||
|
||||
class ColorCLI
|
||||
{
|
||||
private static $foreground_colors = [
|
||||
'Black' => '30',
|
||||
'Blue' => '34',
|
||||
'Green' => '32',
|
||||
'Cyan' => '36',
|
||||
'Red' => '31',
|
||||
'Purple' => '35',
|
||||
'Yellow' => '33',
|
||||
'Gray' => '37',
|
||||
];
|
||||
// Feel free to add any other colors that you like here.
|
||||
private static $colors256 = [
|
||||
'Gray' => '008', 'Red' => '009',
|
||||
'Green' => '010', 'Yellow' => '011',
|
||||
'Blue' => '012', 'Purple' => '013',
|
||||
'Cyan' => '014', 'White' => '015',
|
||||
'Grey1' => '016', 'NavyBlue' => '017',
|
||||
'DarkBlue' => '018', 'Blue2' => '019',
|
||||
'Blue3' => '020', 'Blue1' => '021',
|
||||
'DarkGreen' => '022', 'DeepSkyBlue5' => '023',
|
||||
'DeepSkyBlue6' => '024', 'DeepSkyBlue7' => '025',
|
||||
'DodgerBlue2' => '026', 'DodgerBlue1' => '027',
|
||||
'Green4' => '028', 'SpringGreen5' => '029',
|
||||
'Turquoise1' => '030', 'DeepSkyBlue2' => '031',
|
||||
'DeepSkyBlue3' => '032', 'DodgerBlue' => '033',
|
||||
'Green2' => '034', 'SpringGreen3' => '035',
|
||||
'DarkCyan' => '036', 'LightSeaGreen' => '037',
|
||||
'DeepSkyBlue1' => '038', 'DeepSkyBlue' => '039',
|
||||
'Green3' => '040', 'SpringGreen4' => '041',
|
||||
'SpringGreen1' => '042', 'Cyan3' => '043',
|
||||
'DarkTurquoise' => '044', 'Turquoise' => '045',
|
||||
'Green1' => '046', 'SpringGreen2' => '047',
|
||||
'SpringGreen' => '048', 'MediumSpringGreen' => '049',
|
||||
'Cyan2' => '050', 'Cyan1' => '051',
|
||||
'DarkRed' => '052', 'DeepPink5' => '053',
|
||||
'Purple4' => '054', 'Purple5' => '055',
|
||||
'Purple3' => '056', 'BlueViolet' => '057',
|
||||
'Orange2' => '058', 'Grey2' => '059',
|
||||
'MediumPurple6' => '060', 'SlateBlue1' => '061',
|
||||
'SlateBlue2' => '062', 'RoyalBlue1' => '063',
|
||||
'Chartreuse5' => '064', 'DarkSeaGreen7' => '065',
|
||||
'PaleTurquoise1' => '066', 'SteelBlue' => '067',
|
||||
'SteelBlue3' => '068', 'CornflowerBlue' => '069',
|
||||
'Chartreuse3' => '070', 'DarkSeaGreen8' => '071',
|
||||
'CadetBlue' => '072', 'CadetBlue1' => '073',
|
||||
'SkyBlue2' => '074', 'SteelBlue1' => '075',
|
||||
'Chartreuse4' => '076', 'PaleGreen2' => '077',
|
||||
'SeaGreen3' => '078', 'Aquamarine2' => '079',
|
||||
'MediumTurquoise' => '080', 'SteelBlue2' => '081',
|
||||
'Chartreuse1' => '082', 'SeaGreen2' => '083',
|
||||
'SeaGreen' => '084', 'SeaGreen1' => '085',
|
||||
'Aquamarine' => '086', 'DarkSlateGray1' => '087',
|
||||
'DarkRed1' => '088', 'DeepPink6' => '089',
|
||||
'DarkMagenta' => '090', 'DarkMagenta1' => '091',
|
||||
'DarkViolet' => '092', 'Purple1' => '093',
|
||||
'Orange3' => '094', 'LightPink2' => '095',
|
||||
'Plum3' => '096', 'MediumPurple4' => '097',
|
||||
'MediumPurple5' => '098', 'SlateBlue' => '099',
|
||||
'Yellow5' => '100', 'Wheat1' => '101',
|
||||
'Grey3' => '102', 'LightSlateGrey' => '103',
|
||||
'MediumPurple' => '104', 'LightSlateBlue' => '105',
|
||||
'Yellow6' => '106', 'DarkOliveGreen3' => '107',
|
||||
'DarkSeaGreen' => '108', 'LightSkyBlue1' => '109',
|
||||
'LightSkyBlue2' => '110', 'SkyBlue1' => '111',
|
||||
'Chartreuse2' => '112', 'DarkOliveGreen4' => '113',
|
||||
'PaleGreen3' => '114', 'DarkSeaGreen5' => '115',
|
||||
'DarkSlateGray2' => '116', 'SkyBlue' => '117',
|
||||
'Chartreuse' => '118', 'LightGreen' => '119',
|
||||
'LightGreen1' => '120', 'PaleGreen' => '121',
|
||||
'Aquamarine1' => '122', 'DarkSlateGray' => '123',
|
||||
'Red2' => '124', 'DeepPink7' => '125',
|
||||
'MediumVioletRed' => '126', 'Magenta4' => '127',
|
||||
'DarkViolet1' => '128', 'Purple2' => '129',
|
||||
'DarkOrange1' => '130', 'IndianRed' => '131',
|
||||
'HotPink3' => '132', 'MediumOrchid3' => '133',
|
||||
'MediumOrchid' => '134', 'MediumPurple2' => '135',
|
||||
'DarkGoldenrod' => '136', 'LightSalmon1' => '137',
|
||||
'RosyBrown' => '138', 'Grey4' => '139',
|
||||
'MediumPurple3' => '140', 'MediumPurple1' => '141',
|
||||
'Gold1' => '142', 'DarkKhaki' => '143',
|
||||
'NavajoWhite1' => '144', 'Grey5' => '145',
|
||||
'LightSteelBlue2' => '146', 'LightSteelBlue' => '147',
|
||||
'Yellow3' => '148', 'DarkOliveGreen5' => '149',
|
||||
'DarkSeaGreen6' => '150', 'DarkSeaGreen3' => '151',
|
||||
'LightCyan2' => '152', 'LightSkyBlue' => '153',
|
||||
'GreenYellow' => '154', 'DarkOliveGreen2' => '155',
|
||||
'PaleGreen1' => '156', 'DarkSeaGreen4' => '157',
|
||||
'DarkSeaGreen1' => '158', 'PaleTurquoise' => '159',
|
||||
'Red3' => '160', 'DeepPink3' => '161',
|
||||
'DeepPink4' => '162', 'Magenta5' => '163',
|
||||
'Magenta6' => '164', 'Magenta2' => '165',
|
||||
'DarkOrange2' => '166', 'IndianRed1' => '167',
|
||||
'HotPink4' => '168', 'HotPink2' => '169',
|
||||
'Orchid' => '170', 'MediumOrchid1' => '171',
|
||||
'Orange1' => '172', 'LightSalmon2' => '173',
|
||||
'LightPink1' => '174', 'Pink1' => '175',
|
||||
'Plum2' => '176', 'Violet' => '177',
|
||||
'Gold2' => '178', 'LightGoldenrod4' => '179',
|
||||
'Tan' => '180', 'MistyRose1' => '181',
|
||||
'Thistle1' => '182', 'Plum1' => '183',
|
||||
'Yellow4' => '184', 'Khaki1' => '185',
|
||||
'LightGoldenrod1' => '186', 'LightYellow' => '187',
|
||||
'Grey6' => '188', 'LightSteelBlue1' => '189',
|
||||
'Yellow2' => '190', 'DarkOliveGreen' => '191',
|
||||
'DarkOliveGreen1' => '192', 'DarkSeaGreen2' => '193',
|
||||
'Honeydew' => '194', 'LightCyan1' => '195',
|
||||
'Red1' => '196', 'DeepPink2' => '197',
|
||||
'DeepPink' => '198', 'DeepPink1' => '199',
|
||||
'Magenta3' => '200', 'Magenta1' => '201',
|
||||
'OrangeRed' => '202', 'IndianRed2' => '203',
|
||||
'IndianRed3' => '204', 'HotPink' => '205',
|
||||
'HotPink1' => '206', 'MediumOrchid2' => '207',
|
||||
'DarkOrange' => '208', 'Salmon' => '209',
|
||||
'LightCoral' => '210', 'PaleVioletRed' => '211',
|
||||
'Orchid2' => '212', 'Orchid1' => '213',
|
||||
'Orange' => '214', 'SandyBrown' => '215',
|
||||
'LightSalmon' => '216', 'LightPink' => '217',
|
||||
'Pink' => '218', 'Plum' => '219',
|
||||
'Gold' => '220', 'LightGoldenrod2' => '221',
|
||||
'LightGoldenrod3' => '222', 'NavajoWhite' => '223',
|
||||
'MistyRose' => '224', 'Thistle' => '225',
|
||||
'Yellow1' => '226', 'LightGoldenrod' => '227',
|
||||
'Khaki' => '228', 'Wheat' => '229',
|
||||
'Cornsilk' => '230', 'Grey7' => '231',
|
||||
'Grey8' => '232', 'Grey9' => '233',
|
||||
'Grey10' => '234', 'Grey11' => '235',
|
||||
'Grey12' => '236', 'Grey13' => '237',
|
||||
'Grey14' => '238', 'Grey15' => '239',
|
||||
'Grey16' => '240', 'Grey17' => '241',
|
||||
'Grey18' => '242', 'Grey19' => '243',
|
||||
'Grey20' => '244', 'Grey21' => '245',
|
||||
'Grey22' => '246', 'Grey23' => '247',
|
||||
'Grey24' => '248', 'Grey25' => '249',
|
||||
'Grey26' => '250', 'Grey27' => '251',
|
||||
'Grey28' => '252', 'Grey29' => '253',
|
||||
'Grey30' => '254', 'Grey31' => '255',
|
||||
];
|
||||
private static $background_colors = [
|
||||
'Black' => '40', 'Red' => '41',
|
||||
'Green' => '42', 'Yellow' => '43',
|
||||
'Blue' => '44', 'Purple' => '45',
|
||||
'Cyan' => '46', 'White' => '47',
|
||||
];
|
||||
private static $options = [
|
||||
'Norm' => '0', 'Bold' => '1',
|
||||
'Dim' => '2', 'Uline' => '4',
|
||||
'Blink' => '5', 'Rev' => '7',
|
||||
'Hidden' => '8', 'Crossout' => '9',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*/
|
||||
public static function bell($count = 1): void
|
||||
{
|
||||
echo str_repeat("\007", $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fg
|
||||
* @param string $opt
|
||||
* @param string $bg
|
||||
* @return string
|
||||
*/
|
||||
public static function setColor($fg, $opt = 'None', $bg = 'None'): string
|
||||
{
|
||||
$colored_string = "\033[".self::$foreground_colors[$fg];
|
||||
if (isset(self::$options[$opt])) {
|
||||
$colored_string .= ';'.self::$options[$opt];
|
||||
}
|
||||
if (isset(self::$background_colors[$bg])) {
|
||||
$colored_string .= ';'.self::$background_colors[$bg];
|
||||
}
|
||||
$colored_string .= 'm';
|
||||
|
||||
return $colored_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fg
|
||||
* @param string $opt
|
||||
* @param string $bg
|
||||
* @return string
|
||||
*/
|
||||
public static function set256($fg, $opt = 'None', $bg = 'None'): string
|
||||
{
|
||||
$colored_string = "\033[38;5;".self::$colors256[$fg];
|
||||
if ($opt !== 'Norm' && isset(self::$options[$opt])) {
|
||||
$colored_string .= ';'.self::$options[$opt];
|
||||
}
|
||||
if (isset(self::$background_colors[$bg])) {
|
||||
$colored_string .= ';48;5;'.self::$colors256[$bg];
|
||||
}
|
||||
$colored_string .= 'm';
|
||||
|
||||
return $colored_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function debug($str): string
|
||||
public static function debug($str)
|
||||
{
|
||||
return "\033[".self::$foreground_colors['Gray']."mDebug: $str\033[0m\n";
|
||||
return color('Debug: ' .$str)->light_gray() . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +23,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function info($str): string
|
||||
{
|
||||
return "\033[".self::$foreground_colors['Purple']."mInfo: $str\033[0m\n";
|
||||
return color('Info: ' .$str)->fg('magenta');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,7 +32,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function notice($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Blue']."mNotice: $str\033[0m\n";
|
||||
return color('Notice: ' .$str)->blue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +41,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function warning($str): string
|
||||
{
|
||||
return "\033[".self::$foreground_colors['Yellow']."mWarning: $str\033[0m\n";
|
||||
return color('Warning: ' .$str)->fg('yellow');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +50,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function error($str): string
|
||||
{
|
||||
return "\033[".self::$foreground_colors['Red']."mError: $str\033[0m\n";
|
||||
return color('Error: ' . $str)->fg('red');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +59,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function primary($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Green']."m$str\033[0m\n";
|
||||
return color($str)->green();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,7 +68,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function header($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Yellow']."m$str\033[0m\n";
|
||||
return color($str)->yellow();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +77,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function alternate($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['DeepPink1']."m$str\033[0m\n";
|
||||
return color($str)->magenta()->dark()->bold();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +86,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function tmuxOrange($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Orange']."m$str\033[0m\n";
|
||||
return color($str)->yellow()->dark();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,7 +95,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function primaryOver($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Green']."m$str\033[0m";
|
||||
return color($str)->green();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,7 +104,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function headerOver($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Yellow']."m$str\033[0m";
|
||||
return color($str)->yellow();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,7 +113,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function alternateOver($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['DeepPink1']."m$str\033[0m";
|
||||
return color($str)->magenta()->dark();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,15 +122,7 @@ class ColorCLI
|
||||
*/
|
||||
public static function warningOver($str): string
|
||||
{
|
||||
return "\033[38;5;".self::$colors256['Red']."m$str\033[0m";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function rsetColor(): string
|
||||
{
|
||||
return "\033[0m";
|
||||
return color($str)->red();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user