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.
TypeScript
mods/diff: under 110 columns /diff answers the built-in's resize line and opens nothing
poteat37f19ef9d9a8
diff --git a/mods/diff/README.md b/mods/diff/README.mdindex 4db989fb..d2330afe 100644--- a/mods/diff/README.md+++ b/mods/diff/README.md@@ -7,10 +7,10 @@ runs shell commands and finishes turns, and while it is open it polls therepository's HEAD so a commit or checkout made elsewhere shows too. Thefirst successful edit of a session opens the pane by itself where theterminal is wide enough (144 columns when the person never chose, 110 when-they kept it open before; a person who closed it is left alone). Where the-surface seats the pane inline instead of beside the transcript (a terminal-under 110 columns), it shows only the built-in's line asking for a wider-terminal. A file's+they kept it open before; a person who closed it is left alone). On a+terminal under 110 columns `/diff` answers with the built-in's line asking+for a wider terminal and opens nothing; a pane opened wider that the surface+then seats inline shows only that line. A file'sask button arms that file: its hunks ride the next prompt as context, once.The pane compares the working tree against HEAD, split at the session'sdiff --git a/mods/diff/hooks/limits/columns/open-min-columns.ts b/mods/diff/hooks/limits/columns/open-min-columns.tsindex c34a84a1..450f898b 100644--- a/mods/diff/hooks/limits/columns/open-min-columns.ts+++ b/mods/diff/hooks/limits/columns/open-min-columns.ts@@ -1,5 +1,6 @@/**- * The terminal width from which the first edit opens the pane when the person- * kept it open before (the built-in sidebar's own minimum).+ * The terminal width from which `/diff` opens the pane, and the first edit+ * opens it when the person kept it open before (the built-in sidebar's own+ * minimum).*/export const OPEN_MIN_COLUMNS = 110diff --git a/mods/diff/hooks/names/texts/resize-terminal-text.ts b/mods/diff/hooks/names/texts/resize-terminal-text.tsindex adb93a5a..bc6febac 100644--- a/mods/diff/hooks/names/texts/resize-terminal-text.ts+++ b/mods/diff/hooks/names/texts/resize-terminal-text.ts@@ -1,6 +1,7 @@/**- * The pane's one line where the surface seats it inline (no room beside the- * transcript), worded as the built-in words its refusal below that width.+ * `/diff`'s answer on a terminal narrower than the built-in panel shows on,+ * worded as the built-in words it; also the pane's one line where the+ * surface seats it inline (no room beside the transcript).*/export const RESIZE_TERMINAL_TEXT ='Resize your terminal to at least 110 columns to show the diff panel'diff --git a/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.ts b/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.tsindex 80c4475e..77396921 100644--- a/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.ts+++ b/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.ts@@ -1,8 +1,10 @@/*** What the plugin knows of its pane when `/diff` runs: whether it opened- * it and never closed it, and whether it drew when a redraw was asked.+ * it and never closed it, whether it drew when a redraw was asked, and the+ * terminal's width as last drawn (null before any draw).*/export type PaneBelief = {isBelievedOpen: booleanwasDrawnWhenProbed: boolean+ columns: number | null}diff --git a/mods/diff/hooks/pane-toggle/pane-toggle-of.ts b/mods/diff/hooks/pane-toggle/pane-toggle-of.tsindex 0ddcb2ce..d639d719 100644--- a/mods/diff/hooks/pane-toggle/pane-toggle-of.ts+++ b/mods/diff/hooks/pane-toggle/pane-toggle-of.ts@@ -1,14 +1,23 @@+import Limits from '../limits'import type { PaneBelief } from './pane-belief'/*** What `/diff` does, the one place its toggle is decided: close only when- * the plugin opened the pane and it still draws; otherwise open, focused.+ * the plugin opened the pane and it still draws; otherwise open, focused,+ * unless the terminal is narrower than the built-in panel shows on, where+ * `/diff` answers the built-in's resize line instead (`too-narrow`).** The person's close raises nothing this plugin hooks, so a pane believed- * open is probed with a redraw first.+ * open is probed with a redraw first. A width not drawn yet opens.*- * @param pane the plugin's belief and the probe's answer- * @returns `close` or `open`+ * @param pane the plugin's belief, the probe's answer and the width+ * @returns `close`, `open` or `too-narrow`*/-export const paneToggleOf = (pane: PaneBelief): 'open' | 'close' =>- pane.isBelievedOpen && pane.wasDrawnWhenProbed ? 'close' : 'open'+export const paneToggleOf = (+ pane: PaneBelief,+): 'open' | 'close' | 'too-narrow' =>+ pane.isBelievedOpen && pane.wasDrawnWhenProbed+ ? 'close'+ : pane.columns !== null && pane.columns < Limits.OPEN_MIN_COLUMNS+ ? 'too-narrow'+ : 'open'diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex 26f06c38..decad2e8 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -24,6 +24,8 @@ import Views from './views'* `session.start` registers `/diff` (refused while the built-in holds it),* binds the host every pinned backend reads through, and pins the backend* (backendOf): one probe in flight, asked again on `/diff` until git answers.+ * On a terminal narrower than the built-in panel shows on, `/diff` answers+ * the built-in's resize line and opens nothing (paneToggleOf).** @param on the engine's registrar*/@@ -513,11 +515,17 @@ export function register(on: On) {}}- const isOpening =- PaneToggle.paneToggleOf({- isBelievedOpen: isPaneOpen,- wasDrawnWhenProbed: isPaneOpen && (await wasDrawnWhenProbed(host)),- }) === 'open'+ const toggle = PaneToggle.paneToggleOf({+ isBelievedOpen: isPaneOpen,+ wasDrawnWhenProbed: isPaneOpen && (await wasDrawnWhenProbed(host)),+ columns,+ })++ if (toggle === 'too-narrow') {+ return { text: Names.RESIZE_TERMINAL_TEXT }+ }++ const isOpening = toggle === 'open'await (isOpening ? openPane(host, 'manual') : closePane(host))await host.storeSet(Names.STORE_OPEN_KEY, isOpening).catch(() => undefined)