UNPKG

capsule-ai-cli

Version:

The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing

70 lines 2.25 kB
import stripAnsi from 'strip-ansi'; import wrapAnsi from 'wrap-ansi'; import cliTruncate from 'cli-truncate'; export class TextProcessor { static stripAnsi(str) { return stripAnsi(str); } static getVisibleLength(str) { return stripAnsi(str).length; } static wrapText(text, maxWidth, options) { const defaults = { hard: false, wordWrap: true, trim: true }; const opts = { ...defaults, ...options }; if (!text || maxWidth <= 0) { return []; } const wrapped = wrapAnsi(text, maxWidth, opts); return wrapped.split('\n'); } static truncate(text, maxWidth, options) { return cliTruncate(text, maxWidth, options); } static wrapWithIndent(text, maxWidth, indent) { const indentLength = this.getVisibleLength(indent); const contentWidth = maxWidth - indentLength; if (contentWidth <= 0) { return []; } const lines = this.wrapText(text, contentWidth); return lines.map((line, index) => { return index === 0 ? line : indent + line; }); } static wrapMultilineText(text, maxWidth) { const lines = text.split('\n'); const wrappedLines = []; for (const line of lines) { if (line === '') { wrappedLines.push(''); } else { const wrapped = this.wrapText(line, maxWidth); wrappedLines.push(...wrapped); } } return wrappedLines; } static fitText(text, maxWidth) { const visibleLength = this.getVisibleLength(text); if (visibleLength <= maxWidth) { return text; } return this.truncate(text, maxWidth); } static calculateWrappedHeight(text, maxWidth) { if (!text || maxWidth <= 0) { return 0; } const wrapped = this.wrapText(text, maxWidth); return wrapped.length; } } export const stripAnsiCompat = TextProcessor.stripAnsi; export const wrapTextCompat = TextProcessor.wrapText; export const truncateCompat = TextProcessor.truncate; //# sourceMappingURL=text-processor.js.map