From bd3a5835debef517ffe1328bae0d4ecd75125f69 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 1 Nov 2026 22:33:45 -0800 Subject: [PATCH 1/6] feat(settings): import Kitty configs through a shared terminal config import pipeline --- config/localization-coverage-allowlist.json | 21 ++ src/main/ghostty/index.ts | 182 +++++------------- src/main/ghostty/mapper.ts | 4 +- src/main/ipc/settings-import-handlers.ts | 18 ++ src/main/ipc/settings.ts | 12 +- src/main/kitty/discovery.ts | 44 +++++ src/main/kitty/index.ts | 28 +++ src/main/kitty/kitty-import.test.ts | 81 ++++++++ src/main/kitty/mapper.ts | 152 +++++++++++++++ src/main/kitty/parser.ts | 149 ++++++++++++++ .../config-file-reader.ts | 26 +++ src/main/terminal-config-import/preview.ts | 94 +++++++++ .../settings-changes.ts | 41 ++++ src/preload/api/settings-api.ts | 13 +- src/preload/api/settings-bridge.ts | 12 +- .../onboarding/GhosttyDiscoveryRow.tsx | 4 +- .../src/components/onboarding/ThemeStep.tsx | 15 +- .../settings/AppearancePane.test.tsx | 4 +- .../components/settings/AppearancePane.tsx | 8 +- ...alAppearanceSection.config-import.test.ts} | 67 +++---- .../settings/TerminalAppearanceSection.tsx | 84 ++++---- ...odal.tsx => TerminalConfigImportModal.tsx} | 81 +++++--- .../settings/TerminalPane.pwsh.test.ts | 4 +- ...-interface-secondary-section-renderers.tsx | 2 +- .../terminal-advanced-platform-search.ts | 17 +- .../components/settings/terminal-search.ts | 6 +- .../settings/use-settings-store-model.ts | 6 +- ...tyImport.ts => useTerminalConfigImport.ts} | 48 +++-- src/renderer/src/i18n/locales/en.json | 15 +- src/shared/global-settings-types.ts | 2 - ...w.ts => terminal-config-import-preview.ts} | 19 +- 31 files changed, 957 insertions(+), 302 deletions(-) create mode 100644 src/main/ipc/settings-import-handlers.ts create mode 100644 src/main/kitty/discovery.ts create mode 100644 src/main/kitty/index.ts create mode 100644 src/main/kitty/kitty-import.test.ts create mode 100644 src/main/kitty/mapper.ts create mode 100644 src/main/kitty/parser.ts create mode 100644 src/main/terminal-config-import/config-file-reader.ts create mode 100644 src/main/terminal-config-import/preview.ts create mode 100644 src/main/terminal-config-import/settings-changes.ts rename src/renderer/src/components/settings/{TerminalAppearanceSection.ghostty.test.ts => TerminalAppearanceSection.config-import.test.ts} (89%) rename src/renderer/src/components/settings/{GhosttyImportModal.tsx => TerminalConfigImportModal.tsx} (77%) rename src/renderer/src/components/settings/{useGhosttyImport.ts => useTerminalConfigImport.ts} (69%) rename src/shared/{ghostty-import-preview.ts => terminal-config-import-preview.ts} (52%) diff --git a/config/localization-coverage-allowlist.json b/config/localization-coverage-allowlist.json index 6f0270d9ff32..00fd65c4c517 100644 --- a/config/localization-coverage-allowlist.json +++ b/config/localization-coverage-allowlist.json @@ -69,6 +69,27 @@ "dynamic": false, "count": 2 }, + { + "filePath": "src/renderer/src/components/settings/terminal-advanced-platform-search.ts", + "kind": "object-property:keywords", + "text": "Kitty", + "dynamic": false, + "count": 1 + }, + { + "filePath": "src/renderer/src/components/settings/terminal-advanced-platform-search.ts", + "kind": "object-property:keywords", + "text": "kitty", + "dynamic": false, + "count": 1 + }, + { + "filePath": "src/renderer/src/components/settings/terminal-advanced-platform-search.ts", + "kind": "object-property:keywords", + "text": "kitty.conf", + "dynamic": false, + "count": 1 + }, { "filePath": "src/renderer/src/components/settings/terminal-pane-appearance-search.ts", "kind": "object-property:keywords", diff --git a/src/main/ghostty/index.ts b/src/main/ghostty/index.ts index 53a77e2444b7..fbd1cca06bf2 100644 --- a/src/main/ghostty/index.ts +++ b/src/main/ghostty/index.ts @@ -1,53 +1,21 @@ -import { readFile, stat } from 'node:fs/promises' import { platform } from 'node:os' -import path from 'node:path' import type { WebContents } from 'electron' -import type { - GhosttyImportPreview, - GhosttyImportSource, - GlobalSettings -} from '../../shared/global-settings-types' +import type { GlobalSettings } from '../../shared/global-settings-types' +import type { TerminalConfigImportPreview } from '../../shared/terminal-config-import-preview' import type { Store } from '../persistence/loading-store/store' import { translateMain } from '../i18n/main-i18n' -import { validateImportSource } from '../import-source-validation' -import { chooseTerminalConfigFile } from '../terminal-config-import/choose-config-file' +import { readConfigFile } from '../terminal-config-import/config-file-reader' +import { + previewTerminalConfigImport, + type TerminalConfigImporter, + type TerminalConfigMapping +} from '../terminal-config-import/preview' import { findGhosttyConfigPaths } from './discovery' import { parseGhosttyConfig } from './parser' import { mapGhosttyToOrca } from './mapper' import { importGhosttyTheme } from './theme-mapping' -// Bound config reads to avoid loading arbitrarily large files into main. -const MAX_CONFIG_BYTES = 1_000_000 -const GHOSTTY_IMPORT_SOURCE_KINDS = ['auto', 'chooseFile'] as const - -// Compare nested values structurally with sorted keys while preserving meaningful array order. -function stableStringify(v: unknown): string { - if (v === null || typeof v !== 'object') { - return JSON.stringify(v) - } - if (Array.isArray(v)) { - return `[${v.map(stableStringify).join(',')}]` - } - const entries = Object.entries(v as Record).sort(([ka], [kb]) => - ka.localeCompare(kb) - ) - return `{${entries.map(([k, val]) => `${JSON.stringify(k)}:${stableStringify(val)}`).join(',')}}` -} - -function valuesEqual(a: unknown, b: unknown): boolean { - if (a === b) { - return true - } - if (typeof a === 'object' && a !== null && typeof b === 'object' && b !== null) { - return stableStringify(a) === stableStringify(b) - } - return false -} - -// An unset object setting already matches an import that clears it. -function emptyLike(value: unknown): unknown { - return typeof value === 'object' && value !== null && !Array.isArray(value) ? {} : undefined -} +type GhosttyConfig = Record function asArray(value: string | string[] | undefined): string[] { if (value === undefined) { @@ -72,7 +40,7 @@ function mergeParsedConfig( type ThemeReferencePatch = { diff: Partial - themeNames?: GhosttyImportPreview['terminalThemes'] + themeNames?: TerminalConfigImportPreview['terminalThemes'] unsupportedKeys: string[] } @@ -113,106 +81,46 @@ async function themeReferencePatch( } } -async function resolveConfigPaths( - source: GhosttyImportSource, - webContents?: WebContents -): Promise { - switch (source.kind) { - case 'auto': - return findGhosttyConfigPaths() - case 'chooseFile': { - const picked = await chooseTerminalConfigFile( - translateMain('native.dialog.importGhosttyConfig', 'Import Ghostty Config'), - webContents - ) - return picked === null ? null : [picked] - } - } -} - -export async function previewGhosttyImport( - store: Store, - source: unknown = { kind: 'auto' }, - webContents?: WebContents -): Promise { - const validatedSource = validateImportSource(source, GHOSTTY_IMPORT_SOURCE_KINDS) - if (!validatedSource) { - return { found: false, diff: {}, unsupportedKeys: [], error: 'Invalid Ghostty import source.' } - } - const configPaths = await resolveConfigPaths(validatedSource, webContents) - if (configPaths === null) { - return { found: false, canceled: true, diff: {}, unsupportedKeys: [] } - } - if (configPaths.length === 0) { - return { found: false, diff: {}, unsupportedKeys: [] } - } - - const parsed: Record = {} - const readPaths: string[] = [] - let firstError: string | null = null - for (const configPath of configPaths) { - let content: string - try { - const info = await stat(configPath) - // Picked paths can be devices or FIFOs whose zero size would slip past the byte limit. - if (!info.isFile()) { - firstError ??= 'Config path is not a regular file.' - continue - } - if (info.size > MAX_CONFIG_BYTES) { - firstError ??= `Config file is too large to import (${info.size} bytes, limit ${MAX_CONFIG_BYTES}).` +const GHOSTTY_IMPORTER: TerminalConfigImporter = { + appName: 'Ghostty', + pickerTitle: () => translateMain('native.dialog.importGhosttyConfig', 'Import Ghostty Config'), + discover: findGhosttyConfigPaths, + load: async (configPaths) => { + const config: GhosttyConfig = {} + const readPaths: string[] = [] + let firstError: string | null = null + for (const configPath of configPaths) { + const read = await readConfigFile(configPath) + if (!read.ok) { + firstError ??= read.error continue } - content = await readFile(configPath, 'utf-8') - } catch (err) { - const message = err instanceof Error ? err.message : 'Could not read config file' - firstError ??= `Could not read config: ${message}` - continue + mergeParsedConfig(config, parseGhosttyConfig(read.content)) + readPaths.push(configPath) } - mergeParsedConfig(parsed, parseGhosttyConfig(content)) - readPaths.push(configPath) - } - - if (readPaths.length === 0) { + return { config, readPaths, firstError } + }, + map: async (config, { currentSettings, pickedConfigDir }): Promise => { + const { theme: rawTheme, ...configKeys } = config + const mapped = mapGhosttyToOrca(configKeys, platform() === 'darwin') + const theme = await themeReferencePatch( + rawTheme, + mapped.diff, + pickedConfigDir, + currentSettings + ) return { - found: false, - diff: {}, - unsupportedKeys: [], - error: firstError ?? 'Could not read config' - } - } - - const { theme: rawTheme, ...configKeys } = parsed - const { diff: rawDiff, unsupportedKeys: mappedUnsupportedKeys } = mapGhosttyToOrca( - configKeys, - platform() === 'darwin' - ) - const currentSettings = store.getSettings() - const theme = await themeReferencePatch( - rawTheme, - rawDiff, - validatedSource.kind === 'chooseFile' ? path.dirname(readPaths[0]) : undefined, - currentSettings - ) - Object.assign(rawDiff, theme.diff) - const unsupportedKeys = [...mappedUnsupportedKeys, ...theme.unsupportedKeys] - - const actualDiff: Partial = {} - for (const key of Object.keys(rawDiff) as (keyof typeof rawDiff)[]) { - const value = rawDiff[key] - if (value !== undefined && !valuesEqual(currentSettings[key] ?? emptyLike(value), value)) { - // Why: TypeScript's strict assignment checking for Partial[K] requires - // a cast because GlobalSettings has no index signature. - ;(actualDiff as Record)[key] = value + diff: { ...mapped.diff, ...theme.diff }, + unsupportedKeys: [...mapped.unsupportedKeys, ...theme.unsupportedKeys], + ...(theme.themeNames ? { terminalThemes: theme.themeNames } : {}) } } +} - return { - found: true, - configPath: readPaths[0], - configPaths: readPaths, - diff: actualDiff, - unsupportedKeys, - ...(theme.themeNames ? { terminalThemes: theme.themeNames } : {}) - } +export function previewGhosttyImport( + store: Store, + source?: unknown, + webContents?: WebContents +): Promise { + return previewTerminalConfigImport(GHOSTTY_IMPORTER, store, source, webContents) } diff --git a/src/main/ghostty/mapper.ts b/src/main/ghostty/mapper.ts index c06536ff75cf..4d26412352b6 100644 --- a/src/main/ghostty/mapper.ts +++ b/src/main/ghostty/mapper.ts @@ -1,4 +1,4 @@ -import type { GhosttyImportPreview, GlobalSettings } from '../../shared/global-settings-types' +import type { GlobalSettings } from '../../shared/global-settings-types' import type { TerminalColorOverrides } from '../../shared/terminal-color-overrides' import { HEX_COLOR_RE } from '../../shared/color-validation' import { parsePaddingValue, parseStrictInt } from './numeric-config-values' @@ -334,5 +334,3 @@ export function mapGhosttyToOrca( return { diff, unsupportedKeys } } - -export type { GhosttyImportPreview } diff --git a/src/main/ipc/settings-import-handlers.ts b/src/main/ipc/settings-import-handlers.ts new file mode 100644 index 000000000000..7a3d4627c1a3 --- /dev/null +++ b/src/main/ipc/settings-import-handlers.ts @@ -0,0 +1,18 @@ +import { ipcMain } from 'electron' +import type { Store } from '../persistence/loading-store/store' +import { previewGhosttyImport } from '../ghostty/index' +import { previewKittyImport } from '../kitty' +import { previewWarpThemeImport } from '../warp-themes' + +// Omitted sources fall back to each importer's auto-discovery default. +export function registerSettingsImportHandlers(store: Store): void { + ipcMain.handle('settings:previewGhosttyImport', (event, source?: unknown) => + previewGhosttyImport(store, source, event.sender) + ) + ipcMain.handle('settings:previewKittyImport', (event, source?: unknown) => + previewKittyImport(store, source, event.sender) + ) + ipcMain.handle('settings:previewWarpThemeImport', (event, source?: unknown) => + previewWarpThemeImport(store, source, event.sender) + ) +} diff --git a/src/main/ipc/settings.ts b/src/main/ipc/settings.ts index 1c3d701170bc..18bbee0f1631 100644 --- a/src/main/ipc/settings.ts +++ b/src/main/ipc/settings.ts @@ -4,8 +4,7 @@ import type { Store } from '../persistence/loading-store/store' import type { GlobalSettings } from '../../shared/global-settings-types' import type { PersistedState } from '../../shared/persisted-state-types' import { listSystemFontFamilies } from '../system-fonts' -import { previewGhosttyImport } from '../ghostty/index' -import { previewWarpThemeImport } from '../warp-themes' +import { registerSettingsImportHandlers } from './settings-import-handlers' import { setMainUiLanguage } from '../i18n/main-i18n' import { rebuildAppMenu } from '../menu/register-app-menu' import { rebuildSystemTrayMenu } from '../tray/system-tray' @@ -308,14 +307,7 @@ export function registerSettingsHandlers( ipcMain.handle('settings:listFonts', () => listSystemFontFamilies()) - // Omitted sources fall back to each importer's auto-discovery default. - ipcMain.handle('settings:previewGhosttyImport', (event, source?: unknown) => - previewGhosttyImport(store, source, event.sender) - ) - - ipcMain.handle('settings:previewWarpThemeImport', (event, source?: unknown) => - previewWarpThemeImport(store, source, event.sender) - ) + registerSettingsImportHandlers(store) ipcMain.handle('cache:getGitHub', () => { return store.getGitHubCache() diff --git a/src/main/kitty/discovery.ts b/src/main/kitty/discovery.ts new file mode 100644 index 000000000000..d8f8669ae832 --- /dev/null +++ b/src/main/kitty/discovery.ts @@ -0,0 +1,44 @@ +import { homedir, platform } from 'node:os' +import path from 'node:path' +import { stat } from 'node:fs/promises' + +function expandHome(dir: string, home: string): string { + return dir === '~' || dir.startsWith('~/') ? path.posix.join(home, dir.slice(1)) : dir +} + +// Kitty's ConfigDirForName order; Kitty has no Windows build, so only an explicit directory applies there. +export function getKittyConfigPaths(): string[] { + const home = homedir() + const explicitDir = process.env.KITTY_CONFIG_DIRECTORY + if (explicitDir) { + return [path.join(expandHome(explicitDir, home), 'kitty.conf')] + } + const plat = platform() + if (plat === 'win32') { + return [] + } + const roots = [ + process.env.XDG_CONFIG_HOME, + ...(process.env.XDG_CONFIG_DIRS ?? '').split(':'), + '~/.config', + ...(plat === 'darwin' ? ['~/Library/Preferences'] : []) + ] + const dirs = roots + .filter((root): root is string => Boolean(root)) + .map((root) => path.posix.join(expandHome(root, home), 'kitty')) + return [...new Set(dirs)].map((dir) => path.posix.join(dir, 'kitty.conf')) +} + +/** Kitty reads a single kitty.conf: the first location that has one. */ +export async function findKittyConfigPaths(): Promise { + for (const configPath of getKittyConfigPaths()) { + try { + if ((await stat(configPath)).isFile()) { + return [configPath] + } + } catch { + // Unreadable candidates must not prevent probing the remaining locations. + } + } + return [] +} diff --git a/src/main/kitty/index.ts b/src/main/kitty/index.ts new file mode 100644 index 000000000000..750b6e946066 --- /dev/null +++ b/src/main/kitty/index.ts @@ -0,0 +1,28 @@ +import { homedir, platform } from 'node:os' +import type { WebContents } from 'electron' +import type { TerminalConfigImportPreview } from '../../shared/terminal-config-import-preview' +import type { Store } from '../persistence/loading-store/store' +import { translateMain } from '../i18n/main-i18n' +import { + previewTerminalConfigImport, + type TerminalConfigImporter +} from '../terminal-config-import/preview' +import { findKittyConfigPaths } from './discovery' +import { mapKittyToOrca } from './mapper' +import { loadKittyConfig, type KittyConfig } from './parser' + +const KITTY_IMPORTER: TerminalConfigImporter = { + appName: 'Kitty', + pickerTitle: () => translateMain('native.dialog.importKittyConfig', 'Import Kitty Config'), + discover: findKittyConfigPaths, + load: (configPaths) => loadKittyConfig(configPaths[0] ?? '', homedir()), + map: async (config) => mapKittyToOrca(config, platform() === 'darwin') +} + +export function previewKittyImport( + store: Store, + source?: unknown, + webContents?: WebContents +): Promise { + return previewTerminalConfigImport(KITTY_IMPORTER, store, source, webContents) +} diff --git a/src/main/kitty/kitty-import.test.ts b/src/main/kitty/kitty-import.test.ts new file mode 100644 index 000000000000..eba8f11e84f5 --- /dev/null +++ b/src/main/kitty/kitty-import.test.ts @@ -0,0 +1,81 @@ +import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import path from 'node:path' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { mapKittyToOrca } from './mapper' +import { loadKittyConfig } from './parser' + +let dir: string + +beforeEach(async () => { + dir = await mkdtemp(path.join(tmpdir(), 'orca-kitty-import-')) +}) + +afterEach(async () => { + await rm(dir, { recursive: true, force: true }) +}) + +describe('Kitty config import', () => { + it('follows include, globinclude and continuation lines without running geninclude', async () => { + await mkdir(path.join(dir, 'themes')) + await writeFile( + path.join(dir, 'kitty.conf'), + [ + '# comment', + 'font_family family="JetBrains Mono" style=Regular', + 'font_size 13', + 'include current-theme.conf', + 'globinclude themes/*.conf', + 'geninclude make-colors.py', + 'map ctrl+c copy_to_clipboard', + 'window_padding_width 4', + '\\ 8', + 'include kitty.conf' + ].join('\n') + ) + await writeFile( + path.join(dir, 'current-theme.conf'), + 'background #1e1e2e\nforeground #cdd6f4\ncolor1 #f38ba8\ncursor_shape beam\n' + ) + await writeFile( + path.join(dir, 'themes', 'override.conf'), + 'color1 #ff0000\nbackground_opacity 0.9\n' + ) + + const { config, readPaths } = await loadKittyConfig(path.join(dir, 'kitty.conf'), dir) + const { diff, unsupportedKeys } = mapKittyToOrca(config, true) + + expect(readPaths).toEqual([ + path.join(dir, 'kitty.conf'), + path.join(dir, 'current-theme.conf'), + path.join(dir, 'themes', 'override.conf') + ]) + expect(diff).toEqual({ + terminalFontFamily: 'JetBrains Mono', + terminalFontSize: 13, + terminalCursorStyle: 'bar', + terminalBackgroundOpacity: 0.9, + terminalPaddingX: 8, + terminalPaddingY: 4, + terminalColorOverrides: { background: '#1e1e2e', foreground: '#cdd6f4', red: '#ff0000' } + }) + expect(unsupportedKeys).toEqual(['geninclude', 'map']) + }) + + it('reports values Orca cannot represent instead of guessing', () => { + const options = new Map([ + ['font_family', 'monospace'], + ['cursor_text_color', 'background'], + ['cursor_shape', 'hollow'], + ['macos_option_as_alt', 'left'] + ]) + const { diff, unsupportedKeys } = mapKittyToOrca({ options, unsupportedKeys: [] }, false) + expect(diff).toEqual({}) + expect(unsupportedKeys).toEqual([ + 'font_family', + 'cursor_text_color', + 'cursor_shape', + 'macos_option_as_alt' + ]) + }) +}) diff --git a/src/main/kitty/mapper.ts b/src/main/kitty/mapper.ts new file mode 100644 index 000000000000..db56b65840e2 --- /dev/null +++ b/src/main/kitty/mapper.ts @@ -0,0 +1,152 @@ +import type { GlobalSettings } from '../../shared/global-settings-types' +import type { TerminalColorOverrides } from '../../shared/terminal-color-overrides' +import { + normalizeTerminalHexColor, + TERMINAL_ANSI_COLOR_KEYS +} from '../../shared/terminal-custom-themes' +import type { KittyConfig } from './parser' + +const COLOR_KEYS: Record = { + foreground: 'foreground', + background: 'background', + cursor: 'cursor', + cursor_text_color: 'cursorAccent', + selection_foreground: 'selectionForeground', + selection_background: 'selectionBackground' +} + +const CURSOR_SHAPES: Record = { + block: 'block', + beam: 'bar', + underline: 'underline' +} + +const OPTION_AS_ALT: Record = { + yes: 'true', + both: 'true', + no: 'false', + none: 'false', + left: 'left', + right: 'right' +} + +function parseNumber(value: string): number | null { + const num = Number(value) + return value.trim() !== '' && Number.isFinite(num) ? num : null +} + +// `font_family` is a bare name or Kitty 0.36's `family="Name" style=...` spec; `monospace` means "system default". +function kittyFontFamily(value: string): string | null { + const spec = /(?:^|\s)family=(?:"([^"]+)"|'([^']+)'|(\S+))/.exec(value) + const family = (spec ? (spec[1] ?? spec[2] ?? spec[3]) : value).trim() + return family && family !== 'monospace' && family !== 'auto' ? family : null +} + +// One value pads every side; two are vertical then horizontal; three are top, horizontal, bottom; four go clockwise from top. +function kittyPadding(value: string): { x: number; y: number } | null { + const sides = value.split(/\s+/).map(parseNumber) + if (sides.length === 0 || sides.length > 4 || sides.some((side) => side === null || side < 0)) { + return null + } + const [top = 0, right = top, bottom = top, left = right] = sides.map((side) => side ?? 0) + return { x: (left + right) / 2, y: (top + bottom) / 2 } +} + +function mapOption( + key: string, + value: string, + isMacOS: boolean, + diff: Partial, + colors: TerminalColorOverrides +): boolean { + const colorKey = + COLOR_KEYS[key] ?? TERMINAL_ANSI_COLOR_KEYS[Number(/^color(\d+)$/.exec(key)?.[1])] + if (colorKey) { + const color = normalizeTerminalHexColor(value) + if (color) { + colors[colorKey] = color + } + return color !== null + } + switch (key) { + case 'font_family': { + const family = kittyFontFamily(value) + if (family) { + diff.terminalFontFamily = family + } + return family !== null + } + case 'font_size': { + const size = parseNumber(value) + if (size !== null && size > 0) { + diff.terminalFontSize = size + } + return size !== null && size > 0 + } + case 'background_opacity': { + const opacity = parseNumber(value) + if (opacity !== null && opacity >= 0 && opacity <= 1) { + diff.terminalBackgroundOpacity = opacity + return true + } + return false + } + case 'background_blur': { + const radius = parseNumber(value) + if (radius !== null && radius >= 0) { + diff.windowMaterial = radius > 0 ? 'blur' : 'translucent' + } + return radius !== null && radius >= 0 + } + case 'cursor_shape': { + const style = CURSOR_SHAPES[value] + if (style) { + diff.terminalCursorStyle = style + } + return style !== undefined + } + case 'cursor_blink_interval': { + // The first token is seconds (0 disables, negative uses the OS rate); easing curves may follow. + const interval = parseNumber(value.split(/\s+/)[0] ?? '') + if (interval !== null) { + diff.terminalCursorBlink = interval !== 0 + } + return interval !== null + } + case 'window_padding_width': { + const padding = kittyPadding(value) + if (padding) { + diff.terminalPaddingX = padding.x + diff.terminalPaddingY = padding.y + } + return padding !== null + } + case 'macos_option_as_alt': { + const optionAsAlt = isMacOS ? OPTION_AS_ALT[value] : undefined + if (optionAsAlt) { + diff.terminalMacOptionAsAlt = optionAsAlt + } + return optionAsAlt !== undefined + } + default: + return false + } +} + +export function mapKittyToOrca( + config: KittyConfig, + isMacOS: boolean +): { diff: Partial; unsupportedKeys: string[] } { + const diff: Partial = {} + const colors: TerminalColorOverrides = {} + const unsupportedKeys = [...config.unsupportedKeys] + for (const [key, value] of config.options) { + if (!mapOption(key, value, isMacOS, diff, colors)) { + unsupportedKeys.push(key) + } + } + if (Object.keys(colors).length > 0) { + diff.terminalColorOverrides = colors + } + return { diff, unsupportedKeys } +} diff --git a/src/main/kitty/parser.ts b/src/main/kitty/parser.ts new file mode 100644 index 000000000000..ec6382181fb6 --- /dev/null +++ b/src/main/kitty/parser.ts @@ -0,0 +1,149 @@ +import { platform } from 'node:os' +import path from 'node:path' +import { readdir, stat } from 'node:fs/promises' +import { readConfigFile } from '../terminal-config-import/config-file-reader' + +// Includes can fan out through globs; bound how much one import may read. +const MAX_INCLUDED_FILES = 64 +const AUTO_THEME_FILES = [ + 'dark-theme.auto.conf', + 'light-theme.auto.conf', + 'no-preference-theme.auto.conf' +] +const KEY_RE = /^([a-zA-Z][a-zA-Z0-9_-]*)\s+(.+)$/ + +/** Settings keyed by Kitty option name; later lines win, as in Kitty. */ +export type KittyConfig = { + options: Map + unsupportedKeys: string[] +} + +export type LoadedKittyConfig = { + config: KittyConfig + readPaths: string[] + firstError: string | null +} + +// Kitty joins a line that starts with `\` onto the previous line; `#` only starts whole-line comments. +export function parseKittyLines(content: string): [key: string, value: string][] { + const lines: string[] = [] + for (const rawLine of content.split(/\r?\n/)) { + const line = rawLine.trimStart() + if (line.startsWith('\\') && lines.length > 0) { + lines[lines.length - 1] += line.slice(1) + } else { + lines.push(line) + } + } + const entries: [string, string][] = [] + for (const line of lines) { + const match = KEY_RE.exec(line.trim()) + if (!line.startsWith('#') && match) { + entries.push([match[1], match[2].trim()]) + } + } + return entries +} + +function expandIncludePath(value: string, baseDir: string, home: string): string { + const kittyOs = platform() === 'darwin' ? 'macos' : platform() + const expanded = value + .replace(/^~(?=$|\/)/, home) + .replace( + /\$\{(\w+)\}|\$(\w+)/g, + (whole, braced: string | undefined, bare: string | undefined) => { + const name = braced ?? bare ?? '' + return name === 'KITTY_OS' ? kittyOs : (process.env[name] ?? whole) + } + ) + return path.isAbsolute(expanded) ? expanded : path.join(baseDir, expanded) +} + +// Kitty globs with pathlib; Orca supports wildcards in the file name, the common `themes/*.conf` form. +async function expandGlobInclude(pattern: string): Promise { + const dir = path.dirname(pattern) + if (/[*?[]/.test(dir)) { + return null + } + const source = path + .basename(pattern) + .replace(/[.+^${}()|\\]/g, '\\$&') + .replaceAll('*', '.*') + .replaceAll('?', '.') + const nameRe = new RegExp(`^${source}$`) + try { + const names = await readdir(dir) + return names + .filter((name) => nameRe.test(name)) + .sort() + .map((name) => path.join(dir, name)) + } catch { + return [] + } +} + +async function isFile(filePath: string): Promise { + try { + return (await stat(filePath)).isFile() + } catch { + return false + } +} + +export async function loadKittyConfig(entryPath: string, home: string): Promise { + const options = new Map() + const unsupportedKeys = new Set() + const readPaths: string[] = [] + const seen = new Set() + let firstError: string | null = null + + async function loadFile(filePath: string): Promise { + const key = path.normalize(filePath) + if (seen.has(key)) { + return + } + if (seen.size >= MAX_INCLUDED_FILES) { + unsupportedKeys.add(`include (more than ${MAX_INCLUDED_FILES} files)`) + return + } + seen.add(key) + const read = await readConfigFile(filePath) + if (!read.ok) { + firstError ??= read.error + if (readPaths.length > 0) { + unsupportedKeys.add(`include (${path.basename(filePath)}: ${read.error})`) + } + return + } + readPaths.push(filePath) + const baseDir = path.dirname(filePath) + for (const [optionKey, value] of parseKittyLines(read.content)) { + if (optionKey === 'include') { + await loadFile(expandIncludePath(value, baseDir, home)) + } else if (optionKey === 'globinclude') { + const matches = await expandGlobInclude(expandIncludePath(value, baseDir, home)) + if (matches === null) { + unsupportedKeys.add('globinclude (wildcards in directory names)') + } + for (const match of matches ?? []) { + await loadFile(match) + } + } else if (optionKey === 'geninclude' || optionKey === 'envinclude') { + // geninclude runs a program and envinclude reads the environment; an import must do neither. + unsupportedKeys.add(optionKey) + } else { + options.delete(optionKey) + options.set(optionKey, value) + } + } + } + + await loadFile(entryPath) + // Kitty 0.38+ swaps these in by OS appearance, overriding the colors above; Orca does not import them yet. + for (const name of AUTO_THEME_FILES) { + if (await isFile(path.join(path.dirname(entryPath), name))) { + unsupportedKeys.add(`${name} (appearance-based theme)`) + } + } + return { config: { options, unsupportedKeys: [...unsupportedKeys] }, readPaths, firstError } +} diff --git a/src/main/terminal-config-import/config-file-reader.ts b/src/main/terminal-config-import/config-file-reader.ts new file mode 100644 index 000000000000..5249ac08398f --- /dev/null +++ b/src/main/terminal-config-import/config-file-reader.ts @@ -0,0 +1,26 @@ +import { readFile, stat } from 'node:fs/promises' + +// Bound config reads to avoid loading arbitrarily large files into main. +export const MAX_CONFIG_BYTES = 1_000_000 + +export type ConfigFileRead = { ok: true; content: string } | { ok: false; error: string } + +export async function readConfigFile(configPath: string): Promise { + try { + const info = await stat(configPath) + // Picked paths can be devices or FIFOs whose zero size would slip past the byte limit. + if (!info.isFile()) { + return { ok: false, error: 'Config path is not a regular file.' } + } + if (info.size > MAX_CONFIG_BYTES) { + return { + ok: false, + error: `Config file is too large to import (${info.size} bytes, limit ${MAX_CONFIG_BYTES}).` + } + } + return { ok: true, content: await readFile(configPath, 'utf-8') } + } catch (err) { + const message = err instanceof Error ? err.message : 'Could not read config file' + return { ok: false, error: `Could not read config: ${message}` } + } +} diff --git a/src/main/terminal-config-import/preview.ts b/src/main/terminal-config-import/preview.ts new file mode 100644 index 000000000000..c2559db15b43 --- /dev/null +++ b/src/main/terminal-config-import/preview.ts @@ -0,0 +1,94 @@ +import path from 'node:path' +import type { WebContents } from 'electron' +import type { GlobalSettings } from '../../shared/global-settings-types' +import type { TerminalConfigImportPreview } from '../../shared/terminal-config-import-preview' +import type { Store } from '../persistence/loading-store/store' +import { validateImportSource } from '../import-source-validation' +import { chooseTerminalConfigFile } from './choose-config-file' +import { settingsChanges } from './settings-changes' + +const IMPORT_SOURCE_KINDS = ['auto', 'chooseFile'] as const + +export type LoadedTerminalConfig = { + config: Config + /** Files that were read, in load order; empty when none could be read. */ + readPaths: string[] + firstError: string | null +} + +export type TerminalConfigMapping = Pick< + TerminalConfigImportPreview, + 'diff' | 'unsupportedKeys' | 'terminalThemes' +> + +export type TerminalConfigMappingContext = { + currentSettings: GlobalSettings + /** Directory of a file the user picked, for resolving theme files beside it. */ + pickedConfigDir?: string +} + +/** One terminal app's half of the shared discover → parse → map → preview pipeline. */ +export type TerminalConfigImporter = { + appName: string + pickerTitle: () => string + discover: () => Promise + load: (configPaths: string[]) => Promise> + map: (config: Config, context: TerminalConfigMappingContext) => Promise +} + +export async function previewTerminalConfigImport( + importer: TerminalConfigImporter, + store: Store, + source: unknown = { kind: 'auto' }, + webContents?: WebContents +): Promise { + const validatedSource = validateImportSource(source, IMPORT_SOURCE_KINDS) + if (!validatedSource) { + return { + found: false, + diff: {}, + unsupportedKeys: [], + error: `Invalid ${importer.appName} import source.` + } + } + + let pickedConfigDir: string | undefined + let configPaths: string[] + if (validatedSource.kind === 'chooseFile') { + const picked = await chooseTerminalConfigFile(importer.pickerTitle(), webContents) + if (picked === null) { + return { found: false, canceled: true, diff: {}, unsupportedKeys: [] } + } + pickedConfigDir = path.dirname(picked) + configPaths = [picked] + } else { + configPaths = await importer.discover() + } + if (configPaths.length === 0) { + return { found: false, diff: {}, unsupportedKeys: [] } + } + + const { config, readPaths, firstError } = await importer.load(configPaths) + if (readPaths.length === 0) { + return { + found: false, + diff: {}, + unsupportedKeys: [], + error: firstError ?? 'Could not read config' + } + } + + const currentSettings = store.getSettings() + const { diff, unsupportedKeys, terminalThemes } = await importer.map(config, { + currentSettings, + pickedConfigDir + }) + return { + found: true, + configPath: readPaths[0], + configPaths: readPaths, + diff: settingsChanges(currentSettings, diff), + unsupportedKeys, + ...(terminalThemes ? { terminalThemes } : {}) + } +} diff --git a/src/main/terminal-config-import/settings-changes.ts b/src/main/terminal-config-import/settings-changes.ts new file mode 100644 index 000000000000..cc5f247f27a3 --- /dev/null +++ b/src/main/terminal-config-import/settings-changes.ts @@ -0,0 +1,41 @@ +import type { GlobalSettings } from '../../shared/global-settings-types' + +// Compare nested values structurally with sorted keys while preserving meaningful array order. +function stableStringify(v: unknown): string { + if (v === null || typeof v !== 'object') { + return JSON.stringify(v) + } + if (Array.isArray(v)) { + return `[${v.map(stableStringify).join(',')}]` + } + const entries = Object.entries(v).sort(([ka], [kb]) => ka.localeCompare(kb)) + return `{${entries.map(([k, val]) => `${JSON.stringify(k)}:${stableStringify(val)}`).join(',')}}` +} + +function valuesEqual(a: unknown, b: unknown): boolean { + if (a === b) { + return true + } + if (typeof a === 'object' && a !== null && typeof b === 'object' && b !== null) { + return stableStringify(a) === stableStringify(b) + } + return false +} + +// An unset object setting already matches an import that clears it. +function emptyLike(value: unknown): unknown { + return typeof value === 'object' && value !== null && !Array.isArray(value) ? {} : undefined +} + +/** The part of an imported settings patch that would actually change the current settings. */ +export function settingsChanges( + current: GlobalSettings, + patch: Partial +): Partial { + return Object.fromEntries( + Object.entries(patch).filter(([key, value]) => { + const currentValue: unknown = key in current ? Reflect.get(current, key) : undefined + return value !== undefined && !valuesEqual(currentValue ?? emptyLike(value), value) + }) + ) +} diff --git a/src/preload/api/settings-api.ts b/src/preload/api/settings-api.ts index 7d725c243879..dd80978bc91b 100644 --- a/src/preload/api/settings-api.ts +++ b/src/preload/api/settings-api.ts @@ -3,11 +3,11 @@ import type { WarpThemeImportPreview, WarpThemeImportSource } from '../../shared/terminal-custom-themes' +import type { GlobalSettings } from '../../shared/global-settings-types' import type { - GhosttyImportPreview, - GhosttyImportSource, - GlobalSettings -} from '../../shared/global-settings-types' + TerminalConfigImportPreview, + TerminalConfigImportSource +} from '../../shared/terminal-config-import-preview' export type SettingsApi = { get: () => Promise @@ -19,7 +19,10 @@ export type SettingsApi = { }) => Promise updatePRBotAuthorOverride: (args: { author: string; isBot: boolean }) => Promise listFonts: () => Promise - previewGhosttyImport: (source?: GhosttyImportSource) => Promise + previewGhosttyImport: ( + source?: TerminalConfigImportSource + ) => Promise + previewKittyImport: (source?: TerminalConfigImportSource) => Promise previewWarpThemeImport: (source: WarpThemeImportSource) => Promise onChanged: (callback: (updates: Partial) => void) => () => void } diff --git a/src/preload/api/settings-bridge.ts b/src/preload/api/settings-bridge.ts index 557fd41a364f..28d96f279470 100644 --- a/src/preload/api/settings-bridge.ts +++ b/src/preload/api/settings-bridge.ts @@ -1,5 +1,8 @@ import { ipcRenderer } from 'electron' -import type { GhosttyImportPreview, GhosttyImportSource } from '../../shared/global-settings-types' +import type { + TerminalConfigImportPreview, + TerminalConfigImportSource +} from '../../shared/terminal-config-import-preview' import type { WarpThemeImportPreview, WarpThemeImportSource @@ -21,9 +24,14 @@ export const settingsApi = { listFonts: (): Promise => ipcRenderer.invoke('settings:listFonts'), - previewGhosttyImport: (source?: GhosttyImportSource): Promise => + previewGhosttyImport: ( + source?: TerminalConfigImportSource + ): Promise => ipcRenderer.invoke('settings:previewGhosttyImport', source), + previewKittyImport: (source?: TerminalConfigImportSource): Promise => + ipcRenderer.invoke('settings:previewKittyImport', source), + previewWarpThemeImport: (source: WarpThemeImportSource): Promise => ipcRenderer.invoke('settings:previewWarpThemeImport', source), diff --git a/src/renderer/src/components/onboarding/GhosttyDiscoveryRow.tsx b/src/renderer/src/components/onboarding/GhosttyDiscoveryRow.tsx index 369d358af612..6ba4f74ac3f6 100644 --- a/src/renderer/src/components/onboarding/GhosttyDiscoveryRow.tsx +++ b/src/renderer/src/components/onboarding/GhosttyDiscoveryRow.tsx @@ -1,5 +1,5 @@ import { Check } from 'lucide-react' -import type { GhosttyImportPreview } from '../../../../shared/global-settings-types' +import type { TerminalConfigImportPreview } from '../../../../shared/terminal-config-import-preview' import ghosttyIcon from '../../../../../resources/ghostty.svg' import { translate } from '@/i18n/i18n' import type { DiscoveryState } from './ThemeStep' @@ -13,7 +13,7 @@ export function GhosttyDiscoveryRow({ discovery: DiscoveryState importing: boolean disabled: boolean - onImport: (preview: GhosttyImportPreview) => void + onImport: (preview: TerminalConfigImportPreview) => void }) { // Non-Mac discovery remains idle; hide it instead of leaving a permanent looking placeholder. if (discovery.status === 'absent' || discovery.status === 'idle') { diff --git a/src/renderer/src/components/onboarding/ThemeStep.tsx b/src/renderer/src/components/onboarding/ThemeStep.tsx index ff4fbaf71ae4..743199aa39a1 100644 --- a/src/renderer/src/components/onboarding/ThemeStep.tsx +++ b/src/renderer/src/components/onboarding/ThemeStep.tsx @@ -6,11 +6,14 @@ import { cn } from '@/lib/utils' import { track } from '@/lib/telemetry' import { useMountedRef } from '@/hooks/useMountedRef' import { GhosttyDiscoveryRow } from './GhosttyDiscoveryRow' -import type { GhosttyImportPreview, GlobalSettings } from '../../../../shared/global-settings-types' +import type { GlobalSettings } from '../../../../shared/global-settings-types' import type { DiscoveryStatusEmitted } from '../../../../shared/onboarding-state-types' import { i18n, translate } from '@/i18n/i18n' import { ChromePreview } from './theme-chrome-preview' -import { ghosttyImportSettingsUpdate } from '../../../../shared/ghostty-import-preview' +import { + terminalConfigImportSettingsUpdate, + type TerminalConfigImportPreview +} from '../../../../shared/terminal-config-import-preview' import { getSystemPrefersDark } from '@/lib/terminal-theme' type ThemeStepProps = { @@ -34,7 +37,7 @@ export function applyOnboardingThemeSelection( export type DiscoveryState = | { status: 'idle' } | { status: 'detecting' } - | { status: 'found'; preview: GhosttyImportPreview; fields: string[] } + | { status: 'found'; preview: TerminalConfigImportPreview; fields: string[] } | { status: 'imported'; fields: string[] } | { status: 'absent' } type _DiscoveryStatusEmittedSync = @@ -109,7 +112,7 @@ export function ThemeStep({ theme, onThemeChange, settings, updateSettings }: Th } }, []) - const importGhostty = async (preview: GhosttyImportPreview) => { + const importGhostty = async (preview: TerminalConfigImportPreview) => { if (!settings || importing) { return } @@ -130,7 +133,9 @@ export function ThemeStep({ theme, onThemeChange, settings, updateSettings }: Th track('onboarding_ghostty_import_failed', { reason: 'empty_diff' }) return } - await updateSettings(ghosttyImportSettingsUpdate(settings, resolved, getSystemPrefersDark())) + await updateSettings( + terminalConfigImportSettingsUpdate(settings, resolved, getSystemPrefersDark()) + ) // Sync the controller’s local theme so Continue cannot overwrite the imported theme. if (resolved.diff.theme && mountedRef.current) { onThemeChange(resolved.diff.theme) diff --git a/src/renderer/src/components/settings/AppearancePane.test.tsx b/src/renderer/src/components/settings/AppearancePane.test.tsx index fd002799bca6..abbad96afbe8 100644 --- a/src/renderer/src/components/settings/AppearancePane.test.tsx +++ b/src/renderer/src/components/settings/AppearancePane.test.tsx @@ -163,7 +163,7 @@ async function renderAppearancePane( terminalFontSuggestions={[]} onRequestFontSuggestions={options.onRequestFontSuggestions} systemPrefersDark={false} - ghostty={createGhosttyStub() as never} + terminalConfigImport={createGhosttyStub() as never} warpThemes={createWarpThemesStub() as never} /> @@ -192,7 +192,7 @@ async function rerenderAppearancePane( fontSuggestions={[]} terminalFontSuggestions={[]} systemPrefersDark={false} - ghostty={createGhosttyStub() as never} + terminalConfigImport={createGhosttyStub() as never} warpThemes={createWarpThemesStub() as never} /> diff --git a/src/renderer/src/components/settings/AppearancePane.tsx b/src/renderer/src/components/settings/AppearancePane.tsx index a6f56d8779fa..04c1c1c21921 100644 --- a/src/renderer/src/components/settings/AppearancePane.tsx +++ b/src/renderer/src/components/settings/AppearancePane.tsx @@ -29,7 +29,7 @@ import { import { getReduceVisualEffectsEntries } from './appearance-reduce-visual-effects-search' import { getTerminalAppearanceSearchEntries } from './terminal-search' import { TerminalAppearanceSection } from './TerminalAppearanceSection' -import type { UseGhosttyImportReturn } from './useGhosttyImport' +import type { UseTerminalConfigImportReturn } from './useTerminalConfigImport' import type { UseWarpThemeImportReturn } from './useWarpThemeImport' import { AppIconSelector } from './AppIconSelector' import { normalizeAppIconId } from '../../../../shared/app-icon' @@ -52,7 +52,7 @@ type AppearancePaneProps = { terminalFontSuggestions: string[] onRequestFontSuggestions?: () => void systemPrefersDark: boolean - ghostty: UseGhosttyImportReturn + terminalConfigImport: UseTerminalConfigImportReturn warpThemes: UseWarpThemeImportReturn } @@ -72,7 +72,7 @@ export function AppearancePane({ terminalFontSuggestions, onRequestFontSuggestions, systemPrefersDark, - ghostty, + terminalConfigImport, warpThemes }: AppearancePaneProps): React.JSX.Element { const searchQuery = useAppStore((state) => state.settingsSearchQuery) @@ -244,7 +244,7 @@ export function AppearancePane({ systemPrefersDark={systemPrefersDark} terminalFontSuggestions={terminalFontSuggestions} onRequestFontSuggestions={onRequestFontSuggestions} - ghostty={ghostty} + terminalConfigImport={terminalConfigImport} warpThemes={warpThemes} forceVisiblePrimary={terminalLabelMatches} /> diff --git a/src/renderer/src/components/settings/TerminalAppearanceSection.ghostty.test.ts b/src/renderer/src/components/settings/TerminalAppearanceSection.config-import.test.ts similarity index 89% rename from src/renderer/src/components/settings/TerminalAppearanceSection.ghostty.test.ts rename to src/renderer/src/components/settings/TerminalAppearanceSection.config-import.test.ts index 1c692827d864..d245ed010fe2 100644 --- a/src/renderer/src/components/settings/TerminalAppearanceSection.ghostty.test.ts +++ b/src/renderer/src/components/settings/TerminalAppearanceSection.config-import.test.ts @@ -118,8 +118,8 @@ vi.mock('./TerminalWindowSection', () => ({ } })) -vi.mock('./GhosttyImportModal', () => ({ - GhosttyImportModal: function GhosttyImportModal() { +vi.mock('./TerminalConfigImportModal', () => ({ + TerminalConfigImportModal: function TerminalConfigImportModal() { return null } })) @@ -143,7 +143,8 @@ vi.mock('@/lib/terminal-theme', () => ({ resolvePaneStyleOptions: () => ({ inactivePaneOpacity: 0.8, dividerThicknessPx: 1 }) })) -const ghosttyMock = { +const configImportMock = { + format: 'ghostty' as const, open: true, preview: { found: true, @@ -277,13 +278,13 @@ function findTerminalThemeCatalogSection(node: unknown): ReactElementLike | null return null } -function findGhosttyImportModal(node: unknown): ReactElementLike | null { +function findTerminalConfigImportModal(node: unknown): ReactElementLike | null { if (node == null) { return null } if (Array.isArray(node)) { for (const child of node) { - const found = findGhosttyImportModal(child) + const found = findTerminalConfigImportModal(child) if (found) { return found } @@ -292,11 +293,11 @@ function findGhosttyImportModal(node: unknown): ReactElementLike | null { } const el = node as ReactElementLike const typeName = typeof el.type === 'function' ? el.type.name : String(el.type) - if (typeName === 'GhosttyImportModal') { + if (typeName === 'TerminalConfigImportModal') { return el } if (el.props?.children) { - return findGhosttyImportModal(el.props.children) + return findTerminalConfigImportModal(el.props.children) } return null } @@ -349,7 +350,7 @@ function findComponentByTypeName(node: unknown, targetTypeName: string): ReactEl return null } -describe('TerminalAppearanceSection ghostty import wiring', () => { +describe('TerminalAppearanceSection terminal config import wiring', () => { beforeEach(() => { mockStateValues.length = 0 mockSettingsSearchQuery = '' @@ -365,7 +366,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -374,7 +375,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { expect(importButton).toBeDefined() importButton?.onClick?.() - expect(ghosttyMock.handleClick).toHaveBeenCalled() + expect(configImportMock.handleClick).toHaveBeenCalled() }) it('passes shared theme import controls into the theme catalog on desktop', () => { @@ -383,7 +384,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -402,7 +403,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -415,7 +416,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -428,7 +429,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -441,7 +442,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -456,7 +457,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -471,7 +472,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -487,7 +488,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -502,7 +503,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) @@ -521,14 +522,14 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) expect(findTerminalThemeCatalogSection(element)?.props.showThemeImport).toBe(false) expect(findWarpThemeImportModal(element)).toBeNull() expect(findButtons(element).some((button) => button.text === 'Import from Ghostty')).toBe(false) - expect(findGhosttyImportModal(element)).toBeNull() + expect(findTerminalConfigImportModal(element)).toBeNull() }) it.each([false, true])( @@ -542,7 +543,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock, forceVisiblePrimary }) @@ -550,31 +551,31 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { expect(findButtons(element).some((button) => button.text === 'Import from Ghostty')).toBe( false ) - expect(findGhosttyImportModal(element)).toBeNull() + expect(findTerminalConfigImportModal(element)).toBeNull() if (!forceVisiblePrimary) { expect(findComponentByTypeName(element, 'SettingsSubsectionHeader')).toBeNull() } } ) - it('passes hook state to GhosttyImportModal', () => { + it('passes hook state to TerminalConfigImportModal', () => { const element = TerminalAppearanceSection({ settings: {} as never, updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) - const modal = findGhosttyImportModal(element) + const modal = findTerminalConfigImportModal(element) expect(modal).not.toBeNull() - expect(modal?.props.open).toBe(ghosttyMock.open) - expect(modal?.props.preview).toEqual(ghosttyMock.preview) - expect(modal?.props.loading).toBe(ghosttyMock.loading) - expect(modal?.props.applied).toBe(ghosttyMock.applied) - expect(modal?.props.onApply).toBe(ghosttyMock.handleApply) - expect(modal?.props.onOpenChange).toBe(ghosttyMock.handleOpenChange) + expect(modal?.props.open).toBe(configImportMock.open) + expect(modal?.props.preview).toEqual(configImportMock.preview) + expect(modal?.props.loading).toBe(configImportMock.loading) + expect(modal?.props.applied).toBe(configImportMock.applied) + expect(modal?.props.onApply).toBe(configImportMock.handleApply) + expect(modal?.props.onOpenChange).toBe(configImportMock.handleOpenChange) }) it('passes hook state to WarpThemeImportModal', () => { @@ -583,7 +584,7 @@ describe('TerminalAppearanceSection ghostty import wiring', () => { updateSettings: () => {}, systemPrefersDark: true, terminalFontSuggestions: [], - ghostty: ghosttyMock, + terminalConfigImport: configImportMock, warpThemes: warpThemesMock }) diff --git a/src/renderer/src/components/settings/TerminalAppearanceSection.tsx b/src/renderer/src/components/settings/TerminalAppearanceSection.tsx index 5caa326aa3fc..94edb87212ca 100644 --- a/src/renderer/src/components/settings/TerminalAppearanceSection.tsx +++ b/src/renderer/src/components/settings/TerminalAppearanceSection.tsx @@ -1,3 +1,4 @@ +import { Cat } from 'lucide-react' import { useState, type ReactNode } from 'react' import type { GlobalSettings } from '../../../../shared/global-settings-types' import type { TerminalThemeSlot } from '../../../../shared/terminal-color-overrides' @@ -12,7 +13,7 @@ import { getTerminalAdvancedTypographySearchEntries, getTerminalCursorSearchEntries, getTerminalDarkThemeSearchEntries, - getTerminalGhosttyImportSearchEntries, + getTerminalConfigImportSearchEntries, getTerminalLightThemeSearchEntries, getTerminalPaneAppearanceSearchEntries, getTerminalThemeTargetSearchEntries, @@ -31,8 +32,8 @@ import { TerminalWindowSection } from './TerminalWindowSection' import { TerminalCursorAppearanceSection } from './TerminalCursorAppearanceSection' import { TerminalPaneAppearanceSection } from './TerminalPaneAppearanceSection' import { AppearanceAdvancedDisclosure } from './AppearanceAdvancedDisclosure' -import { GhosttyImportModal } from './GhosttyImportModal' -import type { UseGhosttyImportReturn } from './useGhosttyImport' +import { TerminalConfigImportModal } from './TerminalConfigImportModal' +import type { UseTerminalConfigImportReturn } from './useTerminalConfigImport' import { WarpThemeImportModal } from './WarpThemeImportModal' import type { UseWarpThemeImportReturn } from './useWarpThemeImport' import { isWebClientLocation } from '@/lib/web-client-location' @@ -45,7 +46,7 @@ type TerminalAppearanceSectionProps = { systemPrefersDark: boolean terminalFontSuggestions: string[] onRequestFontSuggestions?: () => void - ghostty: UseGhosttyImportReturn + terminalConfigImport: UseTerminalConfigImportReturn warpThemes: UseWarpThemeImportReturn forceVisiblePrimary?: boolean } @@ -74,7 +75,7 @@ export function TerminalAppearanceSection({ systemPrefersDark, terminalFontSuggestions, onRequestFontSuggestions, - ghostty, + terminalConfigImport, warpThemes, forceVisiblePrimary = false }: TerminalAppearanceSectionProps): React.JSX.Element { @@ -86,7 +87,7 @@ export function TerminalAppearanceSection({ const darkThemeSearchEntries = getTerminalDarkThemeSearchEntries() const lightThemeSearchEntries = getTerminalLightThemeSearchEntries() const terminalTypographyEntries = getTerminalTypographySearchEntries() - const ghosttyImportEntries = getTerminalGhosttyImportSearchEntries() + const configImportEntries = getTerminalConfigImportSearchEntries() const themeCatalogSearchEntries = [ ...getTerminalThemeTargetSearchEntries(), ...darkThemeSearchEntries, @@ -114,16 +115,16 @@ export function TerminalAppearanceSection({ searchQuery, terminalTypographyEntries.slice(0, 2) ) - const ghosttyImportMatches = - showDesktopThemeImports && matchesSettingsSearch(searchQuery, ghosttyImportEntries) + const configImportMatches = + showDesktopThemeImports && matchesSettingsSearch(searchQuery, configImportEntries) const showPrimaryTypography = !isSearching || forceVisiblePrimary || primaryTypographyMatches || typographyMatches || - ghosttyImportMatches - const showGhosttyImport = - showDesktopThemeImports && (!isSearching || forceVisiblePrimary || ghosttyImportMatches) + configImportMatches + const showConfigImports = + showDesktopThemeImports && (!isSearching || forceVisiblePrimary || configImportMatches) const showTypographyAdvancedDisclosure = !isSearching || typographyMatches const advancedGroups = (colorOverrideSlot: TerminalThemeSlot) => @@ -191,19 +192,33 @@ export function TerminalAppearanceSection({ 'Terminal Typography' )} action={ - showGhosttyImport ? ( - + showConfigImports ? ( +
+ + +
) : null } /> @@ -276,16 +291,17 @@ export function TerminalAppearanceSection({ {showDesktopThemeImports ? ( <> - void - preview: GhosttyImportPreview | null + preview: TerminalConfigImportPreview | null loading: boolean choosingFile?: boolean onApply: () => void | Promise @@ -36,7 +40,11 @@ function formatDiffValue(value: unknown): string { } // Theme selections are opaque IDs, so show the theme names the import resolved instead. -function formatPreviewEntry(preview: GhosttyImportPreview, key: string, value: unknown): string { +function formatPreviewEntry( + preview: TerminalConfigImportPreview, + key: string, + value: unknown +): string { const themeNames = preview.terminalThemes ?? {} if (key === 'terminalThemeDark' && themeNames.dark) { return themeNames.dark @@ -54,7 +62,46 @@ function formatPreviewEntry(preview: GhosttyImportPreview, key: string, value: u return formatDiffValue(value) } -export function GhosttyImportModal({ +// Static branches keep every string visible to localization extraction. +function importCopy(format: TerminalConfigImportFormat): { + title: string + description: string + notFound: string +} { + if (format === 'kitty') { + return { + title: translate( + 'auto.components.settings.TerminalConfigImportModal.kitty_title', + 'Import from Kitty' + ), + description: translate( + 'auto.components.settings.TerminalConfigImportModal.kitty_description', + 'Review the settings that will be imported from your kitty.conf and the files it includes.' + ), + notFound: translate( + 'auto.components.settings.TerminalConfigImportModal.kitty_not_found', + 'No kitty.conf found on this computer. Choose a config file to import one from another location.' + ) + } + } + return { + title: translate( + 'auto.components.settings.GhosttyImportModal.d2f33670a9', + 'Import from Ghostty' + ), + description: translate( + 'auto.components.settings.GhosttyImportModal.2763b0c045', + 'Review the settings that will be imported from your Ghostty config.' + ), + notFound: translate( + 'auto.components.settings.GhosttyImportModal.not_found_choose_file', + 'No Ghostty config found on this computer. Choose a config file to import one from another location.' + ) + } +} + +export function TerminalConfigImportModal({ + format, open, onOpenChange, preview, @@ -64,7 +111,8 @@ export function GhosttyImportModal({ onChooseFile, applied = false, applyError = null -}: GhosttyImportModalProps): React.JSX.Element { +}: TerminalConfigImportModalProps): React.JSX.Element { + const copy = importCopy(format) const hasChanges = preview?.found === true && Object.keys(preview.diff).length > 0 const configPaths = preview?.configPaths ?? (preview?.configPath !== undefined ? [preview.configPath] : []) @@ -73,18 +121,8 @@ export function GhosttyImportModal({ - - {translate( - 'auto.components.settings.GhosttyImportModal.d2f33670a9', - 'Import from Ghostty' - )} - - - {translate( - 'auto.components.settings.GhosttyImportModal.2763b0c045', - 'Review the settings that will be imported from your Ghostty config.' - )} - + {copy.title} + {copy.description} {!applied ? ( @@ -188,12 +226,7 @@ export function GhosttyImportModal({ ) : preview.error ? (

{preview.error}

) : ( -

- {translate( - 'auto.components.settings.GhosttyImportModal.not_found_choose_file', - 'No Ghostty config found on this computer. Choose a config file to import one from another location.' - )} -

+

{copy.notFound}

)} diff --git a/src/renderer/src/components/settings/TerminalPane.pwsh.test.ts b/src/renderer/src/components/settings/TerminalPane.pwsh.test.ts index 090c44927c62..b4a48a0a760c 100644 --- a/src/renderer/src/components/settings/TerminalPane.pwsh.test.ts +++ b/src/renderer/src/components/settings/TerminalPane.pwsh.test.ts @@ -131,8 +131,8 @@ vi.mock('./TerminalWindowSection', () => ({ } })) -vi.mock('./GhosttyImportModal', () => ({ - GhosttyImportModal: function GhosttyImportModal() { +vi.mock('./TerminalConfigImportModal', () => ({ + TerminalConfigImportModal: function TerminalConfigImportModal() { return null } })) diff --git a/src/renderer/src/components/settings/settings-interface-secondary-section-renderers.tsx b/src/renderer/src/components/settings/settings-interface-secondary-section-renderers.tsx index 3af28250340b..6677179b87f3 100644 --- a/src/renderer/src/components/settings/settings-interface-secondary-section-renderers.tsx +++ b/src/renderer/src/components/settings/settings-interface-secondary-section-renderers.tsx @@ -29,7 +29,7 @@ export function renderAppearanceSettingsSection(context: SettingsRenderContext): terminalFontSuggestions={model.terminalFontSuggestions} onRequestFontSuggestions={interactions.requestFontSuggestions} systemPrefersDark={model.systemPrefersDark} - ghostty={model.ghostty} + terminalConfigImport={model.terminalConfigImport} warpThemes={model.warpThemes} /> ) : null} diff --git a/src/renderer/src/components/settings/terminal-advanced-platform-search.ts b/src/renderer/src/components/settings/terminal-advanced-platform-search.ts index c210dbc40eb9..e49040245003 100644 --- a/src/renderer/src/components/settings/terminal-advanced-platform-search.ts +++ b/src/renderer/src/components/settings/terminal-advanced-platform-search.ts @@ -111,7 +111,7 @@ export const getTerminalMacYenSearchEntries = createLocalizedCatalog(() => [ } ]) -export const getTerminalGhosttyImportSearchEntries = createLocalizedCatalog(() => [ +export const getTerminalConfigImportSearchEntries = createLocalizedCatalog(() => [ { title: translate('auto.components.settings.terminal.search.a979df0083', 'Import from Ghostty'), description: translate( @@ -127,5 +127,20 @@ export const getTerminalGhosttyImportSearchEntries = createLocalizedCatalog(() = ...translateSearchKeyword('auto.components.settings.terminal.search.2ade3ea490', 'config'), ...translateSearchKeyword('auto.components.settings.terminal.search.10f9fb6fea', 'settings') ] + }, + { + title: translate('auto.components.settings.terminal.search.kitty_import', 'Import from Kitty'), + description: translate( + 'auto.components.settings.terminal.search.kitty_import_description', + 'One-time import of supported settings from kitty.conf.' + ), + keywords: [ + // Keep product names searchable without translation. + 'Kitty', + 'kitty', + 'kitty.conf', + ...translateSearchKeyword('auto.components.settings.terminal.search.fd752b3cac', 'import'), + ...translateSearchKeyword('auto.components.settings.terminal.search.2ade3ea490', 'config') + ] } ]) diff --git a/src/renderer/src/components/settings/terminal-search.ts b/src/renderer/src/components/settings/terminal-search.ts index f6ddd70c307a..31a53b2f9331 100644 --- a/src/renderer/src/components/settings/terminal-search.ts +++ b/src/renderer/src/components/settings/terminal-search.ts @@ -1,7 +1,7 @@ import type { SettingsSearchEntry } from './settings-search' import { getTerminalAdvancedSearchEntries, - getTerminalGhosttyImportSearchEntries, + getTerminalConfigImportSearchEntries, getTerminalMacOptionSearchEntries, getTerminalMacYenSearchEntries } from './terminal-advanced-platform-search' @@ -56,7 +56,7 @@ export { getTerminalAdvancedSearchEntries, getTerminalMacOptionSearchEntries, getTerminalMacYenSearchEntries, - getTerminalGhosttyImportSearchEntries + getTerminalConfigImportSearchEntries } from './terminal-advanced-platform-search' export { getManageSessionsSearchEntries, @@ -83,7 +83,7 @@ const getTerminalAppearanceSearchEntriesWithoutImports = createLocalizedCatalog( const getTerminalAppearanceSearchEntriesWithImports = createLocalizedCatalog( (): SettingsSearchEntry[] => [ ...getTerminalAppearanceSearchEntriesWithoutImports(), - ...getTerminalGhosttyImportSearchEntries(), + ...getTerminalConfigImportSearchEntries(), ...getTerminalWarpImportSearchEntries(), ...getTerminalYamlImportSearchEntries() ] diff --git a/src/renderer/src/components/settings/use-settings-store-model.ts b/src/renderer/src/components/settings/use-settings-store-model.ts index 070f7f5c1012..63bdc4c6ed71 100644 --- a/src/renderer/src/components/settings/use-settings-store-model.ts +++ b/src/renderer/src/components/settings/use-settings-store-model.ts @@ -22,7 +22,7 @@ import { useActiveProjectSkillRuntime } from '@/hooks/useActiveProjectSkillRunti import { useLinearProviderConnected } from '@/hooks/useLinearProviderConnected' import { useSkillFreshness } from '@/hooks/useSkillFreshness' import { getFallbackTerminalFonts, mergeFontSuggestions } from './SettingsConstants' -import { useGhosttyImport } from './useGhosttyImport' +import { useTerminalConfigImport } from './useTerminalConfigImport' import { useWarpThemeImport } from './useWarpThemeImport' import { getInitialMountedSectionIds } from './settings-load-performance' import { @@ -134,7 +134,7 @@ export function useSettingsStoreModel() { const [scrollbackMode, setScrollbackMode] = useState<'preset' | 'custom'>('preset') const [prevScrollbackRows, setPrevScrollbackRows] = useState(settings?.terminalScrollbackRows) // Keep import state above sections so remounts cannot close the modal. - const ghostty = useGhosttyImport(updateSettings, settings) + const terminalConfigImport = useTerminalConfigImport(updateSettings, settings) const warpThemes = useWarpThemeImport(updateSettings, settings) const [fontSuggestions, setFontSuggestions] = useState( mergeFontSuggestions([], getFallbackTerminalFonts()) @@ -237,7 +237,7 @@ export function useSettingsStoreModel() { setScrollbackMode, prevScrollbackRows, setPrevScrollbackRows, - ghostty, + terminalConfigImport, warpThemes, fontSuggestions, setFontSuggestions, diff --git a/src/renderer/src/components/settings/useGhosttyImport.ts b/src/renderer/src/components/settings/useTerminalConfigImport.ts similarity index 69% rename from src/renderer/src/components/settings/useGhosttyImport.ts rename to src/renderer/src/components/settings/useTerminalConfigImport.ts index f03cdcc85ca5..5832b4096104 100644 --- a/src/renderer/src/components/settings/useGhosttyImport.ts +++ b/src/renderer/src/components/settings/useTerminalConfigImport.ts @@ -1,33 +1,36 @@ import { useRef, useState } from 'react' -import type { - GhosttyImportPreview, - GhosttyImportSource, - GlobalSettings -} from '../../../../shared/global-settings-types' +import type { GlobalSettings } from '../../../../shared/global-settings-types' import { useMountedRef } from '../../hooks/useMountedRef' -import { ghosttyImportSettingsUpdate } from '../../../../shared/ghostty-import-preview' +import { + terminalConfigImportSettingsUpdate, + type TerminalConfigImportFormat, + type TerminalConfigImportPreview, + type TerminalConfigImportSource +} from '../../../../shared/terminal-config-import-preview' import { getSystemPrefersDark } from '@/lib/terminal-theme' -export type UseGhosttyImportReturn = { +export type UseTerminalConfigImportReturn = { + format: TerminalConfigImportFormat open: boolean - preview: GhosttyImportPreview | null + preview: TerminalConfigImportPreview | null loading: boolean choosingFile: boolean applied: boolean applyError: string | null - handleClick: () => Promise + handleClick: (format: TerminalConfigImportFormat) => Promise handleChooseFile: () => Promise handleApply: () => Promise handleOpenChange: (open: boolean) => void } -export function useGhosttyImport( +export function useTerminalConfigImport( updateSettings: (updates: Partial) => void | Promise, // Accept unloaded settings so the parent retains stable hook order; defer applying until settings exist. settings: GlobalSettings | null -): UseGhosttyImportReturn { +): UseTerminalConfigImportReturn { + const [format, setFormat] = useState('ghostty') const [open, setOpen] = useState(false) - const [preview, setPreview] = useState(null) + const [preview, setPreview] = useState(null) const [loading, setLoading] = useState(false) const [choosingFile, setChoosingFile] = useState(false) const [applied, setApplied] = useState(false) @@ -36,7 +39,10 @@ export function useGhosttyImport( // Results from a superseded request (closed modal, newer pick) must not overwrite current state. const requestIdRef = useRef(0) - async function loadPreview(source: GhosttyImportSource): Promise { + async function loadPreview( + previewFormat: TerminalConfigImportFormat, + source: TerminalConfigImportSource + ): Promise { const requestId = ++requestIdRef.current const isCurrent = (): boolean => mountedRef.current && requestId === requestIdRef.current // The picker phase keeps the current preview visible instead of flashing a loading state behind it. @@ -44,7 +50,10 @@ export function useGhosttyImport( setLoading(true) } try { - const result = await window.api.settings.previewGhosttyImport(source) + const result = + previewFormat === 'kitty' + ? await window.api.settings.previewKittyImport(source) + : await window.api.settings.previewGhosttyImport(source) // A dismissed picker keeps the preview that was already showing. if (isCurrent() && !result.canceled) { setPreview(result) @@ -63,15 +72,17 @@ export function useGhosttyImport( } } - async function handleClick(): Promise { + async function handleClick(nextFormat: TerminalConfigImportFormat): Promise { + setFormat(nextFormat) + setPreview(null) setOpen(true) - await loadPreview({ kind: 'auto' }) + await loadPreview(nextFormat, { kind: 'auto' }) } async function handleChooseFile(): Promise { setChoosingFile(true) try { - await loadPreview({ kind: 'chooseFile' }) + await loadPreview(format, { kind: 'chooseFile' }) } finally { if (mountedRef.current) { setChoosingFile(false) @@ -90,7 +101,7 @@ export function useGhosttyImport( return } const requestId = requestIdRef.current - const merged = ghosttyImportSettingsUpdate(settings, preview, getSystemPrefersDark()) + const merged = terminalConfigImportSettingsUpdate(settings, preview, getSystemPrefersDark()) setApplyError(null) try { // Await persistence before marking applied so rejected IPC cannot report success. @@ -118,6 +129,7 @@ export function useGhosttyImport( } return { + format, open, preview, loading, diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 72a69f9ea5e8..d69007e86bc8 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -9331,7 +9331,8 @@ "048aac8a64": "Terminal Typography", "4415beb958": "disabled", "4e7d41a9f0": "enabled", - "dimUnfocusedPanes": "Dim unfocused panes." + "dimUnfocusedPanes": "Dim unfocused panes.", + "kitty_import": "Import from Kitty" }, "TerminalAdvancedTypographyControls": { "f5fa1a08f1": "Bold Font Weight", @@ -11346,7 +11347,9 @@ "454df22a5e": "fish", "ddd5efe113": "shell", "3de504994c": "Shell and arguments used for new local interactive terminal panes", - "1733ccd3e9": "Terminal shell" + "1733ccd3e9": "Terminal shell", + "kitty_import": "Import from Kitty", + "kitty_import_description": "One-time import of supported settings from kitty.conf." }, "windows": { "search": { @@ -13578,6 +13581,11 @@ }, "FontAutocomplete": { "installedFontsUnavailable": "Couldn’t list installed fonts. Type any installed font name to use it." + }, + "TerminalConfigImportModal": { + "kitty_title": "Import from Kitty", + "kitty_description": "Review the settings that will be imported from your kitty.conf and the files it includes.", + "kitty_not_found": "No kitty.conf found on this computer. Choose a config file to import one from another location." } }, "right": { @@ -23029,7 +23037,8 @@ "images": "Images", "repoIconImages": "Repo icon images", "audio": "Audio", - "importGhosttyConfig": "Import Ghostty Config" + "importGhosttyConfig": "Import Ghostty Config", + "importKittyConfig": "Import Kitty Config" } }, "taskProviders": { diff --git a/src/shared/global-settings-types.ts b/src/shared/global-settings-types.ts index c164ab1da9b9..2a0df41ac7a9 100644 --- a/src/shared/global-settings-types.ts +++ b/src/shared/global-settings-types.ts @@ -496,6 +496,4 @@ export type GlobalSettings = GlobalSettingsBase & { aiVaultSearch?: AiVaultSearchSettings } -// Retain one import entry point while keeping feature shapes separate from the max-lines-limited settings module. -export type { GhosttyImportPreview, GhosttyImportSource } from './ghostty-import-preview' export type { OrcaWorkspaceLayout } from './orca-workspace-layout' diff --git a/src/shared/ghostty-import-preview.ts b/src/shared/terminal-config-import-preview.ts similarity index 52% rename from src/shared/ghostty-import-preview.ts rename to src/shared/terminal-config-import-preview.ts index 4d337e21b1bf..78603d3ac564 100644 --- a/src/shared/ghostty-import-preview.ts +++ b/src/shared/terminal-config-import-preview.ts @@ -2,11 +2,14 @@ import type { GlobalSettings } from './global-settings-types' import type { TerminalThemeSlot } from './terminal-color-overrides' import { withImportedTerminalColorOverrides } from './terminal-theme-selection' -/** Where a Ghostty import reads from: Ghostty's own config locations, or a file the user picks. */ -export type GhosttyImportSource = { kind: 'auto' } | { kind: 'chooseFile' } +/** Terminal apps whose config Orca can import. */ +export type TerminalConfigImportFormat = 'ghostty' | 'kitty' -/** What a Ghostty config import would change, shown before the user accepts it. */ -export type GhosttyImportPreview = { +/** Where an import reads from: the app's own config locations, or a file the user picks. */ +export type TerminalConfigImportSource = { kind: 'auto' } | { kind: 'chooseFile' } + +/** What a terminal config import would change, shown before the user accepts it. */ +export type TerminalConfigImportPreview = { found: boolean /** The user dismissed the file picker; nothing was read. */ canceled?: boolean @@ -14,15 +17,15 @@ export type GhosttyImportPreview = { configPaths?: string[] diff: Partial unsupportedKeys: string[] - /** Theme name per slot the config's `theme` selects; when set, the diff's override bags are already per slot. */ + /** Theme name per slot the config selects; when set, the diff's override bags are already per slot. */ terminalThemes?: Partial> error?: string } -/** Settings to write when the user accepts a Ghostty import preview. */ -export function ghosttyImportSettingsUpdate( +/** Settings to write when the user accepts an import preview. */ +export function terminalConfigImportSettingsUpdate( settings: Parameters[0], - preview: GhosttyImportPreview, + preview: TerminalConfigImportPreview, systemPrefersDark: boolean ): Partial { return preview.terminalThemes From 3b311b3af2fe4fb1575642872c6a8c8a78846b4b Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 1 Nov 2026 22:37:53 -0800 Subject: [PATCH 2/6] fix(settings): harden Kitty include and value parsing --- src/main/kitty/discovery.ts | 2 +- src/main/kitty/index.ts | 3 +- src/main/kitty/kitty-import.test.ts | 6 +- src/main/kitty/mapper.ts | 92 ++++++++++--------- src/main/kitty/parser.ts | 21 ++++- .../config-file-reader.ts | 11 ++- 6 files changed, 83 insertions(+), 52 deletions(-) diff --git a/src/main/kitty/discovery.ts b/src/main/kitty/discovery.ts index d8f8669ae832..42264a7f09ca 100644 --- a/src/main/kitty/discovery.ts +++ b/src/main/kitty/discovery.ts @@ -3,7 +3,7 @@ import path from 'node:path' import { stat } from 'node:fs/promises' function expandHome(dir: string, home: string): string { - return dir === '~' || dir.startsWith('~/') ? path.posix.join(home, dir.slice(1)) : dir + return dir === '~' || dir.startsWith('~/') ? path.join(home, dir.slice(1)) : dir } // Kitty's ConfigDirForName order; Kitty has no Windows build, so only an explicit directory applies there. diff --git a/src/main/kitty/index.ts b/src/main/kitty/index.ts index 750b6e946066..bd7bf4d03fab 100644 --- a/src/main/kitty/index.ts +++ b/src/main/kitty/index.ts @@ -15,7 +15,8 @@ const KITTY_IMPORTER: TerminalConfigImporter = { appName: 'Kitty', pickerTitle: () => translateMain('native.dialog.importKittyConfig', 'Import Kitty Config'), discover: findKittyConfigPaths, - load: (configPaths) => loadKittyConfig(configPaths[0] ?? '', homedir()), + // Kitty reads one kitty.conf; anything else arrives through its include directives. + load: ([entryPath = '']) => loadKittyConfig(entryPath, homedir()), map: async (config) => mapKittyToOrca(config, platform() === 'darwin') } diff --git a/src/main/kitty/kitty-import.test.ts b/src/main/kitty/kitty-import.test.ts index eba8f11e84f5..56cb63eca2aa 100644 --- a/src/main/kitty/kitty-import.test.ts +++ b/src/main/kitty/kitty-import.test.ts @@ -67,7 +67,8 @@ describe('Kitty config import', () => { ['font_family', 'monospace'], ['cursor_text_color', 'background'], ['cursor_shape', 'hollow'], - ['macos_option_as_alt', 'left'] + ['macos_option_as_alt', 'left'], + ['constructor', '#ff0000'] ]) const { diff, unsupportedKeys } = mapKittyToOrca({ options, unsupportedKeys: [] }, false) expect(diff).toEqual({}) @@ -75,7 +76,8 @@ describe('Kitty config import', () => { 'font_family', 'cursor_text_color', 'cursor_shape', - 'macos_option_as_alt' + 'macos_option_as_alt', + 'constructor' ]) }) }) diff --git a/src/main/kitty/mapper.ts b/src/main/kitty/mapper.ts index db56b65840e2..700bac125065 100644 --- a/src/main/kitty/mapper.ts +++ b/src/main/kitty/mapper.ts @@ -6,33 +6,45 @@ import { } from '../../shared/terminal-custom-themes' import type { KittyConfig } from './parser' -const COLOR_KEYS: Record = { - foreground: 'foreground', - background: 'background', - cursor: 'cursor', - cursor_text_color: 'cursorAccent', - selection_foreground: 'selectionForeground', - selection_background: 'selectionBackground' -} +// Maps, not object literals, so option names like `constructor` cannot hit prototype keys. +const COLOR_KEYS = new Map([ + ['foreground', 'foreground'], + ['background', 'background'], + ['cursor', 'cursor'], + ['cursor_text_color', 'cursorAccent'], + ['selection_foreground', 'selectionForeground'], + ['selection_background', 'selectionBackground'], + ...TERMINAL_ANSI_COLOR_KEYS.map((key, index): [string, keyof TerminalColorOverrides] => [ + `color${index}`, + key + ]) +]) -const CURSOR_SHAPES: Record = { - block: 'block', - beam: 'bar', - underline: 'underline' -} +const CURSOR_SHAPES = new Map([ + ['block', 'block'], + ['beam', 'bar'], + ['underline', 'underline'] +]) -const OPTION_AS_ALT: Record = { - yes: 'true', - both: 'true', - no: 'false', - none: 'false', - left: 'left', - right: 'right' -} +// Kitty lowercases these and accepts its usual boolean spellings for "both". +const OPTION_AS_ALT = new Map([ + ['y', 'true'], + ['yes', 'true'], + ['true', 'true'], + ['both', 'true'], + ['n', 'false'], + ['no', 'false'], + ['false', 'false'], + ['none', 'false'], + ['left', 'left'], + ['right', 'right'] +]) -function parseNumber(value: string): number | null { - const num = Number(value) - return value.trim() !== '' && Number.isFinite(num) ? num : null +const DECIMAL_RE = /^-?\d+(?:\.\d+)?$/ + +function parseNumber(value: string, min: number, max: number): number | null { + const num = DECIMAL_RE.test(value.trim()) ? Number(value) : Number.NaN + return num >= min && num <= max ? num : null } // `font_family` is a bare name or Kitty 0.36's `family="Name" style=...` spec; `monospace` means "system default". @@ -44,8 +56,8 @@ function kittyFontFamily(value: string): string | null { // One value pads every side; two are vertical then horizontal; three are top, horizontal, bottom; four go clockwise from top. function kittyPadding(value: string): { x: number; y: number } | null { - const sides = value.split(/\s+/).map(parseNumber) - if (sides.length === 0 || sides.length > 4 || sides.some((side) => side === null || side < 0)) { + const sides = value.split(/\s+/).map((side) => parseNumber(side, 0, 512)) + if (sides.length === 0 || sides.length > 4 || sides.some((side) => side === null)) { return null } const [top = 0, right = top, bottom = top, left = right] = sides.map((side) => side ?? 0) @@ -59,8 +71,7 @@ function mapOption( diff: Partial, colors: TerminalColorOverrides ): boolean { - const colorKey = - COLOR_KEYS[key] ?? TERMINAL_ANSI_COLOR_KEYS[Number(/^color(\d+)$/.exec(key)?.[1])] + const colorKey = COLOR_KEYS.get(key) if (colorKey) { const color = normalizeTerminalHexColor(value) if (color) { @@ -77,29 +88,28 @@ function mapOption( return family !== null } case 'font_size': { - const size = parseNumber(value) - if (size !== null && size > 0) { + const size = parseNumber(value, 1, 200) + if (size !== null) { diff.terminalFontSize = size } - return size !== null && size > 0 + return size !== null } case 'background_opacity': { - const opacity = parseNumber(value) - if (opacity !== null && opacity >= 0 && opacity <= 1) { + const opacity = parseNumber(value, 0, 1) + if (opacity !== null) { diff.terminalBackgroundOpacity = opacity - return true } - return false + return opacity !== null } case 'background_blur': { - const radius = parseNumber(value) - if (radius !== null && radius >= 0) { + const radius = parseNumber(value, 0, 512) + if (radius !== null) { diff.windowMaterial = radius > 0 ? 'blur' : 'translucent' } - return radius !== null && radius >= 0 + return radius !== null } case 'cursor_shape': { - const style = CURSOR_SHAPES[value] + const style = CURSOR_SHAPES.get(value.toLowerCase()) if (style) { diff.terminalCursorStyle = style } @@ -107,7 +117,7 @@ function mapOption( } case 'cursor_blink_interval': { // The first token is seconds (0 disables, negative uses the OS rate); easing curves may follow. - const interval = parseNumber(value.split(/\s+/)[0] ?? '') + const interval = parseNumber(value.split(/\s+/)[0] ?? '', -1, 3600) if (interval !== null) { diff.terminalCursorBlink = interval !== 0 } @@ -122,7 +132,7 @@ function mapOption( return padding !== null } case 'macos_option_as_alt': { - const optionAsAlt = isMacOS ? OPTION_AS_ALT[value] : undefined + const optionAsAlt = isMacOS ? OPTION_AS_ALT.get(value.toLowerCase()) : undefined if (optionAsAlt) { diff.terminalMacOptionAsAlt = optionAsAlt } diff --git a/src/main/kitty/parser.ts b/src/main/kitty/parser.ts index ec6382181fb6..f1b909921272 100644 --- a/src/main/kitty/parser.ts +++ b/src/main/kitty/parser.ts @@ -1,10 +1,12 @@ import { platform } from 'node:os' import path from 'node:path' -import { readdir, stat } from 'node:fs/promises' +import { readdir, realpath, stat } from 'node:fs/promises' import { readConfigFile } from '../terminal-config-import/config-file-reader' // Includes can fan out through globs; bound how much one import may read. const MAX_INCLUDED_FILES = 64 +const MAX_GLOB_ENTRIES = 1_000 +const MAX_TOTAL_BYTES = 4_000_000 const AUTO_THEME_FILES = [ 'dark-theme.auto.conf', 'light-theme.auto.conf', @@ -67,13 +69,14 @@ async function expandGlobInclude(pattern: string): Promise { } const source = path .basename(pattern) - .replace(/[.+^${}()|\\]/g, '\\$&') + .replace(/[.+^${}()|[\]\\]/g, '\\$&') .replaceAll('*', '.*') .replaceAll('?', '.') const nameRe = new RegExp(`^${source}$`) try { const names = await readdir(dir) return names + .slice(0, MAX_GLOB_ENTRIES) .filter((name) => nameRe.test(name)) .sort() .map((name) => path.join(dir, name)) @@ -96,9 +99,11 @@ export async function loadKittyConfig(entryPath: string, home: string): Promise< const readPaths: string[] = [] const seen = new Set() let firstError: string | null = null + let totalBytes = 0 async function loadFile(filePath: string): Promise { - const key = path.normalize(filePath) + // Real paths stop symlinked directories from re-including the same files. + const key = await realpath(filePath).catch(() => path.normalize(filePath)) if (seen.has(key)) { return } @@ -110,11 +115,17 @@ export async function loadKittyConfig(entryPath: string, home: string): Promise< const read = await readConfigFile(filePath) if (!read.ok) { firstError ??= read.error - if (readPaths.length > 0) { - unsupportedKeys.add(`include (${path.basename(filePath)}: ${read.error})`) + // Kitty skips missing includes silently; other failures are worth surfacing. + if (readPaths.length > 0 && !read.missing) { + unsupportedKeys.add(`include (${path.basename(filePath)} could not be read)`) } return } + totalBytes += read.content.length + if (totalBytes > MAX_TOTAL_BYTES) { + unsupportedKeys.add(`include (more than ${MAX_TOTAL_BYTES} bytes in total)`) + return + } readPaths.push(filePath) const baseDir = path.dirname(filePath) for (const [optionKey, value] of parseKittyLines(read.content)) { diff --git a/src/main/terminal-config-import/config-file-reader.ts b/src/main/terminal-config-import/config-file-reader.ts index 5249ac08398f..3633e0d35906 100644 --- a/src/main/terminal-config-import/config-file-reader.ts +++ b/src/main/terminal-config-import/config-file-reader.ts @@ -3,7 +3,9 @@ import { readFile, stat } from 'node:fs/promises' // Bound config reads to avoid loading arbitrarily large files into main. export const MAX_CONFIG_BYTES = 1_000_000 -export type ConfigFileRead = { ok: true; content: string } | { ok: false; error: string } +export type ConfigFileRead = + | { ok: true; content: string } + | { ok: false; error: string; missing?: boolean } export async function readConfigFile(configPath: string): Promise { try { @@ -21,6 +23,11 @@ export async function readConfigFile(configPath: string): Promise Date: Sun, 1 Nov 2026 22:43:04 -0800 Subject: [PATCH 3/6] fix(settings): match Kitty globs linearly, skip read-only system configs, report non-family font selectors --- src/main/kitty/discovery.ts | 7 +++-- src/main/kitty/kitty-import.test.ts | 16 ++++++++--- src/main/kitty/mapper.ts | 4 +++ src/main/kitty/parser.ts | 42 ++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/main/kitty/discovery.ts b/src/main/kitty/discovery.ts index 42264a7f09ca..c01f0b7a718a 100644 --- a/src/main/kitty/discovery.ts +++ b/src/main/kitty/discovery.ts @@ -1,6 +1,7 @@ import { homedir, platform } from 'node:os' import path from 'node:path' -import { stat } from 'node:fs/promises' +import { constants } from 'node:fs' +import { access, stat } from 'node:fs/promises' function expandHome(dir: string, home: string): string { return dir === '~' || dir.startsWith('~/') ? path.join(home, dir.slice(1)) : dir @@ -29,11 +30,13 @@ export function getKittyConfigPaths(): string[] { return [...new Set(dirs)].map((dir) => path.posix.join(dir, 'kitty.conf')) } -/** Kitty reads a single kitty.conf: the first location that has one. */ +/** Kitty reads a single kitty.conf: the first location that has one in a writable directory. */ export async function findKittyConfigPaths(): Promise { for (const configPath of getKittyConfigPaths()) { try { + // The writability check keeps a read-only system default (e.g. /etc/xdg) from shadowing the user's config. if ((await stat(configPath)).isFile()) { + await access(path.dirname(configPath), constants.W_OK) return [configPath] } } catch { diff --git a/src/main/kitty/kitty-import.test.ts b/src/main/kitty/kitty-import.test.ts index 56cb63eca2aa..7c06714496a8 100644 --- a/src/main/kitty/kitty-import.test.ts +++ b/src/main/kitty/kitty-import.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import path from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { mapKittyToOrca } from './mapper' -import { loadKittyConfig } from './parser' +import { loadKittyConfig, matchesFileGlob } from './parser' let dir: string @@ -68,7 +68,8 @@ describe('Kitty config import', () => { ['cursor_text_color', 'background'], ['cursor_shape', 'hollow'], ['macos_option_as_alt', 'left'], - ['constructor', '#ff0000'] + ['constructor', '#ff0000'], + ['font_size', '1e3'] ]) const { diff, unsupportedKeys } = mapKittyToOrca({ options, unsupportedKeys: [] }, false) expect(diff).toEqual({}) @@ -77,7 +78,16 @@ describe('Kitty config import', () => { 'cursor_text_color', 'cursor_shape', 'macos_option_as_alt', - 'constructor' + 'constructor', + 'font_size' ]) }) + + it('matches file globs without exponential backtracking', () => { + expect(matchesFileGlob('dark.conf', '*.conf')).toBe(true) + expect(matchesFileGlob('dark.conf.bak', '*.conf')).toBe(false) + expect(matchesFileGlob('a1.conf', 'a?.conf')).toBe(true) + // A regex translation of this pattern backtracks for minutes; the matcher returns at once. + expect(matchesFileGlob('a'.repeat(48), `${'a*'.repeat(16)}b`)).toBe(false) + }) }) diff --git a/src/main/kitty/mapper.ts b/src/main/kitty/mapper.ts index 700bac125065..4c83dfc214cc 100644 --- a/src/main/kitty/mapper.ts +++ b/src/main/kitty/mapper.ts @@ -50,6 +50,10 @@ function parseNumber(value: string, min: number, max: number): number | null { // `font_family` is a bare name or Kitty 0.36's `family="Name" style=...` spec; `monospace` means "system default". function kittyFontFamily(value: string): string | null { const spec = /(?:^|\s)family=(?:"([^"]+)"|'([^']+)'|(\S+))/.exec(value) + // Other selectors (postscript_name=, full_name=) name a face Orca cannot look up. + if (!spec && /^\w+=/.test(value)) { + return null + } const family = (spec ? (spec[1] ?? spec[2] ?? spec[3]) : value).trim() return family && family !== 'monospace' && family !== 'auto' ? family : null } diff --git a/src/main/kitty/parser.ts b/src/main/kitty/parser.ts index f1b909921272..8c14af62ba5e 100644 --- a/src/main/kitty/parser.ts +++ b/src/main/kitty/parser.ts @@ -61,23 +61,45 @@ function expandIncludePath(value: string, baseDir: string, home: string): string return path.isAbsolute(expanded) ? expanded : path.join(baseDir, expanded) } -// Kitty globs with pathlib; Orca supports wildcards in the file name, the common `themes/*.conf` form. +// Greedy `*`/`?` matching with one backtrack point stays linear-ish, unlike a translated regex. +export function matchesFileGlob(name: string, pattern: string): boolean { + let nameIndex = 0 + let patternIndex = 0 + let starIndex = -1 + let starNameIndex = 0 + while (nameIndex < name.length) { + const token = pattern[patternIndex] + if (token === '?' || (token !== undefined && token !== '*' && token === name[nameIndex])) { + nameIndex++ + patternIndex++ + } else if (token === '*') { + starIndex = patternIndex++ + starNameIndex = nameIndex + } else if (starIndex !== -1) { + patternIndex = starIndex + 1 + nameIndex = ++starNameIndex + } else { + return false + } + } + while (pattern[patternIndex] === '*') { + patternIndex++ + } + return patternIndex === pattern.length +} + +// Kitty globs with pathlib; Orca supports `*` and `?` in the file name, the common `themes/*.conf` form. async function expandGlobInclude(pattern: string): Promise { const dir = path.dirname(pattern) - if (/[*?[]/.test(dir)) { + const namePattern = path.basename(pattern) + if (/[*?[]/.test(dir) || namePattern.includes('[')) { return null } - const source = path - .basename(pattern) - .replace(/[.+^${}()|[\]\\]/g, '\\$&') - .replaceAll('*', '.*') - .replaceAll('?', '.') - const nameRe = new RegExp(`^${source}$`) try { const names = await readdir(dir) return names .slice(0, MAX_GLOB_ENTRIES) - .filter((name) => nameRe.test(name)) + .filter((name) => matchesFileGlob(name, namePattern)) .sort() .map((name) => path.join(dir, name)) } catch { @@ -134,7 +156,7 @@ export async function loadKittyConfig(entryPath: string, home: string): Promise< } else if (optionKey === 'globinclude') { const matches = await expandGlobInclude(expandIncludePath(value, baseDir, home)) if (matches === null) { - unsupportedKeys.add('globinclude (wildcards in directory names)') + unsupportedKeys.add('globinclude (only * and ? in file names are supported)') } for (const match of matches ?? []) { await loadFile(match) From 9745be6577eac14b7364fff914895e21dc02e451 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 2 Nov 2026 00:15:46 -0800 Subject: [PATCH 4/6] refactor(settings): read current settings through a typed map when diffing imports --- src/main/terminal-config-import/settings-changes.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/terminal-config-import/settings-changes.ts b/src/main/terminal-config-import/settings-changes.ts index cc5f247f27a3..67036d12d53a 100644 --- a/src/main/terminal-config-import/settings-changes.ts +++ b/src/main/terminal-config-import/settings-changes.ts @@ -32,10 +32,11 @@ export function settingsChanges( current: GlobalSettings, patch: Partial ): Partial { + const currentValues = new Map(Object.entries(current)) return Object.fromEntries( - Object.entries(patch).filter(([key, value]) => { - const currentValue: unknown = key in current ? Reflect.get(current, key) : undefined - return value !== undefined && !valuesEqual(currentValue ?? emptyLike(value), value) - }) + Object.entries(patch).filter( + ([key, value]) => + value !== undefined && !valuesEqual(currentValues.get(key) ?? emptyLike(value), value) + ) ) } From 65d7ce0e62e1979fe0ec182def13350cf60a70bf Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 2 Nov 2026 00:19:36 -0800 Subject: [PATCH 5/6] style: format Ghostty importer --- src/main/ghostty/index.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/ghostty/index.ts b/src/main/ghostty/index.ts index fbd1cca06bf2..4a6703a9d0b2 100644 --- a/src/main/ghostty/index.ts +++ b/src/main/ghostty/index.ts @@ -103,12 +103,7 @@ const GHOSTTY_IMPORTER: TerminalConfigImporter = { map: async (config, { currentSettings, pickedConfigDir }): Promise => { const { theme: rawTheme, ...configKeys } = config const mapped = mapGhosttyToOrca(configKeys, platform() === 'darwin') - const theme = await themeReferencePatch( - rawTheme, - mapped.diff, - pickedConfigDir, - currentSettings - ) + const theme = await themeReferencePatch(rawTheme, mapped.diff, pickedConfigDir, currentSettings) return { diff: { ...mapped.diff, ...theme.diff }, unsupportedKeys: [...mapped.unsupportedKeys, ...theme.unsupportedKeys], From 408afd1c260c8824dce28f0f65c38ffac79e1797 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 2 Nov 2026 00:31:30 -0800 Subject: [PATCH 6/6] fix(settings): type the import hook stub and let dialog primitives own their typography --- .../settings/AppearancePane.test.tsx | 23 +++++++++++-------- .../settings/TerminalConfigImportModal.tsx | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/components/settings/AppearancePane.test.tsx b/src/renderer/src/components/settings/AppearancePane.test.tsx index abbad96afbe8..f8e4b54dbd28 100644 --- a/src/renderer/src/components/settings/AppearancePane.test.tsx +++ b/src/renderer/src/components/settings/AppearancePane.test.tsx @@ -106,18 +106,23 @@ vi.mock('../ui/select', async () => { import { AppearancePane } from './AppearancePane' import { TooltipProvider } from '../ui/tooltip' +import type { UseTerminalConfigImportReturn } from './useTerminalConfigImport' const mountedRoots: Root[] = [] -function createGhosttyStub() { +function createTerminalConfigImportStub(): UseTerminalConfigImportReturn { return { - loading: false, + format: 'ghostty', + open: false, preview: null, - error: null, - open: vi.fn(), - close: vi.fn(), - refresh: vi.fn(), - apply: vi.fn() + loading: false, + choosingFile: false, + applied: false, + applyError: null, + handleClick: vi.fn(), + handleChooseFile: vi.fn(), + handleApply: vi.fn(), + handleOpenChange: vi.fn() } } @@ -163,7 +168,7 @@ async function renderAppearancePane( terminalFontSuggestions={[]} onRequestFontSuggestions={options.onRequestFontSuggestions} systemPrefersDark={false} - terminalConfigImport={createGhosttyStub() as never} + terminalConfigImport={createTerminalConfigImportStub()} warpThemes={createWarpThemesStub() as never} /> @@ -192,7 +197,7 @@ async function rerenderAppearancePane( fontSuggestions={[]} terminalFontSuggestions={[]} systemPrefersDark={false} - terminalConfigImport={createGhosttyStub() as never} + terminalConfigImport={createTerminalConfigImportStub()} warpThemes={createWarpThemesStub() as never} /> diff --git a/src/renderer/src/components/settings/TerminalConfigImportModal.tsx b/src/renderer/src/components/settings/TerminalConfigImportModal.tsx index ac44c9fb8c20..27bc953d45e1 100644 --- a/src/renderer/src/components/settings/TerminalConfigImportModal.tsx +++ b/src/renderer/src/components/settings/TerminalConfigImportModal.tsx @@ -121,8 +121,8 @@ export function TerminalConfigImportModal({ - {copy.title} - {copy.description} + {copy.title} + {copy.description} {!applied ? (