import pc from "picocolors"; /** designpaca 의 강조색 — 한 가지만 쓴다 */ export const accent = (s: string) => pc.magenta(s); export const dim = (s: string) => pc.dim(s); export const bold = (s: string) => pc.bold(s); export const ok = (s: string) => `${pc.green("✓")} ${s}`; export const warn = (s: string) => `${pc.yellow("!")} ${s}`; export const bad = (s: string) => `${pc.red("✗")} ${s}`; export const info = (s: string) => `${pc.cyan("·")} ${s}`; /** * 터미널에서 차지하는 칸 수. 한글·한자·가나는 2칸을 먹는다. * String.length 로 padEnd 하면 한글이 섞인 표가 어긋난다. */ export function displayWidth(s: string): number { // ANSI 이스케이프는 폭을 차지하지 않는다 const plain = s.replace(/\[[0-9;]*m/g, ""); let w = 0; for (const ch of plain) { const cp = ch.codePointAt(0) ?? 0; const wide = (cp >= 0x1100 && cp <= 0x115f) || // 한글 자모 (cp >= 0x2e80 && cp <= 0xa4cf) || // CJK 부수 ~ 이 (cp >= 0xac00 && cp <= 0xd7a3) || // 한글 음절 (cp >= 0xf900 && cp <= 0xfaff) || // CJK 호환 (cp >= 0xfe30 && cp <= 0xfe6f) || (cp >= 0xff00 && cp <= 0xff60) || // 전각 (cp >= 0xffe0 && cp <= 0xffe6); w += wide ? 2 : 1; } return w; } /** displayWidth 기준으로 오른쪽을 채운다 */ export function padDisplay(s: string, width: number): string { const pad = width - displayWidth(s); return pad > 0 ? s + " ".repeat(pad) : s; } export function heading(s: string): string { return `\n${bold(s)}\n${dim("─".repeat(Math.min(s.length + 8, 56)))}`; } /** 긴 경로 목록을 접어서 보여준다 — 설치 계획이 화면을 삼키지 않게 */ export function fold(items: string[], max = 6): string[] { if (items.length <= max) return items; return [...items.slice(0, max), dim(`… 그 외 ${items.length - max}개`)]; } export function table(rows: [string, string][]): string { const w = Math.max(...rows.map(([k]) => k.length)); return rows.map(([k, v]) => ` ${k.padEnd(w)} ${dim(v)}`).join("\n"); }