59c8749ad7
- Replaced ad-hoc ANSI/VT stripping regexes with `stripVTControlCharacters` in status text handling and related tests. - Updated status footer rendering to truncate using `truncateToWidth` and visible width after VT stripping. - Extended tui cursor handling and rendering to strip markers from all lines and fit repaint/append-tail lines to width. - Expanded deterministic render tests with overlay-aware assertions and recorded the truncation/cursor-marker behavior in changelogs.
48 lines
2.8 KiB
TypeScript
48 lines
2.8 KiB
TypeScript
import { stripVTControlCharacters } from "node:util";
|
|
import type { TabBarTheme } from "@oh-my-pi/pi-tui";
|
|
import { theme } from "./theme/theme";
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
// Text Sanitization
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Sanitize text for display in a single-line status. Strips ANSI/VT escape sequences, maps remaining C0/C1 control characters to spaces, collapses whitespace, trims. */
|
|
export function sanitizeStatusText(text: string): string {
|
|
return stripVTControlCharacters(text)
|
|
.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ")
|
|
.replace(/ +/g, " ")
|
|
.trim();
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
// Tab Bar Theme
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Shared tab bar theme used by model-selector and settings-selector. */
|
|
export function getTabBarTheme(): TabBarTheme {
|
|
return {
|
|
label: (text: string) => theme.bold(theme.fg("accent", text)),
|
|
activeTab: (text: string) => theme.bold(theme.bg("selectedBg", theme.fg("text", text))),
|
|
inactiveTab: (text: string) => theme.fg("muted", text),
|
|
hint: (text: string) => theme.fg("dim", text),
|
|
};
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
// Working-message hint
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
/**
|
|
* Suffix appended to the loader's working message to remind users they can
|
|
* abort with Esc. Rendered with the active theme's bracket glyphs so it stays
|
|
* visually consistent with badges and other bracketed UI affordances.
|
|
*
|
|
* The leading space separates the hint from the message body and is consumed
|
|
* by `endsWith`/`slice` matching in the loader renderer.
|
|
*/
|
|
export function interruptHint(): string {
|
|
return ` ${theme.format.bracketLeft}esc${theme.format.bracketRight}`;
|
|
}
|
|
|
|
export { parseCommandArgs } from "../utils/command-args";
|