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 / pane-state / mode-label-of / mode-label-of.ts
44 lines · 1.5 KBRaw
1import type Git from '../../git'
2import type { PaneModel } from '../pane-model'
3
4/**
5 * One base mode's name in the picker, worded as the built-in's base line
6 * (diffBaseLabel) words the mode it shows.
7 *
8 * Branch mode names its base branch from the data, or once its own fetch
9 * settled without one says what stands in; uncommitted names the working
10 * tree's base. The requested mode carries an ellipsis while pending.
11 *
12 * @param mode the mode to name
13 * @param model the mode the person picked, the last good fetch, the words
14 * @returns the label
15 */
16export function modeLabelOf(
17 mode: Git.BaseMode,
18 model: Pick<PaneModel, 'requestedMode' | 'data' | 'words'>,
19): string {
20 const { data } = model
21 const source = data?.source
22 const isPending = data !== null && model.requestedMode !== data.mode
23 const isRequested = mode === model.requestedMode
24 const suffix = isRequested && isPending ? '…' : ''
25 const base = source?.kind === 'working-tree' ? source.base : model.words.base
26 const isSettledBranch = isRequested && !isPending && data?.mode === 'branch'
27
28 function nameOf(): string {
29 switch (mode) {
30 case 'session':
31 return 'this session'
32 case 'uncommitted':
33 return `uncommitted (vs ${base})`
34 case 'branch':
35 if (source?.kind === 'branch') {
36 return `branch vs ${source.baseBranch}`
37 }
38
39 return isSettledBranch ? `vs ${base} (no base branch)` : 'branch diff'
40 }
41 }
42
43 return `${nameOf()}${suffix}`
44}