ui: share truncate and firstLine from text.ts

This commit is contained in:
Callum Alpass committed 2026-11-02 22:29:31 +11:00
1 parent 12e1e0ba7a
commit a6cfb9a2cd
8 files changed
+47 -30

No files matched your search

+1 -5
View File
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
import { MAX_DETAIL_FILES, type DetailsAction, type ThreadDetails } from "../model/details.ts";
import { ClickRow } from "./Button.tsx";
import { truncate } from "./text.ts";
import { colors, statusColor } from "./theme.ts";
/** Rows stay readable when the panel takes the conversation's place on a narrow terminal. */
@@ -214,11 +215,6 @@ function countsText(insertions: number, deletions: number): string {
return [insertions > 0 ? `+${insertions}` : "", deletions > 0 ? `−${deletions}` : ""].filter(Boolean).join(" ");
}
function truncate(text: string, width: number): string {
const single = text.replace(/\s+/g, " ");
return single.length > width ? `${single.slice(0, Math.max(0, width - 1))}…` : single;
}
/** Keeps the end of a path, where the file name is, as the web's StartTruncatedPath does. */
function startTruncate(text: string, width: number): string {
return text.length > width ? `…${text.slice(text.length - width + 1)}` : text;