mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
Infer modifyOtherKeys support (#16270)
This commit is contained in:
committed by
GitHub
parent
c7d17dda49
commit
ea7393f7fd
@@ -34,7 +34,6 @@ import { useReverseSearchCompletion } from '../hooks/useReverseSearchCompletion.
|
|||||||
import clipboardy from 'clipboardy';
|
import clipboardy from 'clipboardy';
|
||||||
import * as clipboardUtils from '../utils/clipboardUtils.js';
|
import * as clipboardUtils from '../utils/clipboardUtils.js';
|
||||||
import { useKittyKeyboardProtocol } from '../hooks/useKittyKeyboardProtocol.js';
|
import { useKittyKeyboardProtocol } from '../hooks/useKittyKeyboardProtocol.js';
|
||||||
import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js';
|
|
||||||
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
|
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
|
||||||
import stripAnsi from 'strip-ansi';
|
import stripAnsi from 'strip-ansi';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
@@ -125,10 +124,6 @@ describe('InputPrompt', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
vi.spyOn(
|
|
||||||
terminalCapabilityManager,
|
|
||||||
'isBracketedPasteEnabled',
|
|
||||||
).mockReturnValue(true);
|
|
||||||
|
|
||||||
mockCommandContext = createMockCommandContext();
|
mockCommandContext = createMockCommandContext();
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import {
|
|||||||
type SettingDefinition,
|
type SettingDefinition,
|
||||||
type SettingsSchemaType,
|
type SettingsSchemaType,
|
||||||
} from '../../config/settingsSchema.js';
|
} from '../../config/settingsSchema.js';
|
||||||
import { terminalCapabilityManager } from '../../ui/utils/terminalCapabilityManager.js';
|
|
||||||
|
|
||||||
// Mock the VimModeContext
|
// Mock the VimModeContext
|
||||||
const mockToggleVimEnabled = vi.fn();
|
const mockToggleVimEnabled = vi.fn();
|
||||||
@@ -254,10 +253,6 @@ const renderDialog = (
|
|||||||
|
|
||||||
describe('SettingsDialog', () => {
|
describe('SettingsDialog', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.spyOn(
|
|
||||||
terminalCapabilityManager,
|
|
||||||
'isBracketedPasteEnabled',
|
|
||||||
).mockReturnValue(true);
|
|
||||||
mockToggleVimEnabled.mockResolvedValue(true);
|
mockToggleVimEnabled.mockResolvedValue(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
import { TerminalCapabilityManager } from './terminalCapabilityManager.js';
|
import { TerminalCapabilityManager } from './terminalCapabilityManager.js';
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
|
import {
|
||||||
|
enableKittyKeyboardProtocol,
|
||||||
|
enableModifyOtherKeys,
|
||||||
|
} from '@google/gemini-cli-core';
|
||||||
|
|
||||||
// Mock fs
|
// Mock fs
|
||||||
vi.mock('node:fs', () => ({
|
vi.mock('node:fs', () => ({
|
||||||
@@ -190,7 +194,8 @@ describe('TerminalCapabilityManager', () => {
|
|||||||
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
expect(manager.isModifyOtherKeysEnabled()).toBe(true);
|
|
||||||
|
expect(enableModifyOtherKeys).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not enable modifyOtherKeys for level 0', async () => {
|
it('should not enable modifyOtherKeys for level 0', async () => {
|
||||||
@@ -203,7 +208,8 @@ describe('TerminalCapabilityManager', () => {
|
|||||||
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
expect(manager.isModifyOtherKeysEnabled()).toBe(false);
|
|
||||||
|
expect(enableModifyOtherKeys).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prefer Kitty over modifyOtherKeys', async () => {
|
it('should prefer Kitty over modifyOtherKeys', async () => {
|
||||||
@@ -218,7 +224,9 @@ describe('TerminalCapabilityManager', () => {
|
|||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
expect(manager.isKittyProtocolEnabled()).toBe(true);
|
expect(manager.isKittyProtocolEnabled()).toBe(true);
|
||||||
expect(manager.isModifyOtherKeysEnabled()).toBe(false);
|
|
||||||
|
expect(enableKittyKeyboardProtocol).toHaveBeenCalled();
|
||||||
|
expect(enableModifyOtherKeys).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should enable modifyOtherKeys when Kitty not supported', async () => {
|
it('should enable modifyOtherKeys when Kitty not supported', async () => {
|
||||||
@@ -231,8 +239,9 @@ describe('TerminalCapabilityManager', () => {
|
|||||||
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
expect(manager.isModifyOtherKeysEnabled()).toBe(true);
|
|
||||||
expect(manager.isKittyProtocolEnabled()).toBe(false);
|
expect(manager.isKittyProtocolEnabled()).toBe(false);
|
||||||
|
expect(enableModifyOtherKeys).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle split modifyOtherKeys response chunks', async () => {
|
it('should handle split modifyOtherKeys response chunks', async () => {
|
||||||
@@ -246,7 +255,8 @@ describe('TerminalCapabilityManager', () => {
|
|||||||
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
expect(manager.isModifyOtherKeysEnabled()).toBe(true);
|
|
||||||
|
expect(enableModifyOtherKeys).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect modifyOtherKeys with other capabilities', async () => {
|
it('should detect modifyOtherKeys with other capabilities', async () => {
|
||||||
@@ -263,7 +273,23 @@ describe('TerminalCapabilityManager', () => {
|
|||||||
|
|
||||||
expect(manager.getTerminalBackgroundColor()).toBe('#1a1a1a');
|
expect(manager.getTerminalBackgroundColor()).toBe('#1a1a1a');
|
||||||
expect(manager.getTerminalName()).toBe('tmux');
|
expect(manager.getTerminalName()).toBe('tmux');
|
||||||
expect(manager.isModifyOtherKeysEnabled()).toBe(true);
|
|
||||||
|
expect(enableModifyOtherKeys).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should infer modifyOtherKeys support from Device Attributes (DA1) alone', async () => {
|
||||||
|
const manager = TerminalCapabilityManager.getInstance();
|
||||||
|
const promise = manager.detectCapabilities();
|
||||||
|
|
||||||
|
// Simulate only DA1 response (no specific MOK or Kitty response)
|
||||||
|
stdin.emit('data', Buffer.from('\x1b[?62c'));
|
||||||
|
|
||||||
|
await promise;
|
||||||
|
|
||||||
|
expect(manager.isKittyProtocolEnabled()).toBe(false);
|
||||||
|
// It should fall back to modifyOtherKeys because DA1 proves it's an ANSI terminal
|
||||||
|
|
||||||
|
expect(enableModifyOtherKeys).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,14 +43,13 @@ export class TerminalCapabilityManager {
|
|||||||
// eslint-disable-next-line no-control-regex
|
// eslint-disable-next-line no-control-regex
|
||||||
private static readonly MODIFY_OTHER_KEYS_REGEX = /\x1b\[>4;(\d+)m/;
|
private static readonly MODIFY_OTHER_KEYS_REGEX = /\x1b\[>4;(\d+)m/;
|
||||||
|
|
||||||
|
private detectionComplete = false;
|
||||||
private terminalBackgroundColor: TerminalBackgroundColor;
|
private terminalBackgroundColor: TerminalBackgroundColor;
|
||||||
private kittySupported = false;
|
private kittySupported = false;
|
||||||
private kittyEnabled = false;
|
private kittyEnabled = false;
|
||||||
private detectionComplete = false;
|
|
||||||
private terminalName: string | undefined;
|
private terminalName: string | undefined;
|
||||||
private modifyOtherKeysSupported = false;
|
private modifyOtherKeysSupported?: boolean;
|
||||||
private modifyOtherKeysEnabled = false;
|
private deviceAttributesSupported = false;
|
||||||
private bracketedPasteEnabled = false;
|
|
||||||
|
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
|
|
||||||
@@ -187,6 +186,7 @@ export class TerminalCapabilityManager {
|
|||||||
);
|
);
|
||||||
if (match) {
|
if (match) {
|
||||||
deviceAttributesReceived = true;
|
deviceAttributesReceived = true;
|
||||||
|
this.deviceAttributesSupported = true;
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,13 +215,17 @@ export class TerminalCapabilityManager {
|
|||||||
if (this.kittySupported) {
|
if (this.kittySupported) {
|
||||||
enableKittyKeyboardProtocol();
|
enableKittyKeyboardProtocol();
|
||||||
this.kittyEnabled = true;
|
this.kittyEnabled = true;
|
||||||
} else if (this.modifyOtherKeysSupported) {
|
} else if (
|
||||||
|
this.modifyOtherKeysSupported === true ||
|
||||||
|
// If device attributes were received it's safe to try enabling
|
||||||
|
// anyways, since it will be ignored if unsupported
|
||||||
|
(this.modifyOtherKeysSupported === undefined &&
|
||||||
|
this.deviceAttributesSupported)
|
||||||
|
) {
|
||||||
enableModifyOtherKeys();
|
enableModifyOtherKeys();
|
||||||
this.modifyOtherKeysEnabled = true;
|
|
||||||
}
|
}
|
||||||
// Always enable bracketed paste since it'll be ignored if unsupported.
|
// Always enable bracketed paste since it'll be ignored if unsupported.
|
||||||
enableBracketedPasteMode();
|
enableBracketedPasteMode();
|
||||||
this.bracketedPasteEnabled = true;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLogger.warn('Failed to enable keyboard protocols:', e);
|
debugLogger.warn('Failed to enable keyboard protocols:', e);
|
||||||
}
|
}
|
||||||
@@ -239,14 +243,6 @@ export class TerminalCapabilityManager {
|
|||||||
return this.kittyEnabled;
|
return this.kittyEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
isBracketedPasteEnabled(): boolean {
|
|
||||||
return this.bracketedPasteEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
isModifyOtherKeysEnabled(): boolean {
|
|
||||||
return this.modifyOtherKeysEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseColor(rHex: string, gHex: string, bHex: string): string {
|
private parseColor(rHex: string, gHex: string, bHex: string): string {
|
||||||
const parseComponent = (hex: string) => {
|
const parseComponent = (hex: string) => {
|
||||||
const val = parseInt(hex, 16);
|
const val = parseInt(hex, 16);
|
||||||
|
|||||||
Reference in New Issue
Block a user