From 0558c1127c2f7b6580901774240dbdfb42b6e36a Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Thu, 19 Nov 2026 17:55:24 +0800 Subject: [PATCH] feat(terminal): option to use the application title as the tab name always (#4477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings › Tools › Terminal gets "Use application title as tab name" (When command is running, the default; Always; Never). The title a program sets via OSC 0/2 named the tab only while a command ran, so a CLI agent's own title did not show when shell integration could not tell a command was running. --- crates/ide-core/src/workflow_settings.rs | 4 ++++ src/bindings.ts | 5 +++++ src/features/settings/pages/tools.tsx | 11 +++++++++++ src/features/terminal/store.ts | 9 +++++++-- src/features/terminal/terminal.test.ts | 15 +++++++++++++++ src/platform/clientSettings.ts | 1 + src/platform/locales/text/en.json | 4 +++- src/platform/locales/text/zh.json | 4 +++- src/platform/workflowSettings.ts | 5 +++++ 9 files changed, 54 insertions(+), 4 deletions(-) diff --git a/crates/ide-core/src/workflow_settings.rs b/crates/ide-core/src/workflow_settings.rs index fcd966497..06c41a2a3 100644 --- a/crates/ide-core/src/workflow_settings.rs +++ b/crates/ide-core/src/workflow_settings.rs @@ -448,6 +448,9 @@ pub struct TerminalSettings { /// Shell command line; empty = the login shell. pub shell_path: String, pub tab_name: String, + /// Title a program sets (OSC 0/2) as the tab's name: `running` (while a command runs), + /// `always`, or `off`. + pub app_title_as_tab_name: String, pub audible_bell: bool, pub close_on_exit: bool, pub mouse_reporting: bool, @@ -483,6 +486,7 @@ impl Default for TerminalSettings { env: BTreeMap::new(), shell_path: String::new(), tab_name: "Local".into(), + app_title_as_tab_name: "running".into(), audible_bell: true, close_on_exit: true, mouse_reporting: true, diff --git a/src/bindings.ts b/src/bindings.ts index a99fa92cc..fe04851a6 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -11613,6 +11613,11 @@ export type TerminalSettings = { /** Shell command line; empty = the login shell. */ shellPath?: string, tabName?: string, + /** + * Title a program sets (OSC 0/2) as the tab's name: `running` (while a command runs), + * `always`, or `off`. + */ + appTitleAsTabName?: string, audibleBell?: boolean, closeOnExit?: boolean, mouseReporting?: boolean, diff --git a/src/features/settings/pages/tools.tsx b/src/features/settings/pages/tools.tsx index d648feaff..b662a0d62 100644 --- a/src/features/settings/pages/tools.tsx +++ b/src/features/settings/pages/tools.tsx @@ -33,6 +33,11 @@ const SEND_KEY_OPTIONS = [ { value: "enter", label: "Enter" }, { value: "modEnter", label: "⌘Enter" }, ]; +const APP_TITLE_OPTIONS = [ + { value: "running", label: "When command is running" }, + { value: "always", label: "Always" }, + { value: "off", label: "Never" }, +]; const WHILE_RUNNING_OPTIONS = [ { value: "queue", label: "Queues the message for after the turn" }, { value: "steer", label: "Sends it into the turn" }, @@ -601,6 +606,12 @@ export const TOOLS_PAGES: PageSpec[] = [ options: [ { kind: "custom", label: "Shell path", component: ShellPathRow }, { kind: "text", key: "terminal.tabName", label: "Default Tab name", placeholder: "Local" }, + { + kind: "select", + key: "terminal.appTitleAsTabName", + label: "Use application title as tab name", + options: APP_TITLE_OPTIONS, + }, { kind: "custom", label: "Audible bell", diff --git a/src/features/terminal/store.ts b/src/features/terminal/store.ts index f298d532d..68ace5c0c 100644 --- a/src/features/terminal/store.ts +++ b/src/features/terminal/store.ts @@ -176,10 +176,15 @@ export function trimMiddle(text: string, max: number): string { const APP_TITLE_MAX = 30; -/** The title the program in the tab set, while a command runs (at the prompt it is the shell's own). */ +/** + * The title the program in the tab set (OSC 0/2), per Settings › Terminal: by default only + * while a command runs (at the prompt it is the shell's own), as IDEA does. + */ function appTitle(tab: TerminalTab, sessions?: Record): string | null { const s = sessions?.[tab.session]; - return s?.commandRunning ? s.appTitle : null; + const when = workflowSettings().terminal.appTitleAsTabName; + if (!s?.appTitle || when === "off") return null; + return when === "always" || s.commandRunning ? s.appTitle : null; } /** diff --git a/src/features/terminal/terminal.test.ts b/src/features/terminal/terminal.test.ts index c572e5863..0489411cf 100644 --- a/src/features/terminal/terminal.test.ts +++ b/src/features/terminal/terminal.test.ts @@ -17,6 +17,8 @@ import { } from "./store"; import type { SessionSnapshot } from "./session"; import { usePlatform } from "@/platform/platformInfo"; +import { useProject } from "@/platform/project"; +import type { Settings } from "@/bindings"; import { buildTheme, mix, parseColor, terminalFont, toHex } from "./theme"; describe("theme", () => { @@ -476,6 +478,19 @@ describe("terminal tab titles", () => { expect(tabFullTitle(tab, snap(long))).toBe(long); }); + it("uses the program's title always or never, per Settings › Terminal", () => { + const set = (appTitleAsTabName: string) => + useProject.setState({ settings: { terminal: { appTitleAsTabName } } as unknown as Settings }); + try { + set("always"); + expect(tabTitle(tab, snap("claude", false))).toBe("claude"); + set("off"); + expect(tabTitle(tab, snap("vim notes.md"))).toBe("Local"); + } finally { + useProject.setState({ settings: null }); + } + }); + it("keeps a name the user gave the tab", () => { const renamed = { ...tab, customName: "Server" }; expect(tabTitle(renamed, snap("top"))).toBe("Server"); diff --git a/src/platform/clientSettings.ts b/src/platform/clientSettings.ts index 429e0b128..9541ccc7a 100644 --- a/src/platform/clientSettings.ts +++ b/src/platform/clientSettings.ts @@ -56,6 +56,7 @@ export const CLIENT_SETTINGS_KEYS = [ "editor.general.richTextCopy", "editor.codeStyle.visualGuides", "terminal.tabName", + "terminal.appTitleAsTabName", "terminal.audibleBell", "terminal.closeOnExit", "terminal.mouseReporting", diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 28cdd0dff..c2add3915 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2632,5 +2632,7 @@ "Updated {n} branch": "Updated {n} branch", "Updated {n} branches": "Updated {n} branches", "No branches were updated": "No branches were updated", - "Selected branches are up-to-date": "Selected branches are up-to-date" + "Selected branches are up-to-date": "Selected branches are up-to-date", + "Use application title as tab name": "Use application title as tab name", + "When command is running": "When command is running" } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 3ecee03fb..c61fd5db8 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -9011,5 +9011,7 @@ "Updated {n} branch": "已更新 {n} 个分支", "Updated {n} branches": "已更新 {n} 个分支", "No branches were updated": "没有分支被更新", - "Selected branches are up-to-date": "所选分支都是最新的" + "Selected branches are up-to-date": "所选分支都是最新的", + "Use application title as tab name": "使用应用标题作为标签页名称", + "When command is running": "命令运行时" } diff --git a/src/platform/workflowSettings.ts b/src/platform/workflowSettings.ts index 30768a96d..c94e3178c 100644 --- a/src/platform/workflowSettings.ts +++ b/src/platform/workflowSettings.ts @@ -140,6 +140,8 @@ export interface ExternalDiffValid { } export type TerminalMaxFps = "unlimited" | "60" | "30" | "15" | "10"; +/** When a title the program sets (OSC 0/2) names the terminal tab, as IDEA's option. */ +export type TerminalAppTitle = "running" | "always" | "off"; export const TERMINAL_MAX_FPS_OPTIONS: readonly { value: TerminalMaxFps; label: string }[] = [ { value: "unlimited", label: "Unlimited" }, @@ -154,6 +156,7 @@ export interface TerminalSettingsValid { env: Record; shellPath: string; tabName: string; + appTitleAsTabName: TerminalAppTitle; audibleBell: boolean; closeOnExit: boolean; mouseReporting: boolean; @@ -361,6 +364,7 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = { env: {}, shellPath: "", tabName: "Local", + appTitleAsTabName: "running", audibleBell: true, closeOnExit: true, mouseReporting: true, @@ -570,6 +574,7 @@ export function validateTerminal(raw: unknown): TerminalSettingsValid { env, shellPath: text(v.shellPath, d.shellPath).trim(), tabName: nonEmpty(v.tabName, d.tabName), + appTitleAsTabName: oneOf(v.appTitleAsTabName, ["running", "always", "off"] as const, d.appTitleAsTabName), audibleBell: bool(v.audibleBell, d.audibleBell), closeOnExit: bool(v.closeOnExit, d.closeOnExit), mouseReporting: bool(v.mouseReporting, d.mouseReporting),