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 / body / list-block-of.tsx
89 lines · 2.6 KBRaw
1/* @jsxRuntime classic */
2/* @jsx h */
3/* @jsxFrag Fragment */
4import type { RenderElement } from 'claude-code'
5
6import { keptOf } from '../../kept-of'
7import Names from '../../names'
8import type PaneState from '../../pane-state'
9import type Entries from '../entries'
10import type { Kit } from '../kit'
11import Layout from '../layout'
12import Sections from '../sections'
13import Plan from './plan'
14import type { DockPlan } from './types'
15
16/**
17 * The docked list block (ReplDiffSidebar's summary rows): the window's rows
18 * between its edge rows, the untracked note, the noise toggle.
19 *
20 * The edge rows count the files out of the window and take the built-in's
21 * list keys; files past the row cap join the lower one. Empty with no row
22 * and no noise to toggle.
23 *
24 * @param kit the elements, the handlers, the width
25 * @param model the pane's state
26 * @param plan the docked pane's decisions over that state
27 * @returns the block's rows
28 */
29export function listBlockOf(
30 kit: Kit,
31 model: PaneState.PaneModel,
32 plan: DockPlan,
33): RenderElement[] {
34 const { shown, above, below } = Plan.listWindowOf(model, plan)
35 const { noiseCount } = plan.partition
36 const { notShown } = plan.totals
37 const hasNoise = !plan.turn && noiseCount > 0
38 const hasMoreAbove = above > 0
39 const hasMoreBelow = below > 0
40 const hasNotShown = notShown > 0
41 const noiseFace = model.isNoiseShown ? 'hide' : 'show'
42
43 const lower = keptOf([
44 hasMoreBelow ? `${below} ${Names.MORE_BELOW_TEXT}` : null,
45 hasNotShown ? `${notShown} not shown` : null,
46 ]).join(' · ')
47
48 const rowOf = (entry: Entries.BodyEntry) =>
49 Sections.fileRow(
50 kit,
51 {
52 key: Sections.fileKeyOf(entry),
53 path: entry.path,
54 displayPath: entry.displayPath,
55 added: entry.added,
56 removed: entry.removed,
57 note: null,
58 isSelected: false,
59 },
60 () => kit.actions.selectFile(entry.path),
61 )
62
63 const upperEdge = hasMoreAbove
64 ? Sections.listEdgeButton(kit, 'list-up', `↑ ${above} more above`)
65 : null
66
67 const lowerEdge = hasMoreBelow
68 ? Sections.listEdgeButton(kit, 'list-down', `↓ ${lower}`)
69 : hasNotShown
70 ? Sections.dimNote(kit, `… ${lower}`)
71 : null
72
73 const noiseToggle = hasNoise
74 ? Sections.toggleRow(kit, 'noise', {
75 label: `${Layout.plural(noiseCount, 'test')}/generated (${noiseFace})`,
76 onPress: kit.actions.toggleNoise,
77 })
78 : null
79
80 return Sections.present([
81 upperEdge,
82 ...shown.map(rowOf),
83 lowerEdge,
84 plan.isUntrackedNoted
85 ? Sections.dimNote(kit, Names.untrackedWithheldTextOf(model))
86 : null,
87 noiseToggle,
88 ])
89}