Enhance CLI terminal integration and output handling in InkApp. Introduce terminalService for managing PTY backend, including resizing and updating terminal output. Implement ANSI stripping and tab expansion for accurate line rendering. Improve state management for terminal, logs, and LLM output, ensuring responsive UI updates and error handling during input submission.

This commit is contained in:
sebseb7
2025-08-12 18:34:07 +00:00
parent ac09e4ed08
commit b515275407
4 changed files with 4935 additions and 16 deletions

View File

@@ -3,6 +3,10 @@ import 'dotenv/config';
import React from 'react';
import { render } from 'ink';
import InkApp from './src/ui/InkApp.jsx';
import terminalService from './src/terminalService.js';
// Start the PTY backend independent from UI lifecycle
terminalService.start();
const { unmount } = render(React.createElement(InkApp));
@@ -14,6 +18,7 @@ if (process.stdin.isTTY) {
const exitCleanly = () => {
unmount();
try { terminalService.dispose(); } catch { }
try { process.stdin.setRawMode(false); } catch { }
process.exit(0);
};
@@ -21,6 +26,10 @@ if (process.stdin.isTTY) {
const onData = (data) => {
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(String(data));
for (const byte of buffer) {
// Ctrl-C (ETX)
if (byte === 0x03) {
return exitCleanly();
}
if (!escPending) {
if (byte === 0x1b) { // ESC
escPending = true;
@@ -42,6 +51,10 @@ if (process.stdin.isTTY) {
};
process.stdin.on('data', onData);
// Also handle SIGINT in case raw mode changes or comes from elsewhere
const onSigint = () => exitCleanly();
process.on('SIGINT', onSigint);
}