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:
13
cli-ink.js
13
cli-ink.js
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user