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 / file-row / file-row.tsx
49 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 { diffStat } from '../diff-stat'
9import type { FileRowModel } from '../file-row-model'
10import { POINTER } from '../pointer'
11import { STAT_CELLS } from '../stat-cells'
12
13/**
14 * One file of the list (ReplDiffSidebar FileSummaryRow): a plain Button
15 * with the start-truncated path, its counts or note at the right.
16 *
17 * The pointer marks the selected one.
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 fileRow(
25 kit: Kit,
26 row: FileRowModel,
27 onPress: () => void,
28): RenderElement {
29 const { Box, Text, Button } = kit.ui
30 const room = Math.max(kit.columns - STAT_CELLS, STAT_CELLS)
31 const mark = row.isSelected ? POINTER : ' '
32 const note = (
33 <Text dimColor italic>
34 {row.note ?? ''}
35 </Text>
36 )
37 const hasNote = row.note !== null
38 const tail = hasNote ? note : diffStat(kit, row.added, row.removed)
39
40 return (
41 <Box flexDirection="row">
42 <Button key={row.key} plain onPress={onPress}>
43 {`${mark} ${Layout.truncateStart(Layout.sanitizeName(row.path), room)}`}
44 </Button>
45 <Box flexGrow={1} />
46 {tail}
47 </Box>
48 )
49}