First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import stripAnsi from "strip-ansi";
import sliceAnsi from "slice-ansi";
export function splitAnsiToLines(text, width, maxRoundToWords = Math.min(16, width)) {
if (text == null || text === "")
return [];
const lines = [];
const linesWithoutAnsi = stripAnsi(text).split("\n");
let textIndex = 0;
for (const line of linesWithoutAnsi) {
for (let lineIndex = 0; lineIndex < line.length;) {
let currentWidth = width;
if (maxRoundToWords > 0) {
const currentMaxWidth = Math.min(currentWidth, line.length - lineIndex);
const currentChunkLastChar = line[lineIndex + currentMaxWidth - 1];
const nextChunkFirstChar = line[lineIndex + currentMaxWidth] ?? "";
if (currentChunkLastChar !== " " && nextChunkFirstChar !== "" && nextChunkFirstChar !== " ") {
const lastSpaceIndex = line.lastIndexOf(" ", lineIndex + currentMaxWidth - 1);
if (lastSpaceIndex >= 0) {
const diff = currentMaxWidth - (lastSpaceIndex + " ".length);
if (diff > 0 && diff < maxRoundToWords && diff < currentWidth)
currentWidth -= diff;
}
}
}
lines.push(sliceAnsi(text, textIndex + lineIndex, Math.min(textIndex + lineIndex + currentWidth, textIndex + line.length)));
lineIndex += currentWidth;
}
textIndex += line.length + "\n".length;
}
return lines;
}
//# sourceMappingURL=splitAnsiToLines.js.map