capturedWrites[] = ['message' => $message, 'style' => $style]; } public function writeLine(string $message = '', ?ConsoleColor $color = null): void { $this->capturedLines[] = ['message' => $message, 'color' => $color]; } public function writeError(string $message): void { $this->capturedErrors[] = $message; $this->capturedLines[] = ['message' => $message, 'type' => 'error']; } public function writeSuccess(string $message): void { $this->capturedSuccesses[] = $message; $this->capturedLines[] = ['message' => $message, 'type' => 'success']; } public function writeWarning(string $message): void { $this->capturedWarnings[] = $message; $this->capturedLines[] = ['message' => $message, 'type' => 'warning']; } public function writeInfo(string $message): void { $this->capturedInfos[] = $message; $this->capturedLines[] = ['message' => $message, 'type' => 'info']; } public function newLine(int $count = 1): void { $this->newLineCount += $count; for ($i = 0; $i < $count; $i++) { $this->capturedLines[] = ['message' => '', 'type' => 'newline']; } } public function askQuestion(string $question, ?string $default = null): string { $this->capturedLines[] = ['message' => $question, 'type' => 'question', 'default' => $default]; return $default ?? ''; } public function confirm(string $question, bool $default = false): bool { $this->capturedLines[] = ['message' => $question, 'type' => 'confirm', 'default' => $default]; return $default; } public function writeWindowTitle(string $title, int $mode = 0): void { $this->windowTitles[] = ['title' => $title, 'mode' => $mode]; } /** * Get all captured output as plain text */ public function getOutput(): string { $output = []; foreach ($this->capturedLines as $line) { $output[] = $line['message'] ?? ''; } return implode("\n", $output); } /** * Get all captured writes */ public function getWrites(): array { return $this->capturedWrites; } /** * Clear all captured output */ public function clear(): void { $this->capturedLines = []; $this->capturedWrites = []; $this->capturedErrors = []; $this->capturedSuccesses = []; $this->capturedWarnings = []; $this->capturedInfos = []; $this->newLineCount = 0; $this->windowTitles = []; } /** * Check if output contains a specific string */ public function contains(string $search): bool { $output = $this->getOutput(); return str_contains($output, $search); } /** * Get last captured line */ public function getLastLine(): ?string { if (empty($this->capturedLines)) { return null; } $last = end($this->capturedLines); return $last['message'] ?? null; } }