import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui"; export function pluralize(count: number, singular: string, plural = `${singular}s`): string { return count === 1 ? singular : plural; } export function splitWriteContentLines(content: string): string[] { if (!content) { return []; } const normalized = content.replace(/\r/g, ""); const lines = normalized.split("\n"); if (lines.length > 0 && lines[lines.length - 1] === "") { lines.pop(); } return lines; } export function normalizeCodeWhitespace(text: string): string { return text.replace(/\t/g, " "); } export function fitToWidth(text: string, width: number): string { const trimmed = truncateToWidth(text, width, ""); const gap = Math.max(0, width - visibleWidth(trimmed)); return gap > 0 ? `${trimmed}${" ".repeat(gap)}` : trimmed; } export function wrapToWidth(text: string, width: number, wordWrap: boolean): string[] { if (width <= 0) { return [""]; } if (!wordWrap) { return [fitToWidth(text, width)]; } const wrapped = wrapTextWithAnsi(text, width); if (wrapped.length === 0) { return [fitToWidth("", width)]; } return wrapped.map((line) => fitToWidth(line, width)); }