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-toggle / pane-toggle-of.ts
23 lines · 902 BRaw
1import Limits from '../limits'
2import type { PaneBelief } from './pane-belief'
3
4/**
5 * What `/diff` does, the one place its toggle is decided: close only when
6 * the plugin opened the pane and it still draws; otherwise open, focused,
7 * unless the terminal is narrower than the built-in panel shows on, where
8 * `/diff` answers the built-in's resize line instead (`too-narrow`).
9 *
10 * The person's close raises nothing this plugin hooks, so a pane believed
11 * open is probed with a redraw first. A width not drawn yet opens.
12 *
13 * @param pane the plugin's belief, the probe's answer and the width
14 * @returns `close`, `open` or `too-narrow`
15 */
16export const paneToggleOf = (
17 pane: PaneBelief,
18): 'open' | 'close' | 'too-narrow' =>
19 pane.isBelievedOpen && pane.wasDrawnWhenProbed
20 ? 'close'
21 : pane.columns !== null && pane.columns < Limits.OPEN_MIN_COLUMNS
22 ? 'too-narrow'
23 : 'open'