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 / sections / dialog-file-row / dialog-file-row.tsx
58 lines · 1.4 KBRaw
1/* @jsxRuntime classic */
2/* @jsx h */
3/* @jsxFrag Fragment */
4import type { RenderElement } from 'claude-code'
5
6import Limits from '../../../limits'
7import type { Kit } from '../../kit'
8import Layout from '../../layout'
9import { diffStat } from '../diff-stat'
10import type { FileRowModel } from '../file-row-model'
11import { listRow } from '../list-row'
12import { POINTER } from '../pointer'
13
14/**
15 * One file of the inline list (DiffFileList FileItem): the pointer before
16 * the selected one, where the focus ring starts, the name, counts or note.
17 *
18 * @param kit the elements, the handlers, the width
19 * @param row the file
20 * @param onPress selects the file
21 * @returns the row element
22 */
23export function dialogFileRow(
24 kit: Kit,
25 row: FileRowModel,
26 onPress: () => void,
27): RenderElement {
28 const { Text } = kit.ui
29
30 const room = Math.max(
31 Limits.DIALOG_PATH_FLOOR,
32 kit.columns - Limits.DIALOG_PATH_RESERVE,
33 )
34
35 const mark = row.isSelected ? POINTER : ' '
36 const name = Layout.truncateStart(Layout.sanitizeName(row.displayPath), room)
37
38 const note = (
39 <Text dimColor italic>
40 {row.note ?? ''}
41 </Text>
42 )
43
44 const hasNote = row.note !== null
45 const tail = hasNote ? note : diffStat(kit, row.added, row.removed)
46
47 return listRow(
48 kit,
49 {
50 key: row.key,
51 label: `${mark} ${name}`,
52 onPress,
53 isDim: false,
54 isAutoFocus: row.isSelected,
55 },
56 tail,
57 )
58}