(command: string)
| 112 | } |
| 113 | |
| 114 | private async executeCommand(command: string): Promise<void> { |
| 115 | const trimmed = command.trim(); |
| 116 | |
| 117 | // Skip empty commands |
| 118 | if (!trimmed) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | // Add to history |
| 123 | this.history.push(trimmed); |
| 124 | |
| 125 | // Handle shell built-ins that need special treatment |
| 126 | if (trimmed === "exit" || trimmed.startsWith("exit ")) { |
| 127 | const parts = trimmed.split(/\s+/); |
| 128 | const exitCode = parts[1] ? parseInt(parts[1], 10) : 0; |
| 129 | console.log("exit"); |
| 130 | process.exit(exitCode); |
| 131 | } |
| 132 | |
| 133 | // Sync local history with Bash's history for the history command |
| 134 | this.syncHistory(); |
| 135 | |
| 136 | // Execute command in Bash |
| 137 | try { |
| 138 | const result = await this.env.exec(trimmed); |
| 139 | |
| 140 | if (result.stdout) { |
| 141 | process.stdout.write(result.stdout); |
| 142 | } |
| 143 | |
| 144 | if (result.stderr) { |
| 145 | process.stderr.write(`${colors.red}${result.stderr}${colors.reset}`); |
| 146 | } |
| 147 | } catch (error) { |
| 148 | console.error( |
| 149 | `${colors.red}Error: ${getErrorMessage(error)}${colors.reset}`, |
| 150 | ); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | private printWelcome(): void { |
| 155 | console.log(` |
no test coverage detected