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