feat: vendor permission system source

This commit is contained in:
云服务部-叶林立
2026-08-19 14:35:19 +08:00
parent 198584daf8
commit 410c50a3e5
809 changed files with 157793 additions and 139 deletions
@@ -0,0 +1,27 @@
import { truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
/**
* Fit rendered lines to a terminal width, so each returned entry is a single
* visual row no wider than `width`.
*
* Long lines are wrapped rather than clipped so no content is lost; the final
* `truncateToWidth` guards the edge cases `wrapTextWithAnsi` cannot split (a
* lone wide grapheme). A width of zero or less yields no rows.
*
* Shared by the `ctx.ui.custom` dialog — whose contract requires it — and by
* any renderer that must count rows, since a row count is only meaningful
* after wrapping.
*/
export function fitLinesToWidth(
lines: readonly string[],
width: number,
): string[] {
if (width <= 0) {
return [];
}
return lines.flatMap((line) =>
wrapTextWithAnsi(line, width).map((wrapped) =>
truncateToWidth(wrapped, width),
),
);
}