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.
TypeScript
import { chargedWidth } from '../charged-width'
/**
* A path cut from its start to fit, an ellipsis standing for what went, so
* the file name survives, as the engine truncates a path from its start.
*
* It counts by chargedWidth, a cell at least per code point, so a name
* padded with combining marks is cut like any other and never passes the
* room whole.
*
* @param text the path
* @param cells the room
* @returns the path, or `…` and its tail
*/
export function truncateStart(text: string, cells: number) {
if (chargedWidth(text) <= cells) {
return text
}
const characters = [...text]
let kept = ''
for (let at = characters.length - 1; at >= 0; at--) {
const candidate = `${characters[at]}${kept}`
if (chargedWidth(candidate) + 1 > cells) {
break
}
kept = candidate
}
return `…${kept}`
}