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 / dialog-pane / dialog-rows-of.ts
46 lines · 1.5 KBRaw
1import Limits from '../../limits'
2import PaneState from '../../pane-state'
3import { dialogEntriesOf } from './dialog-entries-of'
4import { dialogWindowOf } from './dialog-window-of'
5
6/**
7 * The rows the dialog's content takes as dialogPane draws it, for the
8 * `rows` an inline open asks for: title, blank, count, picker, body, hints.
9 *
10 * The body is the message line, the list's window with its `more files`
11 * rows, or the file's name, rule and hunk lines (their wraps not counted:
12 * the layout caps a long file anyway and its arrows scroll it).
13 *
14 * @param model the pane's state
15 * @returns the rows wanted
16 */
17export function dialogRowsOf(model: PaneState.PaneModel): number {
18 const entries = dialogEntriesOf(model)
19
20 const hasCount =
21 PaneState.pickedTurnOf(model) !== undefined || model.data !== null
22
23 const isPaged = entries.length > Limits.MAX_VISIBLE_FILES
24 const picked = entries.find(entry => entry.path === model.selectedPath)
25 const isDetail = model.dialogView === 'detail' && picked !== undefined
26
27 const start = dialogWindowOf(
28 model,
29 entries.map(entry => entry.path),
30 )
31
32 const lines = (picked?.body?.hunks ?? []).reduce(
33 (sum, hunk) => sum + 1 + hunk.lines.length,
34 0,
35 )
36
37 const listed = Math.min(entries.length - start, Limits.MAX_VISIBLE_FILES)
38
39 const isEmpty = entries.length === 0
40 const listRows = isEmpty ? 1 : listed + (isPaged ? 2 : 0)
41 const bodyRows = isDetail ? 2 + Math.max(1, lines) : listRows
42
43 return (
44 2 + Number(hasCount) + Number(model.turns.length > 0) + 2 + bodyRows + 1
45 )
46}