fix: calc log lines

This commit is contained in:
jialin
2025-01-10 15:41:01 +08:00
parent 5d903de2a2
commit 8282f48cdb
5 changed files with 47 additions and 36 deletions
+11 -6
View File
@@ -23,8 +23,7 @@ const parseAnsi = (input: string, setId: () => number) => {
let cursorCol = 0;
let screen = [['']];
let lastIndex = 0;
// let input = inputStr.replace(replaceLineRegex, '\n');
let rawDataRows = 1;
// handle the \r and \n characters in the text
const handleText = (text: string) => {
@@ -33,6 +32,7 @@ const parseAnsi = (input: string, setId: () => number) => {
if (char === '\r') {
cursorCol = 0; // move to the beginning of the line
} else if (char === '\n') {
rawDataRows++;
cursorRow++; // move to the next line
cursorCol = 0; // move to the beginning of the line
screen[cursorRow] = screen[cursorRow] || ['']; // create a new line if it does not exist
@@ -138,20 +138,25 @@ const parseAnsi = (input: string, setId: () => number) => {
uid: setId()
});
return result;
return {
data: result,
lines: rawDataRows
};
};
self.onmessage = function (event) {
const { inputStr } = event.data;
const parsedData = Array.from(parseAnsi(inputStr, setId));
const { data: parsedData, lines } = parseAnsi(inputStr, setId);
const result = parsedData.map((item) => ({
content: item.content,
uid: item.uid
}));
console.log('result===', result);
self.postMessage(result);
self.postMessage({
result,
lines
});
};
self.onerror = function (event) {