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
36 lines · 1.2 KBRaw
1import type Backend from '../../backend'
2import type Git from '../../git'
3
4/**
5 * A requested mode's name for the base line; branch mode names its base
6 * branch from the data, or says what stands in while none is known. A
7 * working-tree diff names its own base (`HEAD`, a short sha); anything
8 * else falls back to the backend's word for it.
9 *
10 * @param requested the mode the person picked
11 * @param source what the data on screen compares
12 * @param phase `pending` while the requested mode's fetch has not landed
13 * @param words the backend's words
14 * @returns the label without its pending ellipsis
15 */
16export function modeLabelOf(
17 requested: Git.BaseMode,
18 source: Git.DiffSource,
19 phase: 'pending' | 'settled',
20 words: Pick<Backend.BackendWords, 'base'>,
21) {
22 const base = source.kind === 'working-tree' ? source.base : words.base
23
24 switch (requested) {
25 case 'session':
26 return 'this session'
27 case 'uncommitted':
28 return `uncommitted (vs ${base})`
29 case 'branch':
30 if (source.kind === 'branch') {
31 return `branch vs ${source.baseBranch}`
32 }
33
34 return phase === 'pending' ? 'branch diff' : `vs ${base} (no base branch)`
35 }
36}