ccmanager 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,11 @@ import { shortcutManager } from '../services/shortcutManager.js';
|
|
|
4
4
|
const Session = ({ session, sessionManager, onReturnToMenu, }) => {
|
|
5
5
|
const { stdout } = useStdout();
|
|
6
6
|
const [isExiting, setIsExiting] = useState(false);
|
|
7
|
+
const stripOscColorSequences = (input) => {
|
|
8
|
+
// Remove default foreground/background color OSC sequences that Codex emits
|
|
9
|
+
// These sequences leak as literal text when replaying buffered output
|
|
10
|
+
return input.replace(/\x1B\](?:10|11);[^\x07\x1B]*(?:\x07|\x1B\\)/g, '');
|
|
11
|
+
};
|
|
7
12
|
useEffect(() => {
|
|
8
13
|
if (!stdout)
|
|
9
14
|
return;
|
|
@@ -17,7 +22,7 @@ const Session = ({ session, sessionManager, onReturnToMenu, }) => {
|
|
|
17
22
|
const buffer = restoredSession.outputHistory[i];
|
|
18
23
|
if (!buffer)
|
|
19
24
|
continue;
|
|
20
|
-
const str = buffer.toString('utf8');
|
|
25
|
+
const str = stripOscColorSequences(buffer.toString('utf8'));
|
|
21
26
|
// Skip clear screen sequences at the beginning
|
|
22
27
|
if (i === 0 && (str.includes('\x1B[2J') || str.includes('\x1B[H'))) {
|
|
23
28
|
// Skip this buffer or remove the clear sequence
|
|
@@ -25,11 +30,13 @@ const Session = ({ session, sessionManager, onReturnToMenu, }) => {
|
|
|
25
30
|
.replace(/\x1B\[2J/g, '')
|
|
26
31
|
.replace(/\x1B\[H/g, '');
|
|
27
32
|
if (cleaned.length > 0) {
|
|
28
|
-
stdout.write(
|
|
33
|
+
stdout.write(cleaned);
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
else {
|
|
32
|
-
|
|
37
|
+
if (str.length > 0) {
|
|
38
|
+
stdout.write(str);
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
@@ -93,9 +100,7 @@ const Session = ({ session, sessionManager, onReturnToMenu, }) => {
|
|
|
93
100
|
if (isExiting)
|
|
94
101
|
return;
|
|
95
102
|
// Check for return to menu shortcut
|
|
96
|
-
|
|
97
|
-
const shortcutCode = shortcutManager.getShortcutCode(returnToMenuShortcut);
|
|
98
|
-
if (shortcutCode && data === shortcutCode) {
|
|
103
|
+
if (shortcutManager.matchesRawInput('returnToMenu', data)) {
|
|
99
104
|
// Disable focus reporting mode before returning to menu
|
|
100
105
|
if (stdout) {
|
|
101
106
|
stdout.write('\x1b[?1004l');
|
|
@@ -7,8 +7,10 @@ export declare class ShortcutManager {
|
|
|
7
7
|
private isReservedKey;
|
|
8
8
|
saveShortcuts(shortcuts: ShortcutConfig): boolean;
|
|
9
9
|
getShortcuts(): ShortcutConfig;
|
|
10
|
+
private getRawShortcutCodes;
|
|
10
11
|
matchesShortcut(shortcutName: keyof ShortcutConfig, input: string, key: Key): boolean;
|
|
11
12
|
getShortcutDisplay(shortcutName: keyof ShortcutConfig): string;
|
|
12
13
|
getShortcutCode(shortcut: ShortcutKey): string | null;
|
|
14
|
+
matchesRawInput(shortcutName: keyof ShortcutConfig, input: string): boolean;
|
|
13
15
|
}
|
|
14
16
|
export declare const shortcutManager: ShortcutManager;
|
|
@@ -60,6 +60,51 @@ export class ShortcutManager {
|
|
|
60
60
|
getShortcuts() {
|
|
61
61
|
return configurationManager.getShortcuts();
|
|
62
62
|
}
|
|
63
|
+
getRawShortcutCodes(shortcut) {
|
|
64
|
+
const codes = new Set();
|
|
65
|
+
// Direct control-code form (e.g. Ctrl+E -> \u0005)
|
|
66
|
+
const controlCode = this.getShortcutCode(shortcut);
|
|
67
|
+
if (controlCode) {
|
|
68
|
+
codes.add(controlCode);
|
|
69
|
+
}
|
|
70
|
+
// Escape key in raw mode
|
|
71
|
+
if (shortcut.key === 'escape' &&
|
|
72
|
+
!shortcut.ctrl &&
|
|
73
|
+
!shortcut.alt &&
|
|
74
|
+
!shortcut.shift) {
|
|
75
|
+
codes.add('\u001b');
|
|
76
|
+
}
|
|
77
|
+
// Kitty/xterm extended keyboard sequences (CSI <code>;<mod>u)
|
|
78
|
+
if (shortcut.ctrl &&
|
|
79
|
+
!shortcut.alt &&
|
|
80
|
+
!shortcut.shift &&
|
|
81
|
+
shortcut.key.length === 1) {
|
|
82
|
+
const lower = shortcut.key.toLowerCase();
|
|
83
|
+
const upperCode = lower.toUpperCase().charCodeAt(0);
|
|
84
|
+
const lowerCode = lower.charCodeAt(0);
|
|
85
|
+
// Include the CSI u format (ESC[<code>;5u) used by Kitty/WezTerm for Ctrl+letters.
|
|
86
|
+
if (upperCode >= 32 && upperCode <= 126) {
|
|
87
|
+
codes.add(`\u001b[${upperCode};5u`);
|
|
88
|
+
}
|
|
89
|
+
if (lowerCode !== upperCode && lowerCode >= 32 && lowerCode <= 126) {
|
|
90
|
+
codes.add(`\u001b[${lowerCode};5u`);
|
|
91
|
+
}
|
|
92
|
+
// Tmux/xterm with modifyOtherKeys emit ESC[27;5;<code>~ for the same shortcut.
|
|
93
|
+
if (upperCode >= 32 && upperCode <= 126) {
|
|
94
|
+
codes.add(`\u001b[27;5;${upperCode}~`);
|
|
95
|
+
}
|
|
96
|
+
if (lowerCode !== upperCode && lowerCode >= 32 && lowerCode <= 126) {
|
|
97
|
+
codes.add(`\u001b[27;5;${lowerCode}~`);
|
|
98
|
+
}
|
|
99
|
+
// Some setups (issue #82/#107 repros) send ESC[1;5<letter>; include both upper/lower.
|
|
100
|
+
const upperKey = lower.toUpperCase();
|
|
101
|
+
codes.add(`\u001b[1;5${upperKey}`);
|
|
102
|
+
if (upperKey !== lower) {
|
|
103
|
+
codes.add(`\u001b[1;5${lower}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return Array.from(codes);
|
|
107
|
+
}
|
|
63
108
|
matchesShortcut(shortcutName, input, key) {
|
|
64
109
|
const shortcuts = configurationManager.getShortcuts();
|
|
65
110
|
const shortcut = shortcuts[shortcutName];
|
|
@@ -115,5 +160,13 @@ export class ShortcutManager {
|
|
|
115
160
|
}
|
|
116
161
|
return null;
|
|
117
162
|
}
|
|
163
|
+
matchesRawInput(shortcutName, input) {
|
|
164
|
+
const shortcuts = configurationManager.getShortcuts();
|
|
165
|
+
const shortcut = shortcuts[shortcutName];
|
|
166
|
+
if (!shortcut)
|
|
167
|
+
return false;
|
|
168
|
+
const codes = this.getRawShortcutCodes(shortcut);
|
|
169
|
+
return codes.some(code => input === code || input.includes(code));
|
|
170
|
+
}
|
|
118
171
|
}
|
|
119
172
|
export const shortcutManager = new ShortcutManager();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import { shortcutManager } from './shortcutManager.js';
|
|
3
|
+
import { configurationManager } from './configurationManager.js';
|
|
4
|
+
describe('shortcutManager.matchesRawInput', () => {
|
|
5
|
+
const shortcuts = {
|
|
6
|
+
returnToMenu: { ctrl: true, key: 'e', alt: false, shift: false },
|
|
7
|
+
cancel: { ctrl: true, key: 'c', alt: false, shift: false },
|
|
8
|
+
};
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
vi.spyOn(configurationManager, 'getShortcuts').mockReturnValue(shortcuts);
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.restoreAllMocks();
|
|
14
|
+
});
|
|
15
|
+
it('matches classic control code', () => {
|
|
16
|
+
expect(shortcutManager.matchesRawInput('returnToMenu', '\u0005')).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it('matches CSI u sequence', () => {
|
|
19
|
+
expect(shortcutManager.matchesRawInput('returnToMenu', '\u001b[69;5u')).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
it('matches modifyOtherKeys sequence', () => {
|
|
22
|
+
expect(shortcutManager.matchesRawInput('returnToMenu', '\u001b[27;5;69~')).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('matches CSI 1;5<key>', () => {
|
|
25
|
+
expect(shortcutManager.matchesRawInput('returnToMenu', '\u001b[1;5E')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('ignores unrelated input', () => {
|
|
28
|
+
expect(shortcutManager.matchesRawInput('returnToMenu', 'hello')).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|