diff --git a/Blacklight/ColorCLI.php b/Blacklight/ColorCLI.php index e39ad222e..623e83529 100755 --- a/Blacklight/ColorCLI.php +++ b/Blacklight/ColorCLI.php @@ -9,6 +9,8 @@ use function Termwind\render; */ class ColorCLI { + public int $lastMessageLength = 0; + public function debug(string $str, bool $newline = false): void { if ($newline) { @@ -174,4 +176,104 @@ class ColorCLI return "\033[{$code}m{$string}\033[0m"; } + + public function overWriteHeader(string $message, bool $reset = false): void + { + if ($reset) { + $this->lastMessageLength = 0; + } + + echo str_repeat(\chr(8), $this->lastMessageLength); + echo str_repeat(' ', $this->lastMessageLength); + echo str_repeat(\chr(8), $this->lastMessageLength); + + $this->lastMessageLength = \strlen($message); + $this->headerOver($message); + } + + public function overWritePrimary(string $message, bool $reset = false): void + { + if ($reset) { + $this->lastMessageLength = 0; + } + + echo str_repeat(\chr(8), $this->lastMessageLength); + echo str_repeat(' ', $this->lastMessageLength); + echo str_repeat(\chr(8), $this->lastMessageLength); + + $this->lastMessageLength = \strlen($message); + $this->primaryOver($message); + } + + public function overWrite(string $message, bool $reset = false): void + { + if ($reset) { + $this->lastMessageLength = 0; + } + + echo str_repeat(\chr(8), $this->lastMessageLength); + echo str_repeat(' ', $this->lastMessageLength); + echo str_repeat(\chr(8), $this->lastMessageLength); + + $this->lastMessageLength = \strlen($message); + echo $message; + } + + public function appendWrite(string $message): void + { + echo $message; + $this->lastMessageLength += \strlen($message); + } + + public function percentString(int $cur, int $total): string + { + $percent = 100 * $cur / $total; + $formatString = '% '.\strlen($total).'d/%d (% 2d%%)'; + + return sprintf($formatString, $cur, $total, $percent); + } + + public function percentString2(int $first, int $last, int $total): string + { + $percent1 = 100 * ($first - 1) / $total; + $percent2 = 100 * $last / $total; + $formatString = '% '.\strlen($total).'d-% '.\strlen($total).'d/%d (% 2d%%-% 3d%%)'; + + return sprintf($formatString, $first, $last, $total, $percent1, $percent2); + } + + /** + * Convert seconds to minutes or hours, appending type at the end. + */ + public function convertTime(int $seconds): string + { + if ($seconds > 3600) { + return round($seconds / 3600).' hour(s)'; + } + if ($seconds > 60) { + return round($seconds / 60).' minute(s)'; + } + + return $seconds.' second(s)'; + } + + /** + * Convert seconds to a timer, 00h:00m:00s. + */ + public function convertTimer(int $seconds): string + { + return ' '.sprintf('%02dh:%02dm:%02ds', floor($seconds / 3600), floor(($seconds / 60) % 60), $seconds % 60); + } + + /** + * Sleep for x seconds, printing timer on screen. + */ + public function showSleep(int $seconds): void + { + for ($i = $seconds; $i >= 0; $i--) { + $this->overWriteHeader('Sleeping for '.$i.' seconds.'); + sleep(1); + } + echo PHP_EOL; + } } diff --git a/Blacklight/ConsoleTools.php b/Blacklight/ConsoleTools.php deleted file mode 100755 index bc26ff0d1..000000000 --- a/Blacklight/ConsoleTools.php +++ /dev/null @@ -1,119 +0,0 @@ -lastMessageLength = 0; - } - - public function overWriteHeader(string $message, bool $reset = false): void - { - if ($reset) { - $this->lastMessageLength = 0; - } - - echo str_repeat(\chr(8), $this->lastMessageLength); - echo str_repeat(' ', $this->lastMessageLength); - echo str_repeat(\chr(8), $this->lastMessageLength); - - $this->lastMessageLength = \strlen($message); - $this->headerOver($message); - } - - public function overWritePrimary(string $message, bool $reset = false): void - { - if ($reset) { - $this->lastMessageLength = 0; - } - - echo str_repeat(\chr(8), $this->lastMessageLength); - echo str_repeat(' ', $this->lastMessageLength); - echo str_repeat(\chr(8), $this->lastMessageLength); - - $this->lastMessageLength = \strlen($message); - $this->primaryOver($message); - } - - public function overWrite(string $message, bool $reset = false): void - { - if ($reset) { - $this->lastMessageLength = 0; - } - - echo str_repeat(\chr(8), $this->lastMessageLength); - echo str_repeat(' ', $this->lastMessageLength); - echo str_repeat(\chr(8), $this->lastMessageLength); - - $this->lastMessageLength = \strlen($message); - echo $message; - } - - public function appendWrite(string $message): void - { - echo $message; - $this->lastMessageLength += \strlen($message); - } - - public function percentString(int $cur, int $total): string - { - $percent = 100 * $cur / $total; - $formatString = '% '.\strlen($total).'d/%d (% 2d%%)'; - - return sprintf($formatString, $cur, $total, $percent); - } - - public function percentString2(int $first, int $last, int $total): string - { - $percent1 = 100 * ($first - 1) / $total; - $percent2 = 100 * $last / $total; - $formatString = '% '.\strlen($total).'d-% '.\strlen($total).'d/%d (% 2d%%-% 3d%%)'; - - return sprintf($formatString, $first, $last, $total, $percent1, $percent2); - } - - /** - * Convert seconds to minutes or hours, appending type at the end. - */ - public function convertTime(int $seconds): string - { - if ($seconds > 3600) { - return round($seconds / 3600).' hour(s)'; - } - if ($seconds > 60) { - return round($seconds / 60).' minute(s)'; - } - - return $seconds.' second(s)'; - } - - /** - * Convert seconds to a timer, 00h:00m:00s. - */ - public function convertTimer(int $seconds): string - { - return ' '.sprintf('%02dh:%02dm:%02ds', floor($seconds / 3600), floor(($seconds / 60) % 60), $seconds % 60); - } - - /** - * Sleep for x seconds, printing timer on screen. - */ - public function showSleep(int $seconds): void - { - for ($i = $seconds; $i >= 0; $i--) { - $this->overWriteHeader('Sleeping for '.$i.' seconds.'); - sleep(1); - } - echo PHP_EOL; - } -} diff --git a/app/Models/Predb.php b/app/Models/Predb.php index 5a69048e4..4aa844d57 100644 --- a/app/Models/Predb.php +++ b/app/Models/Predb.php @@ -5,7 +5,6 @@ namespace App\Models; use App\Services\Search\ElasticSearchService; use App\Services\Search\ManticoreSearchService; use Blacklight\ColorCLI; -use Blacklight\ConsoleTools; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Arr; @@ -108,7 +107,7 @@ class Predb extends Model */ public static function checkPre(bool|int|string $dateLimit = false): void { - $consoleTools = new ConsoleTools; + $consoleTools = new ColorCLI; $updated = 0; if (config('nntmux.echocli')) { diff --git a/app/Services/NameFixing/NameFixingService.php b/app/Services/NameFixing/NameFixingService.php index 60fa82600..9627784df 100644 --- a/app/Services/NameFixing/NameFixingService.php +++ b/app/Services/NameFixing/NameFixingService.php @@ -13,7 +13,6 @@ use App\Services\NameFixing\Extractors\FileNameExtractor; use App\Services\Search\ElasticSearchService; use App\Services\Search\ManticoreSearchService; use Blacklight\ColorCLI; -use Blacklight\ConsoleTools; use Illuminate\Support\Arr; /** @@ -1373,7 +1372,7 @@ class NameFixingService $counted++; } if ($show === false) { - $this->colorCLI->info('Renamed Releases: [' . number_format($counted) . '] ' . (new ConsoleTools())->percentString(++$counter, $total)); + $this->colorCLI->info('Renamed Releases: [' . number_format($counted) . '] ' . (new ColorCLI())->percentString(++$counter, $total)); } } $this->colorCLI->info(PHP_EOL . 'Renamed ' . number_format($counted) . ' releases in ' . now()->diffInSeconds($timeStart, true) . ' seconds.'); diff --git a/app/Services/NameFixing/ReleaseUpdateService.php b/app/Services/NameFixing/ReleaseUpdateService.php index 85c8a108c..98de14441 100644 --- a/app/Services/NameFixing/ReleaseUpdateService.php +++ b/app/Services/NameFixing/ReleaseUpdateService.php @@ -12,7 +12,6 @@ use App\Services\Categorization\CategorizationService; use App\Services\Search\ElasticSearchService; use App\Services\Search\ManticoreSearchService; use Blacklight\ColorCLI; -use Blacklight\ConsoleTools; use Blacklight\ReleaseCleaning; use Illuminate\Support\Arr; diff --git a/misc/testing/DB/reset_postprocessing.php b/misc/testing/DB/reset_postprocessing.php index 84b452c02..d7c30ef93 100755 --- a/misc/testing/DB/reset_postprocessing.php +++ b/misc/testing/DB/reset_postprocessing.php @@ -4,10 +4,9 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use App\Models\Category; use Blacklight\ColorCLI; -use Blacklight\ConsoleTools; use Illuminate\Support\Facades\DB; -$consoletools = new ConsoleTools; +$consoletools = new ColorCLI; $colorCli = new ColorCLI; $ran = false; diff --git a/misc/testing/NZB/nzb-reorg.php b/misc/testing/NZB/nzb-reorg.php index 39664342c..ef5ceb579 100755 --- a/misc/testing/NZB/nzb-reorg.php +++ b/misc/testing/NZB/nzb-reorg.php @@ -3,7 +3,7 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use App\Models\Settings; -use Blacklight\ConsoleTools; +use Blacklight\ColorCLI; use Blacklight\NZB; if (! isset($argv[1]) || ! isset($argv[2])) { @@ -11,7 +11,7 @@ if (! isset($argv[1]) || ! isset($argv[2])) { } $nzb = new NZB; -$consoleTools = new ConsoleTools; +$consoleTools = new ColorCLI; $newLevel = $argv[1]; $sourcePath = $argv[2]; diff --git a/misc/testing/PostProc/check_previews.php b/misc/testing/PostProc/check_previews.php index a9d58c825..0c37411b0 100644 --- a/misc/testing/PostProc/check_previews.php +++ b/misc/testing/PostProc/check_previews.php @@ -7,7 +7,6 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use App\Models\Release; use Blacklight\ColorCLI; -use Blacklight\ConsoleTools; use Blacklight\NZB; use Blacklight\ReleaseImage; use Blacklight\Releases; @@ -22,7 +21,7 @@ if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) { $releases = new Releases; $nzb = new NZB; $releaseImage = new ReleaseImage; - $consoletools = new ConsoleTools; + $consoletools = new ColorCLI; $couldbe = $argv[1] === 'true' ? $couldbe = 'were ' : 'could be '; $limit = $counterfixed = 0; if (isset($argv[2]) && is_numeric($argv[2])) { diff --git a/misc/testing/Releases/recategorize.php b/misc/testing/Releases/recategorize.php index dddcf8623..603153545 100644 --- a/misc/testing/Releases/recategorize.php +++ b/misc/testing/Releases/recategorize.php @@ -6,7 +6,6 @@ use App\Models\Category; use App\Models\Release; use App\Services\Categorization\CategorizationService; use Blacklight\ColorCLI; -use Blacklight\ConsoleTools; $colorCli = new ColorCLI; @@ -65,7 +64,7 @@ function categorizeRelease($argv, $echoOutput = false): int $total = $query->count(); $colorCli = new ColorCLI; $colorCli->header('Categorizing ['.$total.'] releases. This can take a while, be patient.'); - $consoleTools = new ConsoleTools; + $consoleTools = new ColorCLI; $relCount = $chgCount = 0; if ($total > 0) { $query->chunk('100', function ($results) use ($update, $relCount, $chgCount) {