mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-22 05:11:06 -05:00
Process terminal first chunk to be more human readable
This commit is contained in:
@@ -256,26 +256,37 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
|
|||||||
// todo: need to handle errors
|
// todo: need to handle errors
|
||||||
let isFirstChunk = true
|
let isFirstChunk = true
|
||||||
for await (let data of stream) {
|
for await (let data of stream) {
|
||||||
// if (isFirstChunk) {
|
if (isFirstChunk) {
|
||||||
// // https://code.visualstudio.com/docs/terminal/shell-integration#_vs-code-custom-sequences-osc-633-st
|
/*
|
||||||
// const vscodeSequenceRegex = /\x1b\]633;.[^\x07]*\x07/g
|
The first chunk we get from this stream needs to be processed to be more human readable, ie remove vscode's custom escape sequences and identifiers, removing duplicate first char bug, etc.
|
||||||
// data = stripAnsi(data.replace(vscodeSequenceRegex, ""))
|
*/
|
||||||
// // Split data by newlines
|
// https://code.visualstudio.com/docs/terminal/shell-integration#_vs-code-custom-sequences-osc-633-st
|
||||||
// let lines = data.split("\n")
|
const vscodeSequenceRegex = /\x1b\]633;.[^\x07]*\x07/g
|
||||||
// // Remove the first line
|
data = stripAnsi(data.replace(vscodeSequenceRegex, ""))
|
||||||
// // if (lines.length > 0) {
|
// Split data by newlines
|
||||||
// // lines.shift()
|
let lines = data.split("\n")
|
||||||
// // }
|
// Remove non-human readable characters from the first line
|
||||||
// // Process second line: remove everything up to the first alphanumeric character
|
if (lines.length > 0) {
|
||||||
// if (lines.length > 0) {
|
lines[0] = lines[0].replace(/[^\x20-\x7E]/g, "")
|
||||||
// lines[0] = lines[0].replace(/^[^a-zA-Z0-9]*/, "")
|
}
|
||||||
// }
|
// Check if first two characters are the same, if so remove the first character
|
||||||
// // Join lines back
|
if (lines.length > 0 && lines[0].length >= 2 && lines[0][0] === lines[0][1]) {
|
||||||
// data = lines.join("\n")
|
lines[0] = lines[0].slice(1)
|
||||||
// isFirstChunk = false
|
}
|
||||||
// } else {
|
// Process second line: remove everything up to the first alphanumeric character
|
||||||
// data = stripAnsi(data)
|
if (lines.length > 1) {
|
||||||
// }
|
lines[1] = lines[1].replace(/^[^a-zA-Z0-9]*/, "")
|
||||||
|
}
|
||||||
|
// Remove the first line if it matches the command (case-insensitive)
|
||||||
|
if (lines.length > 0 && lines[0].trim().toLowerCase() === command.trim().toLowerCase()) {
|
||||||
|
lines.shift()
|
||||||
|
}
|
||||||
|
// Join lines back
|
||||||
|
data = lines.join("\n")
|
||||||
|
isFirstChunk = false
|
||||||
|
} else {
|
||||||
|
data = stripAnsi(data)
|
||||||
|
}
|
||||||
console.log(`Received data chunk for terminal:`, data)
|
console.log(`Received data chunk for terminal:`, data)
|
||||||
this.fullOutput += data
|
this.fullOutput += data
|
||||||
if (this.isListening) {
|
if (this.isListening) {
|
||||||
@@ -319,7 +330,7 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
|
|||||||
this.buffer += chunk
|
this.buffer += chunk
|
||||||
let lineEndIndex: number
|
let lineEndIndex: number
|
||||||
while ((lineEndIndex = this.buffer.indexOf("\n")) !== -1) {
|
while ((lineEndIndex = this.buffer.indexOf("\n")) !== -1) {
|
||||||
let line = this.buffer.slice(0, lineEndIndex).trim()
|
let line = this.buffer.slice(0, lineEndIndex).trim() // removes trailing \r
|
||||||
// Remove \r if present (for Windows-style line endings)
|
// Remove \r if present (for Windows-style line endings)
|
||||||
// if (line.endsWith("\r")) {
|
// if (line.endsWith("\r")) {
|
||||||
// line = line.slice(0, -1)
|
// line = line.slice(0, -1)
|
||||||
|
|||||||
Reference in New Issue
Block a user