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 / charged-width / charged-width.ts
22 lines · 654 BRaw
1import { cellWidth } from '../cell-width'
2
3/**
4 * The cells a sanitized text is charged when laid into rows and padded:
5 * cellWidth, but a code point drawing in no cell is still charged one.
6 *
7 * The slicer and the band padding both count by this, so a row never
8 * emits more code points than the cells it was given, combining marks or
9 * not.
10 *
11 * @param text a line or segment with no tabs or control characters
12 * @returns its charge in cells, at least one per code point
13 */
14export function chargedWidth(text: string) {
15 let charged = 0
16
17 for (const character of text) {
18 charged += Math.max(1, cellWidth(character))
19 }
20
21 return charged
22}