/**
- * Offer shell selection for a new terminal or mount a restored screen.
+ * Offer shell selection or render the retained terminal with the application theme.
* @param props - sidebar occurrence, model lookup and translated copy.
* @returns the terminal screen and any pending or exceptional state.
*/
-export function TerminalBody({ useTabInfo, useTerminal, view, t }: TerminalBodyProps): ReactNode {
+export function TerminalBody({ useTabInfo, useTerminal, useTheme, view, t }: TerminalBodyProps): ReactNode {
const { tab } = useTabInfo()
+ const theme = useTheme(value => value)
const model = view(tab.id)
const state = useTerminal(tab.id)
useEffect(() => model.mount(), [model])
@@ -43,7 +45,7 @@ export function TerminalBody({ useTabInfo, useTerminal, view, t }: TerminalBodyP
?
: )}
}
- {state.info !== undefined && }
+ {state.info !== undefined && }
{error !== undefined && {t('failed', { message: error })}
}
)
@@ -81,11 +83,12 @@ function TerminalLauncher({ state, model, t }: {
}
/* oxlint-disable typescript/no-non-null-assertion -- React sets the DOM ref, then these effects initialize and use the emulator. */
-function TerminalScreen({ state, model, visible, label }: {
+function TerminalScreen({ state, model, visible, label, theme }: {
state: TerminalViewState
model: TerminalView
visible: boolean
label: string
+ theme: ThemeSnapshot
}): ReactNode {
const element = useRef(null)
const terminal = useRef()
@@ -96,7 +99,7 @@ function TerminalScreen({ state, model, visible, label }: {
useLayoutEffect(() => {
const node = element.current!
- const xterm = new Terminal({ cursorBlink: true, fontSize: 13, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', scrollback: current.current.state.environment?.scrollback ?? 0, theme: { background: '#17191d', foreground: '#e7e9ee' } })
+ const xterm = new Terminal({ cursorBlink: true, fontSize: 13, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', scrollback: current.current.state.environment?.scrollback ?? 0 })
const addon = new FitAddon()
xterm.loadAddon(addon)
xterm.open(node)
@@ -120,6 +123,16 @@ function TerminalScreen({ state, model, visible, label }: {
}
}, [model])
+ useLayoutEffect(() => {
+ const style = getComputedStyle(element.current!)
+ terminal.current!.options.theme = {
+ background: style.backgroundColor, foreground: style.color,
+ cursor: style.color, cursorAccent: style.backgroundColor,
+ selectionBackground: style.color, selectionForeground: style.backgroundColor,
+ selectionInactiveBackground: style.color,
+ }
+ }, [theme, model])
+
useLayoutEffect(() => {
const xterm = terminal.current!
const render = state.render
diff --git a/packages/client/ui-sidebar-terminal/src/client/face.ts b/packages/client/ui-sidebar-terminal/src/client/face.ts
index 95920e23b1..57236a39b2 100644
--- a/packages/client/ui-sidebar-terminal/src/client/face.ts
+++ b/packages/client/ui-sidebar-terminal/src/client/face.ts
@@ -2,6 +2,7 @@
import type { WebTerminalId } from '@deepseek-ai/dsh-api-terminal-controller/types'
import type { TerminalView, TerminalViewState } from '@deepseek-ai/dsh-api-terminal-controller/client'
import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots'
+import type { ThemeSnapshot } from '@deepseek-ai/dsh-client-ui-theme/client'
/** The terminal's React-free model is resolved by sidebar occurrence. */
export interface TerminalInjected {
@@ -11,6 +12,11 @@ export interface TerminalInjected {
}
+/** The terminal screen follows the resolved application theme through a framework hook. */
+export interface TerminalBodyInjected extends TerminalInjected {
+ readonly hooks: { readonly theme: HostObservable }
+}
+
declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
interface SidebarRightTabParamsMap {
/** An existing Host terminal selected from the Session terminal list. */
diff --git a/packages/client/ui-sidebar-terminal/src/client/index.ts b/packages/client/ui-sidebar-terminal/src/client/index.ts
index cf71fb2f87..5d5eb28890 100644
--- a/packages/client/ui-sidebar-terminal/src/client/index.ts
+++ b/packages/client/ui-sidebar-terminal/src/client/index.ts
@@ -8,16 +8,17 @@ import type {} from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
import type {} from '@deepseek-ai/dsh-client-locale/client'
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
+import type {} from '@deepseek-ai/dsh-client-ui-theme/client'
import { TerminalGuideIcon } from './TerminalIcon.tsx'
import { TerminalBody } from './TerminalBody.tsx'
import { TerminalTitle } from './TerminalTitle.tsx'
import { TerminalRecovery, type TerminalRecoveryInjected } from './TerminalRecovery.tsx'
import { TerminalCleanup, type TerminalCleanupInjected } from './TerminalCleanup.tsx'
-import type { TerminalInjected } from './face.ts'
+import type { TerminalBodyInjected, TerminalInjected } from './face.ts'
import { en, zh } from './locales.ts'
/** Services needed by the terminal's two sidebar seats. */
-export const inject = ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'webTerminals']
+export const inject = ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'webTerminals', 'theme']
/**
* Register the terminal type, observable views and background process cleanup.
@@ -47,8 +48,14 @@ export function apply(ctx: Context): void {
view: key => view(sessionId, key),
keyedHooks: { terminal: key => view(sessionId, key).state },
})
+ const theme: TerminalBodyInjected['hooks']['theme'] = {
+ getSnapshot: () => ctx.theme.getTheme(),
+ subscribe: listener => ctx.on('theme/change', listener),
+ }
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register(
- { name: 'sidebar.right.pane.tab', key: id, locale: namespace, inject }, TerminalBody,
+ { name: 'sidebar.right.pane.tab', key: id, locale: namespace,
+ inject: (sessionId): TerminalBodyInjected => ({ ...inject(sessionId), hooks: { theme } }),
+ }, TerminalBody,
)), 'ui-sidebar-terminal.body')
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register(
{ name: 'sidebar.right.pane.tab.title', key: id, locale: namespace, inject }, TerminalTitle,
diff --git a/packages/client/ui-sidebar-terminal/tests/apply.client.spec.ts b/packages/client/ui-sidebar-terminal/tests/apply.client.spec.ts
index dbbd4fa040..3d44309f51 100644
--- a/packages/client/ui-sidebar-terminal/tests/apply.client.spec.ts
+++ b/packages/client/ui-sidebar-terminal/tests/apply.client.spec.ts
@@ -14,7 +14,7 @@ import { TerminalBody } from '../src/client/TerminalBody.tsx'
import { TerminalTitle } from '../src/client/TerminalTitle.tsx'
import { TerminalRecovery, type TerminalRecoveryInjected } from '../src/client/TerminalRecovery.tsx'
import { TerminalCleanup, type TerminalCleanupInjected } from '../src/client/TerminalCleanup.tsx'
-import type { TerminalInjected } from '../src/client/face.ts'
+import type { TerminalBodyInjected } from '../src/client/face.ts'
import { en, zh } from '../src/client/locales.ts'
vi.mock('@xterm/xterm', () => ({ Terminal: vi.fn() }))
@@ -56,9 +56,12 @@ async function mountPlugin() {
bind: () => (key: string) => key,
register: (name: string, values: unknown) => { dictionaries.set(name, values); return () => { dictionaries.delete(name) } },
} as never)
+ const theme = { preference: 'light' as const, fontSize: 14, active: { id: 'light', colorScheme: 'light' as const, tokens: {} }, themes: [], revision: 0 }
+ ctx.provide('theme', { getTheme: () => theme } as never)
const fiber = await ctx.plugin({ inject, apply })
return {
- tabs, entries, dictionaries, terminals, model, occurrence, openTabIn,
+ tabs, entries, dictionaries, terminals, model, occurrence, openTabIn, theme,
+ emitTheme() { ctx.emit('theme/change', theme) },
get closeHandler() { return closeHandler },
setParams(next: typeof params) { params = next },
async dispose() { await fiber.dispose(); await ctx.fiber.dispose() },
@@ -85,7 +88,15 @@ it('registers terminal views, recovery and cleanup, then releases every contribu
['shell.overlay', TerminalCleanup, 'sidebarTerminal'],
])
const sessionId = 'session' as SessionId
- const face = h.entries[0]!.inject(sessionId) as TerminalInjected
+ const face = h.entries[0]!.inject(sessionId) as TerminalBodyInjected
+ expect(face.hooks.theme.getSnapshot()).toBe(h.theme)
+ const changed = vi.fn()
+ const unsubscribe = face.hooks.theme.subscribe(changed)
+ h.emitTheme()
+ expect(changed).toHaveBeenCalledOnce()
+ unsubscribe()
+ h.emitTheme()
+ expect(changed).toHaveBeenCalledOnce()
expect(face.view('tab')).toBe(h.model)
expect(h.terminals.view).toHaveBeenLastCalledWith(sessionId, 'tab', undefined)
const terminalId = 'retained' as WebTerminalId
diff --git a/packages/client/ui-sidebar-terminal/tests/terminal-body.client.spec.tsx b/packages/client/ui-sidebar-terminal/tests/terminal-body.client.spec.tsx
index 7070b43df9..bc15452980 100644
--- a/packages/client/ui-sidebar-terminal/tests/terminal-body.client.spec.tsx
+++ b/packages/client/ui-sidebar-terminal/tests/terminal-body.client.spec.tsx
@@ -3,6 +3,8 @@
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render } from '@testing-library/react'
import type { ReactNode } from 'react'
+import type { ITheme } from '@xterm/xterm'
+import type { ThemeSnapshot } from '@deepseek-ai/dsh-client-ui-theme/client'
import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
import type { TerminalViewState } from '@deepseek-ai/dsh-api-terminal-controller/client'
import type { WebTerminalId } from '@deepseek-ai/dsh-api-terminal-controller/types'
@@ -15,7 +17,7 @@ const fake = vi.hoisted(() => ({
dimensions: { cols: 120, rows: 40 } as { cols: number; rows: number } | undefined,
}))
class FakeTerminal {
- options: { disableStdin?: boolean }
+ options: { disableStdin?: boolean; theme?: ITheme }
textarea: HTMLTextAreaElement | undefined = document.createElement('textarea')
input: ((data: string) => void) | undefined
readonly disposeInput = vi.fn()
@@ -63,6 +65,7 @@ const titleSurfaces = [
function mount(initial: TerminalViewState | undefined = idle, dictionary = en) {
let state: TerminalViewState | undefined = initial
let visible = true
+ let theme: ThemeSnapshot = { preference: 'light', fontSize: 14, active: { id: 'light', colorScheme: 'light', tokens: {} }, themes: [], revision: 0 }
const detach = vi.fn()
const model = {
start: vi.fn(async () => {}), selectShell: vi.fn(),
@@ -75,11 +78,13 @@ function mount(initial: TerminalViewState | undefined = idle, dictionary = en) {
const props = {
view: () => model,
useTerminal: (_key: string, select?: (value: TerminalViewState | undefined) => unknown) => select === undefined ? state : select(state),
+ useTheme: (select: (value: ThemeSnapshot) => unknown) => select(theme),
useTabInfo: tab, t: makeTranslate(dictionary),
} as unknown as TerminalBodyProps
const view = render()
return {
view, props, model, detach, openTab,
+ changeTheme() { theme = { ...theme, revision: theme.revision + 1 }; view.rerender() },
update(next: TerminalViewState | undefined, shown = visible) {
state = next; visible = shown; view.rerender()
},
@@ -172,6 +177,28 @@ it('displays disconnect, close and exit states and offers explicit reconnection
expect(h.view.getByRole('status').textContent).toBe(en.unavailable)
})
+it('updates screen, cursor and selection colors without replacing the terminal or clearing output', () => {
+ const colors = { backgroundColor: 'rgb(255, 255, 255)', color: 'rgb(23, 25, 29)' }
+ vi.spyOn(window, 'getComputedStyle').mockImplementation(() => colors as CSSStyleDeclaration)
+ const h = mount({ ...idle, info, phase: 'connected', writable: true })
+ const terminal = fake.terminals[0]!
+ expect(terminal.options.theme).toMatchObject({
+ background: colors.backgroundColor, foreground: colors.color, cursor: colors.color, selectionForeground: colors.backgroundColor,
+ })
+ colors.backgroundColor = 'rgb(23, 25, 29)'
+ colors.color = 'rgb(231, 233, 238)'
+ h.changeTheme()
+ expect(terminal.options.theme).toEqual({
+ background: colors.backgroundColor, foreground: colors.color, cursor: colors.color, cursorAccent: colors.backgroundColor,
+ selectionBackground: colors.color, selectionForeground: colors.backgroundColor, selectionInactiveBackground: colors.color,
+ })
+ expect(fake.terminals).toEqual([terminal])
+ expect(terminal.reset).not.toHaveBeenCalled()
+ expect(terminal.dispose).not.toHaveBeenCalled()
+ expect(h.model.mount).toHaveBeenCalledOnce()
+ expect(h.detach).not.toHaveBeenCalled()
+})
+
it('fits only visible writable terminals with measurable dimensions and clamps the provider limits', () => {
const state: TerminalViewState = { ...idle, info, phase: 'connected', writable: true }
const h = mount(state)
diff --git a/packages/client/ui-sidebar-terminal/tsconfig.json b/packages/client/ui-sidebar-terminal/tsconfig.json
index 4e229078ec..1727fed36d 100644
--- a/packages/client/ui-sidebar-terminal/tsconfig.json
+++ b/packages/client/ui-sidebar-terminal/tsconfig.json
@@ -46,6 +46,9 @@
},
{
"path": "../ui-conversation"
+ },
+ {
+ "path": "../ui-theme"
}
]
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 196f816cc6..4924ea3623 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -637,12 +637,12 @@ importers:
'@deepseek-ai/dsh-pwsh-local':
specifier: workspace:^
version: link:../../packages/shell/pwsh-local
- '@deepseek-ai/dsh-subprocess-local':
- specifier: workspace:^
- version: link:../../packages/subprocess/subprocess-local
'@deepseek-ai/dsh-remote-mock':
specifier: workspace:^
version: link:../../packages/test-support/remote-mock
+ '@deepseek-ai/dsh-subprocess-local':
+ specifier: workspace:^
+ version: link:../../packages/subprocess/subprocess-local
'@types/node':
specifier: ^22.0.0
version: 22.20.0
@@ -4224,6 +4224,9 @@ importers:
'@deepseek-ai/dsh-client-ui-slots':
specifier: workspace:^
version: link:../ui-slots
+ '@deepseek-ai/dsh-client-ui-theme':
+ specifier: workspace:^
+ version: link:../ui-theme
'@deepseek-ai/dsh-session':
specifier: workspace:^
version: link:../../core/session