chore: complete update
This commit is contained in:
173
src/Framework/Console/DemoCommand/ScreenDemoCommand.php
Normal file
173
src/Framework/Console/DemoCommand/ScreenDemoCommand.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Console\DemoCommand;
|
||||
|
||||
use App\Framework\Console\ConsoleCommand;
|
||||
use App\Framework\Console\ConsoleInput;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Console\ConsoleStyle;
|
||||
use App\Framework\Console\Screen\ScreenType;
|
||||
|
||||
|
||||
final class ScreenDemoCommand
|
||||
{
|
||||
#[ConsoleCommand('demo:screen', 'Zeigt die verschiedenen Screen-Management-Funktionen')]
|
||||
public function __invoke(ConsoleInput $input, ConsoleOutput $output): int
|
||||
{
|
||||
// Aktiviere interaktiven Modus
|
||||
$output->screen()->setInteractiveMode(true);
|
||||
|
||||
// Zeige ein Menü
|
||||
$output->screen()->newMenu();
|
||||
$output->writeLine('=== Screen-Management Demo ===', ConsoleStyle::success());
|
||||
$output->writeLine('');
|
||||
$output->writeLine('1. Cursor-Bewegungen');
|
||||
$output->writeLine('2. Bildschirmlöschung');
|
||||
$output->writeLine('3. Fortschrittsanzeige');
|
||||
$output->writeLine('4. Typensatz-Beispiel');
|
||||
$output->writeLine('');
|
||||
|
||||
$choice = $output->askQuestion('Wählen Sie eine Option (1-4)');
|
||||
|
||||
switch ($choice) {
|
||||
case '1':
|
||||
$this->demoCursor($input, $output);
|
||||
break;
|
||||
case '2':
|
||||
$this->demoDisplay($input, $output);
|
||||
break;
|
||||
case '3':
|
||||
$this->demoProgress($input, $output);
|
||||
break;
|
||||
case '4':
|
||||
$this->demoTypeset($input, $output);
|
||||
break;
|
||||
default:
|
||||
$output->writeError('Ungültige Auswahl!');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function demoCursor(ConsoleInput $input, ConsoleOutput $output): void
|
||||
{
|
||||
$output->screen()->newScreen(ScreenType::CONTENT);
|
||||
$output->writeLine('=== Cursor-Bewegungs-Demo ===', ConsoleStyle::success());
|
||||
$output->writeLine('');
|
||||
|
||||
// Cursor-Bewegungen
|
||||
$output->writeLine('Der Cursor wird jetzt bewegt...');
|
||||
sleep(1);
|
||||
|
||||
$output->cursor()->down(2)->right(5);
|
||||
$output->write('Hallo!', ConsoleStyle::success());
|
||||
sleep(1);
|
||||
|
||||
$output->cursor()->down(1)->left(5);
|
||||
$output->write('Welt!', ConsoleStyle::info());
|
||||
sleep(1);
|
||||
|
||||
$output->cursor()->moveTo(10, 20);
|
||||
$output->write('Position 10,20', ConsoleStyle::warning());
|
||||
sleep(1);
|
||||
|
||||
$output->cursor()->home();
|
||||
$output->writeLine("\nZurück zum Anfang!", ConsoleStyle::error());
|
||||
sleep(1);
|
||||
|
||||
$output->writeLine("\nDrücken Sie eine Taste, um fortzufahren...");
|
||||
$output->screen()->waitForInput();
|
||||
}
|
||||
|
||||
private function demoDisplay(ConsoleInput $input, ConsoleOutput $output): void
|
||||
{
|
||||
$output->screen()->newScreen(ScreenType::CONTENT);
|
||||
$output->writeLine('=== Bildschirmlöschungs-Demo ===', ConsoleStyle::success());
|
||||
$output->writeLine('');
|
||||
|
||||
// Bildschirm füllen
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$output->writeLine("Zeile $i: Dies ist ein Test");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
$output->writeLine("\nLösche in 3 Sekunden den Bildschirm...");
|
||||
sleep(3);
|
||||
|
||||
// Bildschirm löschen
|
||||
$output->display()->clear();
|
||||
$output->writeLine('Bildschirm wurde gelöscht!');
|
||||
sleep(1);
|
||||
|
||||
// Zeilen hinzufügen
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
$output->writeLine("Neue Zeile $i");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
$output->writeLine("\nLösche nur die aktuelle Zeile in 2 Sekunden...");
|
||||
sleep(2);
|
||||
|
||||
// Zeile löschen
|
||||
$output->display()->clearLine();
|
||||
$output->writeLine('Die Zeile wurde gelöscht und durch diese ersetzt!');
|
||||
|
||||
sleep(1);
|
||||
$output->writeLine("\nDrücken Sie eine Taste, um fortzufahren...");
|
||||
$output->screen()->waitForInput();
|
||||
}
|
||||
|
||||
private function demoProgress(ConsoleInput $input, ConsoleOutput $output): void
|
||||
{
|
||||
$output->screen()->newScreen(ScreenType::PROGRESS);
|
||||
$output->writeLine('=== Fortschrittsanzeige-Demo ===', ConsoleStyle::success());
|
||||
$output->writeLine('');
|
||||
|
||||
$total = 20;
|
||||
|
||||
for ($i = 0; $i <= $total; $i++) {
|
||||
$percent = floor(($i / $total) * 100);
|
||||
$bar = str_repeat('█', $i) . str_repeat('░', $total - $i);
|
||||
|
||||
// Zeile löschen und neue Fortschrittsanzeige
|
||||
$output->display()->clearLine();
|
||||
$output->write("Fortschritt: [{$bar}] {$percent}%");
|
||||
|
||||
usleep(200000); // 200ms pause
|
||||
}
|
||||
|
||||
$output->writeLine("\n\nFortschritt abgeschlossen!");
|
||||
sleep(1);
|
||||
|
||||
$output->writeLine("\nDrücken Sie eine Taste, um fortzufahren...");
|
||||
$output->screen()->waitForInput();
|
||||
}
|
||||
|
||||
private function demoTypeset(ConsoleInput $input, ConsoleOutput $output): void
|
||||
{
|
||||
$output->screen()->newScreen(ScreenType::CONTENT);
|
||||
$output->writeLine('=== Typensatz-Demo ===', ConsoleStyle::success());
|
||||
$output->writeLine('');
|
||||
|
||||
$text = 'Dies ist eine Demonstration des Typensatz-Effekts. Der Text wird Zeichen für Zeichen angezeigt, ' .
|
||||
'als ob er gerade getippt würde. Diese Technik kann für Intros, Tutorials oder ' .
|
||||
'dramatische Effekte verwendet werden.';
|
||||
|
||||
// Typensatz-Effekt
|
||||
foreach (str_split($text) as $char) {
|
||||
$output->write($char);
|
||||
usleep(rand(50000, 150000)); // 50-150ms zufällige Pause
|
||||
}
|
||||
|
||||
$output->writeLine("\n\nTypensatz abgeschlossen!");
|
||||
sleep(1);
|
||||
|
||||
$output->writeLine("\nDrücken Sie eine Taste, um zurückzukehren...");
|
||||
$output->screen()->waitForInput();
|
||||
|
||||
// Zurück zum Hauptmenü
|
||||
$output->screen()->newMenu();
|
||||
$this->__invoke($input, $output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user