-
Notifications
You must be signed in to change notification settings - Fork 9.5k
feat: support custom ASCII art variants for header logo (TOML) #13706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
7757432
0054a74
f19d2a6
db92ffc
a0277ac
47a14e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { useEffect, useState } from 'react'; | ||
| import * as fs from 'node:fs/promises'; | ||
| import { getErrorMessage, debugLogger } from '@google/gemini-cli-core'; | ||
| import toml from '@iarna/toml'; | ||
| import type { LogoVariants } from '../types.js'; | ||
|
|
||
| export function useCustomLogo( | ||
| variantsFilePath: string | undefined, | ||
| ): LogoVariants | undefined { | ||
| const [variants, setVariants] = useState<LogoVariants | undefined>(undefined); | ||
|
|
||
| useEffect(() => { | ||
| if (!variantsFilePath) { | ||
| setVariants(undefined); | ||
| return; | ||
| } | ||
|
|
||
| const loadVariants = async () => { | ||
| try { | ||
| const content = await fs.readFile(variantsFilePath, 'utf-8'); | ||
| const parsed = toml.parse(content) as unknown as LogoVariants; | ||
| setVariants(parsed); | ||
|
Comment on lines
+27
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type assertion const parsed = toml.parse(content);
if (typeof parsed !== 'object' || parsed === null) {
throw new Error('TOML file content is not a valid object.');
}
// Ensure all logo variants are strings.
for (const [key, value] of Object.entries(parsed)) {
if (typeof value !== 'string') {
throw new Error(`Invalid type for logo variant "${key}": expected string, got ${typeof value}.`);
}
}
setVariants(parsed as LogoVariants); |
||
| } catch (e) { | ||
| const msg = `Failed to load custom logo variants from "${variantsFilePath}": ${getErrorMessage(e)}`; | ||
| debugLogger.warn(msg); | ||
| setVariants(undefined); | ||
| } | ||
| }; | ||
|
|
||
| loadVariants(); | ||
| }, [variantsFilePath]); | ||
|
|
||
| return variants; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a potential improvement in the fallback logic for IDE-specific logos. Currently, if a user provides a custom
longAsciiLogobut not alongAsciiLogoIde, the header will fall back to thedefaultLongAsciiLogoIdewhen in an IDE environment. This might be unexpected for the user, who might assume their custom non-IDE logo would be used as a fallback.Consider a more intuitive fallback chain:
custom IDE variant->custom non-IDE variant->default IDE variant. This would provide a better user experience and more consistent branding for users who don't want to create separate IDE variants.