mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 14:40:52 -07:00
feat(cli): Add setting to show status(or Gemini 's thoughts) in terminal title and taskbar icon (#4386)
Co-authored-by: Jacob Richman <jacob314@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
59
packages/cli/src/utils/windowTitle.test.ts
Normal file
59
packages/cli/src/utils/windowTitle.test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { computeWindowTitle } from './windowTitle.js';
|
||||
|
||||
describe('computeWindowTitle', () => {
|
||||
let originalEnv: NodeJS.ProcessEnv;
|
||||
|
||||
beforeEach(() => {
|
||||
originalEnv = process.env;
|
||||
vi.stubEnv('CLI_TITLE', undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
it('should use default Gemini title when CLI_TITLE is not set', () => {
|
||||
const result = computeWindowTitle('my-project');
|
||||
expect(result).toBe('Gemini - my-project');
|
||||
});
|
||||
|
||||
it('should use CLI_TITLE environment variable when set', () => {
|
||||
vi.stubEnv('CLI_TITLE', 'Custom Title');
|
||||
const result = computeWindowTitle('my-project');
|
||||
expect(result).toBe('Custom Title');
|
||||
});
|
||||
|
||||
it('should remove control characters from title', () => {
|
||||
vi.stubEnv('CLI_TITLE', 'Title\x1b[31m with \x07 control chars');
|
||||
const result = computeWindowTitle('my-project');
|
||||
// The \x1b[31m (ANSI escape sequence) and \x07 (bell character) should be removed
|
||||
expect(result).toBe('Title[31m with control chars');
|
||||
});
|
||||
|
||||
it('should handle folder names with control characters', () => {
|
||||
const result = computeWindowTitle('project\x07name');
|
||||
expect(result).toBe('Gemini - projectname');
|
||||
});
|
||||
|
||||
it('should handle empty folder name', () => {
|
||||
const result = computeWindowTitle('');
|
||||
expect(result).toBe('Gemini - ');
|
||||
});
|
||||
|
||||
it('should handle folder names with spaces', () => {
|
||||
const result = computeWindowTitle('my project');
|
||||
expect(result).toBe('Gemini - my project');
|
||||
});
|
||||
|
||||
it('should handle folder names with special characters', () => {
|
||||
const result = computeWindowTitle('project-name_v1.0');
|
||||
expect(result).toBe('Gemini - project-name_v1.0');
|
||||
});
|
||||
});
|
||||
22
packages/cli/src/utils/windowTitle.ts
Normal file
22
packages/cli/src/utils/windowTitle.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Computes the window title for the Gemini CLI application.
|
||||
*
|
||||
* @param folderName - The name of the current folder/workspace to display in the title
|
||||
* @returns The computed window title, either from CLI_TITLE environment variable or the default Gemini title
|
||||
*/
|
||||
export function computeWindowTitle(folderName: string): string {
|
||||
const title = process.env['CLI_TITLE'] || `Gemini - ${folderName}`;
|
||||
|
||||
// Remove control characters that could cause issues in terminal titles
|
||||
return title.replace(
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/[\x00-\x1F\x7F]/g,
|
||||
'',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user