- Fix Enter key detection: handle multiple Enter key formats (\n, \r, \r\n) - Reduce flickering: lower render frequency from 60 FPS to 30 FPS - Fix menu bar visibility: re-render menu bar after content to prevent overwriting - Fix content positioning: explicit line positioning for categories and commands - Fix line shifting: clear lines before writing, control newlines manually - Limit visible items: prevent overflow with maxVisibleCategories/Commands - Improve CPU usage: increase sleep interval when no events processed This fixes: - Enter key not working for selection - Strong flickering of the application - Menu bar not visible or being overwritten - Top half of selection list not displayed - Lines being shifted/misaligned
209 lines
6.4 KiB
PHP
209 lines
6.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Framework\Console;
|
|
|
|
use App\Framework\Console\ConsoleColor;
|
|
use App\Framework\Console\ConsoleOutput;
|
|
use App\Framework\Console\ConsoleStyle;
|
|
|
|
describe('ConsoleOutput', function () {
|
|
it('can be instantiated', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect($output)->toBeInstanceOf(ConsoleOutput::class);
|
|
});
|
|
|
|
it('provides cursor, display, and screen managers', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect($output->cursor)->toBeInstanceOf(\App\Framework\Console\Screen\Cursor::class);
|
|
expect($output->display)->toBeInstanceOf(\App\Framework\Console\Screen\Display::class);
|
|
expect($output->screen)->toBeInstanceOf(\App\Framework\Console\Screen\ScreenManager::class);
|
|
});
|
|
|
|
it('provides terminal capabilities', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect($output->getCapabilities())->toBeInstanceOf(\App\Framework\Console\Terminal\TerminalCapabilities::class);
|
|
expect($output->isTerminal())->toBeBool();
|
|
});
|
|
|
|
it('provides ANSI generator and link formatter', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect($output->getAnsiGenerator())->toBeInstanceOf(\App\Framework\Console\Ansi\AnsiSequenceGenerator::class);
|
|
expect($output->getLinkFormatter())->toBeInstanceOf(\App\Framework\Console\Ansi\LinkFormatter::class);
|
|
});
|
|
|
|
it('provides window title manager', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect($output->getTitleManager())->toBeInstanceOf(\App\Framework\Console\Terminal\WindowTitleManager::class);
|
|
});
|
|
|
|
it('provides animation manager', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect($output->getAnimationManager())->toBeInstanceOf(\App\Framework\Console\Animation\AnimationManager::class);
|
|
});
|
|
});
|
|
|
|
describe('ConsoleOutput Write Methods', function () {
|
|
it('writes text without style', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->write('Hello World');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Hello World');
|
|
});
|
|
|
|
it('writes text with ConsoleColor', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->write('Error', ConsoleColor::RED);
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Error');
|
|
});
|
|
|
|
it('writes line with newline', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->writeLine('Test Line');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Test Line');
|
|
});
|
|
|
|
it('writes success message', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->writeSuccess('Operation successful');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Operation successful');
|
|
});
|
|
|
|
it('writes error message', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->writeError('Operation failed');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Operation failed');
|
|
});
|
|
|
|
it('writes warning message', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->writeWarning('Warning message');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Warning message');
|
|
});
|
|
|
|
it('writes info message', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->writeInfo('Info message');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Info message');
|
|
});
|
|
|
|
it('writes error line to stderr', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->writeErrorLine('Error to stderr');
|
|
$content = ob_get_clean();
|
|
|
|
expect($content)->toContain('Error to stderr');
|
|
});
|
|
|
|
it('adds newlines', function () {
|
|
$output = new ConsoleOutput();
|
|
ob_start();
|
|
$output->newLine(3);
|
|
$content = ob_get_clean();
|
|
|
|
// Should contain newlines
|
|
expect($content)->toContain("\n");
|
|
});
|
|
|
|
it('sets window title', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
// Should not throw
|
|
$output->writeWindowTitle('Test Title');
|
|
expect(true)->toBeTrue(); // Just verify it doesn't throw
|
|
});
|
|
|
|
it('sets window title with different modes', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
// Test different modes
|
|
$output->writeWindowTitle('Title 1', 0);
|
|
$output->writeWindowTitle('Title 2', 1);
|
|
$output->writeWindowTitle('Title 3', 2);
|
|
|
|
expect(true)->toBeTrue(); // Just verify it doesn't throw
|
|
});
|
|
});
|
|
|
|
describe('ConsoleOutput Interactive Methods', function () {
|
|
it('delegates askQuestion to InteractivePrompter', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
// In a real test, we'd mock the prompter, but for now we just verify the method exists
|
|
expect(method_exists($output, 'askQuestion'))->toBeTrue();
|
|
});
|
|
|
|
it('delegates confirm to InteractivePrompter', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'confirm'))->toBeTrue();
|
|
});
|
|
});
|
|
|
|
describe('ConsoleOutput Animation Methods', function () {
|
|
it('has animateFadeIn method', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'animateFadeIn'))->toBeTrue();
|
|
});
|
|
|
|
it('has animateFadeOut method', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'animateFadeOut'))->toBeTrue();
|
|
});
|
|
|
|
it('has animateTypewriter method', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'animateTypewriter'))->toBeTrue();
|
|
});
|
|
|
|
it('has animateMarquee method', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'animateMarquee'))->toBeTrue();
|
|
});
|
|
|
|
it('has animateText method for custom animations', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'animateText'))->toBeTrue();
|
|
});
|
|
|
|
it('has updateAnimations method', function () {
|
|
$output = new ConsoleOutput();
|
|
|
|
expect(method_exists($output, 'updateAnimations'))->toBeTrue();
|
|
});
|
|
});
|
|
|