MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / isCompleteSequence

Function isCompleteSequence

packages/pi-tui/src/stdin-buffer.ts:29–78  ·  view source on GitHub ↗

* Check if a string is a complete escape sequence or needs more data

(data: string)

Source from the content-addressed store, hash-verified

27 * Check if a string is a complete escape sequence or needs more data
28 */
29function isCompleteSequence(data: string): "complete" | "incomplete" | "not-escape" {
30 if (!data.startsWith(ESC)) {
31 return "not-escape";
32 }
33
34 if (data.length === 1) {
35 return "incomplete";
36 }
37
38 const afterEsc = data.slice(1);
39
40 // CSI sequences: ESC [
41 if (afterEsc.startsWith("[")) {
42 // Check for old-style mouse sequence: ESC[M + 3 bytes
43 if (afterEsc.startsWith("[M")) {
44 // Old-style mouse needs ESC[M + 3 bytes = 6 total
45 return data.length >= 6 ? "complete" : "incomplete";
46 }
47 return isCompleteCsiSequence(data);
48 }
49
50 // OSC sequences: ESC ]
51 if (afterEsc.startsWith("]")) {
52 return isCompleteOscSequence(data);
53 }
54
55 // DCS sequences: ESC P ... ESC \ (includes XTVersion responses)
56 if (afterEsc.startsWith("P")) {
57 return isCompleteDcsSequence(data);
58 }
59
60 // APC sequences: ESC _ ... ESC \ (includes Kitty graphics responses)
61 if (afterEsc.startsWith("_")) {
62 return isCompleteApcSequence(data);
63 }
64
65 // SS3 sequences: ESC O
66 if (afterEsc.startsWith("O")) {
67 // ESC O followed by a single character
68 return afterEsc.length >= 2 ? "complete" : "incomplete";
69 }
70
71 // Meta key sequences: ESC followed by a single character
72 if (afterEsc.length === 1) {
73 return "complete";
74 }
75
76 // Unknown escape sequence - treat as complete
77 return "complete";
78}
79
80/**
81 * Check if CSI sequence is complete

Callers 1

extractCompleteSequencesFunction · 0.85

Calls 4

isCompleteCsiSequenceFunction · 0.85
isCompleteOscSequenceFunction · 0.85
isCompleteDcsSequenceFunction · 0.85
isCompleteApcSequenceFunction · 0.85

Tested by

no test coverage detected