clawt 3.8.6 → 3.8.7
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.
- package/dist/index.js +17 -13
- package/package.json +1 -1
- package/src/utils/interactive-panel.ts +21 -16
package/dist/index.js
CHANGED
|
@@ -4002,14 +4002,7 @@ var InteractivePanel = class {
|
|
|
4002
4002
|
this.clearTimers();
|
|
4003
4003
|
this.keyboardController.stop();
|
|
4004
4004
|
this.restoreTerminal();
|
|
4005
|
-
|
|
4006
|
-
process.stdout.removeListener("resize", this.resizeHandler);
|
|
4007
|
-
this.resizeHandler = null;
|
|
4008
|
-
}
|
|
4009
|
-
if (this.exitHandler) {
|
|
4010
|
-
process.removeListener("exit", this.exitHandler);
|
|
4011
|
-
this.exitHandler = null;
|
|
4012
|
-
}
|
|
4005
|
+
this.removeTerminalListeners();
|
|
4013
4006
|
if (this.resolveStart) {
|
|
4014
4007
|
this.resolveStart();
|
|
4015
4008
|
this.resolveStart = null;
|
|
@@ -4019,6 +4012,7 @@ var InteractivePanel = class {
|
|
|
4019
4012
|
* 初始化终端:进入备选屏幕、隐藏光标、禁用行换行
|
|
4020
4013
|
*/
|
|
4021
4014
|
initTerminal() {
|
|
4015
|
+
this.removeTerminalListeners();
|
|
4022
4016
|
process.stdout.write(ALT_SCREEN_ENTER);
|
|
4023
4017
|
process.stdout.write(CURSOR_HIDE);
|
|
4024
4018
|
process.stdout.write(LINE_WRAP_DISABLE);
|
|
@@ -4029,13 +4023,22 @@ var InteractivePanel = class {
|
|
|
4029
4023
|
}
|
|
4030
4024
|
};
|
|
4031
4025
|
process.stdout.on("resize", this.resizeHandler);
|
|
4032
|
-
this.exitHandler = () =>
|
|
4033
|
-
process.stdout.write(LINE_WRAP_ENABLE);
|
|
4034
|
-
process.stdout.write(CURSOR_SHOW);
|
|
4035
|
-
process.stdout.write(ALT_SCREEN_LEAVE);
|
|
4036
|
-
};
|
|
4026
|
+
this.exitHandler = () => this.restoreTerminal();
|
|
4037
4027
|
process.on("exit", this.exitHandler);
|
|
4038
4028
|
}
|
|
4029
|
+
/**
|
|
4030
|
+
* 移除终端事件监听器(resize 和 exit)
|
|
4031
|
+
*/
|
|
4032
|
+
removeTerminalListeners() {
|
|
4033
|
+
if (this.resizeHandler) {
|
|
4034
|
+
process.stdout.removeListener("resize", this.resizeHandler);
|
|
4035
|
+
this.resizeHandler = null;
|
|
4036
|
+
}
|
|
4037
|
+
if (this.exitHandler) {
|
|
4038
|
+
process.removeListener("exit", this.exitHandler);
|
|
4039
|
+
this.exitHandler = null;
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4039
4042
|
/**
|
|
4040
4043
|
* 恢复终端:启用行换行、显示光标、退出备选屏幕
|
|
4041
4044
|
*/
|
|
@@ -4178,6 +4181,7 @@ var InteractivePanel = class {
|
|
|
4178
4181
|
this.isOperating = true;
|
|
4179
4182
|
this.clearTimers();
|
|
4180
4183
|
this.restoreTerminal();
|
|
4184
|
+
this.removeTerminalListeners();
|
|
4181
4185
|
this.keyboardController.stop();
|
|
4182
4186
|
action();
|
|
4183
4187
|
console.log(PANEL_PRESS_ENTER_TO_RETURN);
|
package/package.json
CHANGED
|
@@ -125,17 +125,7 @@ export class InteractivePanel {
|
|
|
125
125
|
// 恢复终端
|
|
126
126
|
this.restoreTerminal();
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
if (this.resizeHandler) {
|
|
130
|
-
process.stdout.removeListener('resize', this.resizeHandler);
|
|
131
|
-
this.resizeHandler = null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 移除 exit 兜底
|
|
135
|
-
if (this.exitHandler) {
|
|
136
|
-
process.removeListener('exit', this.exitHandler);
|
|
137
|
-
this.exitHandler = null;
|
|
138
|
-
}
|
|
128
|
+
this.removeTerminalListeners();
|
|
139
129
|
|
|
140
130
|
// 完成 Promise
|
|
141
131
|
if (this.resolveStart) {
|
|
@@ -148,6 +138,9 @@ export class InteractivePanel {
|
|
|
148
138
|
* 初始化终端:进入备选屏幕、隐藏光标、禁用行换行
|
|
149
139
|
*/
|
|
150
140
|
private initTerminal(): void {
|
|
141
|
+
// 确保不会重复注册监听器
|
|
142
|
+
this.removeTerminalListeners();
|
|
143
|
+
|
|
151
144
|
process.stdout.write(ALT_SCREEN_ENTER);
|
|
152
145
|
process.stdout.write(CURSOR_HIDE);
|
|
153
146
|
process.stdout.write(LINE_WRAP_DISABLE);
|
|
@@ -163,14 +156,24 @@ export class InteractivePanel {
|
|
|
163
156
|
process.stdout.on('resize', this.resizeHandler);
|
|
164
157
|
|
|
165
158
|
// 注册 exit 兜底,确保异常退出时终端状态被恢复
|
|
166
|
-
this.exitHandler = () =>
|
|
167
|
-
process.stdout.write(LINE_WRAP_ENABLE);
|
|
168
|
-
process.stdout.write(CURSOR_SHOW);
|
|
169
|
-
process.stdout.write(ALT_SCREEN_LEAVE);
|
|
170
|
-
};
|
|
159
|
+
this.exitHandler = () => this.restoreTerminal();
|
|
171
160
|
process.on('exit', this.exitHandler);
|
|
172
161
|
}
|
|
173
162
|
|
|
163
|
+
/**
|
|
164
|
+
* 移除终端事件监听器(resize 和 exit)
|
|
165
|
+
*/
|
|
166
|
+
private removeTerminalListeners(): void {
|
|
167
|
+
if (this.resizeHandler) {
|
|
168
|
+
process.stdout.removeListener('resize', this.resizeHandler);
|
|
169
|
+
this.resizeHandler = null;
|
|
170
|
+
}
|
|
171
|
+
if (this.exitHandler) {
|
|
172
|
+
process.removeListener('exit', this.exitHandler);
|
|
173
|
+
this.exitHandler = null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
174
177
|
/**
|
|
175
178
|
* 恢复终端:启用行换行、显示光标、退出备选屏幕
|
|
176
179
|
*/
|
|
@@ -365,6 +368,8 @@ export class InteractivePanel {
|
|
|
365
368
|
|
|
366
369
|
// 恢复终端以便子命令输出
|
|
367
370
|
this.restoreTerminal();
|
|
371
|
+
// 移除旧的终端事件监听器,避免 initTerminal() 重复注册导致泄漏
|
|
372
|
+
this.removeTerminalListeners();
|
|
368
373
|
|
|
369
374
|
// 恢复 stdin 以便子命令交互
|
|
370
375
|
this.keyboardController.stop();
|