Add 5 pi extensions: pi-subagents, pi-crew, rpiv-pi, pi-interactive-shell, pi-intercom
This commit is contained in:
33
extensions/pi-interactive-shell/pty-protocol.ts
Normal file
33
extensions/pi-interactive-shell/pty-protocol.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
// DSR (Device Status Report) - cursor position query: ESC[6n or ESC[?6n
|
||||
const DSR_PATTERN = /\x1b\[\??6n/g;
|
||||
|
||||
/** Result of splitting PTY output around device-status-report cursor queries. */
|
||||
export interface DsrSplit {
|
||||
segments: Array<{ text: string; dsrAfter: boolean }>;
|
||||
hasDsr: boolean;
|
||||
}
|
||||
|
||||
export function splitAroundDsr(input: string): DsrSplit {
|
||||
const segments: Array<{ text: string; dsrAfter: boolean }> = [];
|
||||
let lastIndex = 0;
|
||||
let hasDsr = false;
|
||||
const regex = new RegExp(DSR_PATTERN.source, "g");
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = regex.exec(input)) !== null) {
|
||||
hasDsr = true;
|
||||
if (match.index > lastIndex) {
|
||||
segments.push({ text: input.slice(lastIndex, match.index), dsrAfter: true });
|
||||
} else {
|
||||
segments.push({ text: "", dsrAfter: true });
|
||||
}
|
||||
lastIndex = match.index + match[0].length;
|
||||
}
|
||||
if (lastIndex < input.length) {
|
||||
segments.push({ text: input.slice(lastIndex), dsrAfter: false });
|
||||
}
|
||||
return { segments, hasDsr };
|
||||
}
|
||||
|
||||
export function buildCursorPositionResponse(row = 1, col = 1): string {
|
||||
return `\x1b[${row};${col}R`;
|
||||
}
|
||||
Reference in New Issue
Block a user