spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / views / layout / truncate-start / truncate-start.ts
35 lines · 857 BRaw
1import { chargedWidth } from '../charged-width'
2
3/**
4 * A path cut from its start to fit, an ellipsis standing for what went, so
5 * the file name survives, as the engine truncates a path from its start.
6 *
7 * It counts by chargedWidth, a cell at least per code point, so a name
8 * padded with combining marks is cut like any other and never passes the
9 * room whole.
10 *
11 * @param text the path
12 * @param cells the room
13 * @returns the path, or `…` and its tail
14 */
15export function truncateStart(text: string, cells: number) {
16 if (chargedWidth(text) <= cells) {
17 return text
18 }
19
20 const characters = [...text]
21
22 let kept = ''
23
24 for (let at = characters.length - 1; at >= 0; at--) {
25 const candidate = `${characters[at]}${kept}`
26
27 if (chargedWidth(candidate) + 1 > cells) {
28 break
29 }
30
31 kept = candidate
32 }
33
34 return `…${kept}`
35}