@pikecode/api-key-manager 1.3.0 → 1.3.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.
- package/package.json +1 -1
- package/src/commands/switch.js +27 -19
package/package.json
CHANGED
package/src/commands/switch.js
CHANGED
|
@@ -36,7 +36,14 @@ class EnvSwitcher extends BaseCommand {
|
|
|
36
36
|
this.currentPromptContext = null;
|
|
37
37
|
this.activeStatusRefresh = null;
|
|
38
38
|
this.filter = null;
|
|
39
|
-
this.filteredProviders = null;
|
|
39
|
+
this.filteredProviders = null;
|
|
40
|
+
this._refreshTimer = null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_getPageSize(itemCount) {
|
|
44
|
+
const rows = process.stdout.rows || 24;
|
|
45
|
+
const reserved = 8;
|
|
46
|
+
return Math.min(itemCount, Math.max(5, rows - reserved));
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
async validateProvider(providerName) {
|
|
@@ -296,14 +303,7 @@ class EnvSwitcher extends BaseCommand {
|
|
|
296
303
|
message: promptMessage,
|
|
297
304
|
choices,
|
|
298
305
|
default: defaultChoice,
|
|
299
|
-
pageSize:
|
|
300
|
-
}
|
|
301
|
-
]);
|
|
302
|
-
|
|
303
|
-
// 移除 ESC 键监听
|
|
304
|
-
this.removeESCListener(escListener);
|
|
305
|
-
|
|
306
|
-
this._cancelStatusRefresh();
|
|
306
|
+
pageSize: this._getPageSize(choices.length)
|
|
307
307
|
|
|
308
308
|
if (answer.provider === '__OPEN_CONFIG__') {
|
|
309
309
|
await this.openConfigFile();
|
|
@@ -785,12 +785,7 @@ class EnvSwitcher extends BaseCommand {
|
|
|
785
785
|
name: 'action',
|
|
786
786
|
message: `选择供应商或操作 (总计 ${providers.length} 个):`,
|
|
787
787
|
choices,
|
|
788
|
-
pageSize:
|
|
789
|
-
}
|
|
790
|
-
]);
|
|
791
|
-
} catch (error) {
|
|
792
|
-
this.removeESCListener(escListener);
|
|
793
|
-
if (this.isEscCancelled(error)) {
|
|
788
|
+
pageSize: this._getPageSize(choices.length)
|
|
794
789
|
return;
|
|
795
790
|
}
|
|
796
791
|
throw error;
|
|
@@ -877,6 +872,10 @@ class EnvSwitcher extends BaseCommand {
|
|
|
877
872
|
|
|
878
873
|
_cancelStatusRefresh() {
|
|
879
874
|
this.activeStatusRefresh = null;
|
|
875
|
+
if (this._refreshTimer) {
|
|
876
|
+
clearTimeout(this._refreshTimer);
|
|
877
|
+
this._refreshTimer = null;
|
|
878
|
+
}
|
|
880
879
|
}
|
|
881
880
|
|
|
882
881
|
_applyStatusUpdate(providers, statusMap, error, refreshToken = null) {
|
|
@@ -908,10 +907,19 @@ class EnvSwitcher extends BaseCommand {
|
|
|
908
907
|
return;
|
|
909
908
|
}
|
|
910
909
|
|
|
911
|
-
//
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
910
|
+
// 节流:80ms 内的多次回调合并为一次 render,避免高频刷新导致 ANSI 光标错位
|
|
911
|
+
if (this._refreshTimer) {
|
|
912
|
+
clearTimeout(this._refreshTimer);
|
|
913
|
+
}
|
|
914
|
+
this._refreshTimer = setTimeout(() => {
|
|
915
|
+
this._refreshTimer = null;
|
|
916
|
+
if (this.activeStatusRefresh !== refreshToken) return;
|
|
917
|
+
const activeP = this.activePrompt?.promise?.ui?.activePrompt;
|
|
918
|
+
if (!activeP || activeP.status === 'answered') return;
|
|
919
|
+
const providers = this.filteredProviders || this.configManager.listProviders();
|
|
920
|
+
const statusMap = this.latestStatusMap || {};
|
|
921
|
+
this._refreshPromptChoices(activeP, providers, statusMap);
|
|
922
|
+
}, 80);
|
|
915
923
|
}
|
|
916
924
|
|
|
917
925
|
_refreshPromptChoices(activePrompt, providers, statusMap, options = {}) {
|