mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 08:59:40 +02:00
fix(screen): send text and Enter key as separate commands
Claude CLI (Ink) doesn't process carriage return correctly when sent together with text via screen -X stuff. Splitting into two separate commands works reliably: 1. screen -X stuff "text" 2. screen -X stuff "$(printf '\015')" Also adds writeViaScreen() method to Session for programmatic input that bypasses PTY and uses screen -X stuff directly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+11
-13
@@ -468,28 +468,26 @@ export class ScreenManager extends EventEmitter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Split input into text and control characters
|
// Split input into text and control characters
|
||||||
// Use printf to generate control characters (octal \015 = carriage return)
|
// IMPORTANT: Must send text and carriage return as SEPARATE commands
|
||||||
// This is more reliable than bash $'...' escaping for Ink/Claude CLI
|
// Sending them together doesn't work with Ink/Claude CLI
|
||||||
const hasCarriageReturn = input.includes('\r');
|
const hasCarriageReturn = input.includes('\r');
|
||||||
const textPart = input.replace(/\r/g, '').replace(/\n/g, '');
|
const textPart = input.replace(/\r/g, '').replace(/\n/g, '');
|
||||||
|
|
||||||
// Escape the text part for shell (double quotes)
|
// Escape the text part for shell (double quotes)
|
||||||
const escapedText = textPart.replace(/"/g, '\\"').replace(/\$/g, '\\$').replace(/`/g, '\\`');
|
const escapedText = textPart.replace(/"/g, '\\"').replace(/\$/g, '\\$').replace(/`/g, '\\`');
|
||||||
|
|
||||||
// Build command: send text, then carriage return via printf
|
// Send text first (if any)
|
||||||
let cmd: string;
|
if (escapedText) {
|
||||||
|
const textCmd = `screen -S ${screen.screenName} -p 0 -X stuff "${escapedText}"`;
|
||||||
|
execSync(textCmd, { encoding: 'utf-8', timeout: 5000 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send carriage return separately (Enter key for Ink)
|
||||||
if (hasCarriageReturn) {
|
if (hasCarriageReturn) {
|
||||||
// Send text + carriage return (Enter key for Ink)
|
const crCmd = `screen -S ${screen.screenName} -p 0 -X stuff "$(printf '\\015')"`;
|
||||||
cmd = `screen -S ${screen.screenName} -p 0 -X stuff "$(printf '${escapedText}\\015')"`;
|
execSync(crCmd, { encoding: 'utf-8', timeout: 5000 });
|
||||||
} else {
|
|
||||||
// Just send text without Enter
|
|
||||||
cmd = `screen -S ${screen.screenName} -p 0 -X stuff "${escapedText}"`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
execSync(cmd, {
|
|
||||||
encoding: 'utf-8',
|
|
||||||
timeout: 5000
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[ScreenManager] Failed to send input:', err);
|
console.error('[ScreenManager] Failed to send input:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user