MCPcopy Create free account
hub / github.com/Marus/cortex-debug / handleOtherChars

Method handleOtherChars

src/frontend/pty.ts:211–256  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

209 **
210 */
211 private handleOtherChars(str: string) {
212 // We are only expecting COOKED mode here. Everything else should have already been handled
213 const lines = str.split(/\r\n|\r|\n/);
214 if (lines.length > 1) {
215 if (this.promptTimer) {
216 this.promptTimer.kill();
217 this.promptTimer = null;
218 }
219 // The last line decides if there will be a prompt or not. Otherwise, no prompt
220 // emitted until all the lines are consumed
221 this.didPrompt = false;
222 this.suspendPrompting = true;
223 }
224 for (let ix = 0; ix < lines.length; ix++ ) {
225 const line = lines[ix];
226 const isLastLine = (ix === (lines.length - 1));
227 if ((line === '') && isLastLine) {
228 // Last line will be empty if the input string ended with a newline
229 this.suspendPrompting = false;
230 this.doPrompt();
231 break;
232 }
233 let tail = this.curLine.slice(this.cursorPos - 1);
234 this.curLine = PtyTerminal.insertCharsAt(this.curLine, line, this.cursorPos - 1);
235 this.writeEmitter.fire(ACTIONS.killLineForward());
236 if (!isLastLine) {
237 this.writeEmitter.fire(line);
238 this.cursorPos += line.length;
239 this.curLine = (tail.length > 0) ? this.curLine.slice(0, -tail.length) : this.curLine;
240 this.handleReturn(KEYS.enter);
241 if (tail.length > 0) {
242 // We carry the tail with us to the next line but cursor position does not change
243 // Which at this point should be at the beginning of the next line.
244 this.writeEmitter.fire(tail + ACTIONS.cursorBack(tail.length));
245 this.curLine = tail;
246 }
247 } else {
248 tail = this.curLine.slice(this.cursorPos - 1);
249 this.writeEmitter.fire(tail);
250 const count = tail.length - line.length;
251 this.writeEmitter.fire(ACTIONS.cursorBack(count));
252 this.cursorPos += line.length;
253 }
254 }
255 this.suspendPrompting = false;
256 }
257
258 /*
259 ** Handle character key sequences. Most terminals are variations of xterm which in turn

Callers 1

handleInputMethod · 0.95

Calls 7

doPromptMethod · 0.95
handleReturnMethod · 0.95
insertCharsAtMethod · 0.80
fireMethod · 0.80
killLineForwardMethod · 0.80
cursorBackMethod · 0.80
killMethod · 0.45

Tested by

no test coverage detected