Files
gemini-cli/packages/cli/src/config/footerItems.ts
T

133 lines
3.2 KiB
TypeScript
Raw Normal View History

2026-02-13 07:04:28 -05:00
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type { MergedSettings } from './settings.js';
2026-02-13 12:50:26 -05:00
export const ALL_ITEMS = [
2026-02-13 07:04:28 -05:00
{
id: 'cwd',
header: 'workspace (/directory)',
2026-02-16 18:07:54 -05:00
description: 'Current working directory',
2026-02-13 07:04:28 -05:00
},
{
id: 'git-branch',
header: 'branch',
2026-02-16 18:07:54 -05:00
description: 'Current git branch name (not shown when unavailable)',
2026-02-13 07:04:28 -05:00
},
{
id: 'sandbox-status',
header: 'sandbox',
2026-02-13 07:04:28 -05:00
description: 'Sandbox type and trust indicator',
},
{
id: 'model-name',
2026-02-16 12:54:39 -05:00
header: '/model',
2026-02-13 07:04:28 -05:00
description: 'Current model identifier',
},
{
id: 'context-remaining',
header: 'context',
2026-02-13 07:04:28 -05:00
description: 'Percentage of context window remaining',
},
{
id: 'quota',
2026-02-16 12:54:39 -05:00
header: '/stats',
2026-02-16 18:07:54 -05:00
description: 'Remaining usage on daily limit (not shown when unavailable)',
2026-02-13 07:04:28 -05:00
},
{
id: 'memory-usage',
header: 'memory',
2026-02-16 18:07:54 -05:00
description: 'Memory used by the application',
2026-02-13 07:04:28 -05:00
},
{
id: 'session-id',
header: 'session',
2026-02-13 07:04:28 -05:00
description: 'Unique identifier for the current session',
},
{
id: 'code-changes',
header: 'diff',
2026-02-16 18:07:54 -05:00
description: 'Lines added/removed in the session (not shown when zero)',
2026-02-13 07:04:28 -05:00
},
{
id: 'token-count',
header: 'tokens',
2026-02-16 18:07:54 -05:00
description: 'Total tokens used in the session (not shown when zero)',
2026-02-13 07:04:28 -05:00
},
2026-02-13 12:50:26 -05:00
] as const;
export type FooterItemId = (typeof ALL_ITEMS)[number]['id'];
2026-02-13 07:04:28 -05:00
export const DEFAULT_ORDER = [
'cwd',
'git-branch',
'sandbox-status',
'model-name',
'context-remaining',
'quota',
2026-02-13 07:04:28 -05:00
'memory-usage',
'session-id',
'code-changes',
'token-count',
];
export function deriveItemsFromLegacySettings(
settings: MergedSettings,
): string[] {
const defaults = [
'cwd',
'git-branch',
'sandbox-status',
'model-name',
'quota',
2026-02-13 07:04:28 -05:00
];
const items = [...defaults];
const remove = (arr: string[], id: string) => {
const idx = arr.indexOf(id);
if (idx !== -1) arr.splice(idx, 1);
};
if (settings.ui.footer.hideCWD) remove(items, 'cwd');
if (settings.ui.footer.hideSandboxStatus) remove(items, 'sandbox-status');
if (settings.ui.footer.hideModelInfo) {
remove(items, 'model-name');
remove(items, 'context-remaining');
remove(items, 'quota');
2026-02-13 07:04:28 -05:00
}
if (
!settings.ui.footer.hideContextPercentage &&
!items.includes('context-remaining')
) {
const modelIdx = items.indexOf('model-name');
if (modelIdx !== -1) items.splice(modelIdx + 1, 0, 'context-remaining');
else items.push('context-remaining');
}
if (settings.ui.showMemoryUsage) items.push('memory-usage');
return items;
}
2026-02-16 15:35:41 -05:00
const VALID_IDS: Set<string> = new Set(ALL_ITEMS.map((i) => i.id));
/**
* Resolves the ordered list and selected set of footer items from settings.
* Used by FooterConfigDialog to initialize and reset state.
*/
export function resolveFooterState(settings: MergedSettings): {
orderedIds: string[];
selectedIds: Set<string>;
} {
const source = (
settings.ui?.footer?.items ?? deriveItemsFromLegacySettings(settings)
).filter((id: string) => VALID_IDS.has(id));
const others = DEFAULT_ORDER.filter((id) => !source.includes(id));
return {
orderedIds: [...source, ...others],
selectedIds: new Set(source),
};
}