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 / sidebar-pane / list-rows-of / list-rows-of.ts
57 lines · 1.8 KBRaw
1import type { RenderElement } from 'claude-code'
2
3import { keptOf } from '../../../kept-of'
4import Limits from '../../../limits'
5import type Entries from '../../entries'
6import type { Kit } from '../../kit'
7import Layout from '../../layout'
8import Sections from '../../sections'
9
10/**
11 * The docked list (ReplDiffSidebar's summary rows): MAX_SUMMARY_ROWS files
12 * as rows that scroll the body to their file, then a dim count of the rest.
13 *
14 * The rest are the rows below the window and the files past the row cap.
15 * The built-in moves this window with the wheel over it or a chord; a pane
16 * has neither, so the window stays at the top and names no key.
17 *
18 * @param kit the elements, the handlers, the width
19 * @param entries the listed files, in order
20 * @param notShown how many session files fell past the row cap
21 * @returns the rows
22 */
23export function listRowsOf(
24 kit: Kit,
25 entries: readonly Entries.BodyEntry[],
26 notShown: number,
27): RenderElement[] {
28 const shown = entries.slice(0, Limits.MAX_SUMMARY_ROWS)
29 const moreBelow = entries.length - shown.length
30
31 const rows = shown.map(entry =>
32 Sections.fileRow(
33 kit,
34 {
35 key: Sections.fileKeyOf(entry.path),
36 path: entry.path,
37 displayPath: entry.displayPath,
38 added: entry.added,
39 removed: entry.removed,
40 note: null,
41 isSelected: false,
42 },
43 () => kit.actions.selectFile(entry.path),
44 ),
45 )
46
47 const counts = keptOf([
48 moreBelow > 0 ? `${moreBelow} more below` : null,
49 notShown > 0 ? `${notShown} not shown` : null,
50 ])
51
52 const lead = moreBelow > 0 ? '↓ ' : '… '
53 const hasCounts = counts.length > 0
54 const more = Layout.sanitizeName(`${lead}${counts.join(' · ')}`)
55
56 return hasCounts ? [...rows, Sections.dimNote(kit, more)] : rows
57}