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
| 1 | import { countOf } from '../../../count-of' |
| 2 | import Layout from '../../layout' |
| 3 | import type Types from '../types' |
| 4 | import { MAX_HIGHLIGHTS } from './max-highlights' |
| 5 | import { segmentsOf } from './segments-of' |
| 6 | |
| 7 | /** |
| 8 | * Numbered lines laid into terminal rows: a long line wraps onto |
| 9 | * continuation rows with an empty gutter. |
| 10 | * |
| 11 | * Word highlights stop once MAX_HIGHLIGHTS are spent, keeping the tree |
| 12 | * under its node cap. |
| 13 | * |
| 14 | * @param lines the numbered lines |
| 15 | * @param cells the content's room per row after gutter and marker, one at |
| 16 | * least |
| 17 | * @returns the rows in drawing order |
| 18 | */ |
| 19 | export function rowsOf( |
| 20 | lines: readonly Types.DiffLine[], |
| 21 | cells: number, |
| 22 | ): Types.Row[] { |
| 23 | const rows: Types.Row[] = [] |
| 24 | let highlights = 0 |
| 25 | |
| 26 | for (const line of lines) { |
| 27 | const marked = segmentsOf(line) |
| 28 | const wanted = countOf(marked, segment => segment.isChanged) |
| 29 | const isAffordable = highlights + wanted <= MAX_HIGHLIGHTS |
| 30 | highlights += isAffordable ? wanted : 0 |
| 31 | const segments = isAffordable |
| 32 | ? marked |
| 33 | : [{ text: line.text, isChanged: false }] |
| 34 | const marker = |
| 35 | line.kind === 'added' ? '+' : line.kind === 'removed' ? '-' : ' ' |
| 36 | |
| 37 | Layout.wrapSegments(segments, cells).forEach((wrapped, at) => { |
| 38 | rows.push({ |
| 39 | kind: line.kind, |
| 40 | gutter: at === 0 ? String(line.lineNumber) : '', |
| 41 | marker: at === 0 ? marker : ' ', |
| 42 | segments: wrapped, |
| 43 | }) |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | return rows |
| 48 | } |