- 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
170 lines
5.9 KiB
PHP
170 lines
5.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Framework\Console\Components;
|
|
|
|
use App\Framework\Console\CommandGroupRegistry;
|
|
use App\Framework\Console\CommandHistory;
|
|
use App\Framework\Console\Components\ConsoleTUI;
|
|
use App\Framework\Console\Components\TuiCommandExecutor;
|
|
use App\Framework\Console\Components\TuiRenderer;
|
|
use App\Framework\Console\Components\TuiState;
|
|
use App\Framework\Console\ConsoleOutput;
|
|
use App\Framework\Console\SimpleWorkflowExecutor;
|
|
use App\Framework\DI\DefaultContainer;
|
|
use App\Framework\Discovery\Results\AttributeRegistry;
|
|
use App\Framework\Discovery\Results\DiscoveryRegistry;
|
|
use App\Framework\Discovery\Results\InterfaceRegistry;
|
|
use App\Framework\Discovery\Results\TemplateRegistry;
|
|
|
|
describe('ConsoleTUI', function () {
|
|
beforeEach(function () {
|
|
$this->container = new DefaultContainer();
|
|
$this->output = new ConsoleOutput();
|
|
$this->discoveryRegistry = new DiscoveryRegistry(
|
|
attributes: new AttributeRegistry(),
|
|
interfaces: new InterfaceRegistry([]),
|
|
templates: new TemplateRegistry([])
|
|
);
|
|
$this->state = new TuiState();
|
|
$this->renderer = new TuiRenderer($this->output, $this->state);
|
|
$this->commandExecutor = new TuiCommandExecutor(
|
|
new \App\Framework\Console\CommandRegistry($this->container, $this->discoveryRegistry),
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
new CommandHistory(),
|
|
new \App\Framework\Console\CommandValidator(),
|
|
new \App\Framework\Console\CommandHelpGenerator(new \App\Framework\Console\ParameterInspector()),
|
|
'test-console'
|
|
);
|
|
$this->commandHistory = new CommandHistory();
|
|
$this->groupRegistry = new CommandGroupRegistry($this->discoveryRegistry);
|
|
$this->workflowExecutor = new SimpleWorkflowExecutor($this->container, $this->discoveryRegistry);
|
|
});
|
|
|
|
it('can be instantiated', function () {
|
|
$tui = new ConsoleTUI(
|
|
$this->output,
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
$this->state,
|
|
$this->renderer,
|
|
$this->commandExecutor,
|
|
$this->commandHistory,
|
|
$this->groupRegistry,
|
|
$this->workflowExecutor
|
|
);
|
|
|
|
expect($tui)->toBeInstanceOf(ConsoleTUI::class);
|
|
});
|
|
|
|
it('has run method', function () {
|
|
$tui = new ConsoleTUI(
|
|
$this->output,
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
$this->state,
|
|
$this->renderer,
|
|
$this->commandExecutor,
|
|
$this->commandHistory,
|
|
$this->groupRegistry,
|
|
$this->workflowExecutor
|
|
);
|
|
|
|
expect(method_exists($tui, 'run'))->toBeTrue();
|
|
});
|
|
|
|
it('has handleShutdownSignal method', function () {
|
|
$tui = new ConsoleTUI(
|
|
$this->output,
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
$this->state,
|
|
$this->renderer,
|
|
$this->commandExecutor,
|
|
$this->commandHistory,
|
|
$this->groupRegistry,
|
|
$this->workflowExecutor
|
|
);
|
|
|
|
expect(method_exists($tui, 'handleShutdownSignal'))->toBeTrue();
|
|
});
|
|
|
|
it('has handleShutdownSignalLegacy method', function () {
|
|
$tui = new ConsoleTUI(
|
|
$this->output,
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
$this->state,
|
|
$this->renderer,
|
|
$this->commandExecutor,
|
|
$this->commandHistory,
|
|
$this->groupRegistry,
|
|
$this->workflowExecutor
|
|
);
|
|
|
|
expect(method_exists($tui, 'handleShutdownSignalLegacy'))->toBeTrue();
|
|
});
|
|
|
|
it('initializes with all required dependencies', function () {
|
|
$tui = new ConsoleTUI(
|
|
$this->output,
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
$this->state,
|
|
$this->renderer,
|
|
$this->commandExecutor,
|
|
$this->commandHistory,
|
|
$this->groupRegistry,
|
|
$this->workflowExecutor
|
|
);
|
|
|
|
expect($tui)->toBeInstanceOf(ConsoleTUI::class);
|
|
});
|
|
});
|
|
|
|
describe('ConsoleTUI Terminal Compatibility', function () {
|
|
beforeEach(function () {
|
|
$this->container = new DefaultContainer();
|
|
$this->output = new ConsoleOutput();
|
|
$this->discoveryRegistry = new DiscoveryRegistry(
|
|
attributes: new AttributeRegistry(),
|
|
interfaces: new InterfaceRegistry([]),
|
|
templates: new TemplateRegistry([])
|
|
);
|
|
$this->state = new TuiState();
|
|
$this->renderer = new TuiRenderer($this->output, $this->state);
|
|
$this->commandExecutor = new TuiCommandExecutor(
|
|
new \App\Framework\Console\CommandRegistry($this->container, $this->discoveryRegistry),
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
new CommandHistory(),
|
|
new \App\Framework\Console\CommandValidator(),
|
|
new \App\Framework\Console\CommandHelpGenerator(new \App\Framework\Console\ParameterInspector()),
|
|
'test-console'
|
|
);
|
|
$this->commandHistory = new CommandHistory();
|
|
$this->groupRegistry = new CommandGroupRegistry($this->discoveryRegistry);
|
|
$this->workflowExecutor = new SimpleWorkflowExecutor($this->container, $this->discoveryRegistry);
|
|
});
|
|
|
|
it('handles terminal compatibility check', function () {
|
|
$tui = new ConsoleTUI(
|
|
$this->output,
|
|
$this->container,
|
|
$this->discoveryRegistry,
|
|
$this->state,
|
|
$this->renderer,
|
|
$this->commandExecutor,
|
|
$this->commandHistory,
|
|
$this->groupRegistry,
|
|
$this->workflowExecutor
|
|
);
|
|
|
|
// TUI should handle terminal compatibility internally
|
|
expect($tui)->toBeInstanceOf(ConsoleTUI::class);
|
|
});
|
|
});
|
|
|