@franzzemen/brokenstock-shell 0.9.1 → 0.9.2
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.
|
@@ -3068,6 +3068,12 @@ class PendingPromptState {
|
|
|
3068
3068
|
const CommandInputSchema = z.string().trim().min(1, 'Command cannot be empty');
|
|
3069
3069
|
class CommandService {
|
|
3070
3070
|
#prompts;
|
|
3071
|
+
/**
|
|
3072
|
+
* True while a command (or an answer) runs. A question it asks is written to the history only
|
|
3073
|
+
* after the command's own lines, so it reads as the last thing said, under the preview it is about.
|
|
3074
|
+
*/
|
|
3075
|
+
#running;
|
|
3076
|
+
#deferredQuestion;
|
|
3071
3077
|
constructor() {
|
|
3072
3078
|
this.history = signal([], /* @ts-ignore */
|
|
3073
3079
|
...(ngDevMode ? [{ debugName: "history" }] : /* istanbul ignore next */ []));
|
|
@@ -3084,6 +3090,11 @@ class CommandService {
|
|
|
3084
3090
|
this.pending = signal(null, /* @ts-ignore */
|
|
3085
3091
|
...(ngDevMode ? [{ debugName: "pending" }] : /* istanbul ignore next */ []));
|
|
3086
3092
|
this.#prompts = new PendingPromptState();
|
|
3093
|
+
/**
|
|
3094
|
+
* True while a command (or an answer) runs. A question it asks is written to the history only
|
|
3095
|
+
* after the command's own lines, so it reads as the last thing said, under the preview it is about.
|
|
3096
|
+
*/
|
|
3097
|
+
this.#running = false;
|
|
3087
3098
|
this.authService = inject(AuthenticationService);
|
|
3088
3099
|
this.registry = inject(CommandRegistryService);
|
|
3089
3100
|
this.router = inject(Router);
|
|
@@ -3108,11 +3119,25 @@ class CommandService {
|
|
|
3108
3119
|
ask(prompt) {
|
|
3109
3120
|
this.#prompts.ask(prompt);
|
|
3110
3121
|
this.pending.set(prompt);
|
|
3122
|
+
if (this.#running)
|
|
3123
|
+
this.#deferredQuestion = prompt;
|
|
3124
|
+
else
|
|
3125
|
+
this.#writeQuestion(prompt);
|
|
3126
|
+
}
|
|
3127
|
+
#writeQuestion(prompt) {
|
|
3111
3128
|
this.history.update(h => [...h, {
|
|
3112
3129
|
input: '',
|
|
3113
3130
|
result: { success: true, message: prompt.question, timestamp: new Date(), severity: 'info' },
|
|
3114
3131
|
}]);
|
|
3115
3132
|
}
|
|
3133
|
+
/** After a command's or an answer's own lines: the question it asked, if it is still open. */
|
|
3134
|
+
#finishRun() {
|
|
3135
|
+
this.#running = false;
|
|
3136
|
+
const q = this.#deferredQuestion;
|
|
3137
|
+
this.#deferredQuestion = undefined;
|
|
3138
|
+
if (q && this.#prompts.current === q)
|
|
3139
|
+
this.#writeQuestion(q);
|
|
3140
|
+
}
|
|
3116
3141
|
/** Esc: closes the open question, if any. True when there was one. */
|
|
3117
3142
|
cancelPending() {
|
|
3118
3143
|
if (!this.#prompts.cancel())
|
|
@@ -3135,11 +3160,9 @@ class CommandService {
|
|
|
3135
3160
|
this.currentInput.set('');
|
|
3136
3161
|
const record = (result) => {
|
|
3137
3162
|
this.history.update(h => [...h, { input: echo, result }]);
|
|
3138
|
-
|
|
3139
|
-
const next = this.#prompts.current;
|
|
3140
|
-
if (next && next !== this.pending())
|
|
3141
|
-
this.pending.set(next);
|
|
3163
|
+
this.#finishRun();
|
|
3142
3164
|
};
|
|
3165
|
+
this.#running = true;
|
|
3143
3166
|
let out;
|
|
3144
3167
|
try {
|
|
3145
3168
|
out = prompt.answer(text);
|
|
@@ -3200,7 +3223,14 @@ class CommandService {
|
|
|
3200
3223
|
// masked under `login` stays masked under any other word for it).
|
|
3201
3224
|
const def = this.registry.resolve(command)?.command;
|
|
3202
3225
|
const displayInput = def?.sanitizeInput ? def.sanitizeInput(input) : input;
|
|
3203
|
-
|
|
3226
|
+
this.#running = true;
|
|
3227
|
+
let resultOrPromise;
|
|
3228
|
+
try {
|
|
3229
|
+
resultOrPromise = this.#dispatch(command, parts.slice(1));
|
|
3230
|
+
}
|
|
3231
|
+
catch (err) {
|
|
3232
|
+
resultOrPromise = { success: false, message: err?.message ?? String(err), timestamp: new Date() };
|
|
3233
|
+
}
|
|
3204
3234
|
this.currentInput.set('');
|
|
3205
3235
|
if (resultOrPromise instanceof Promise) {
|
|
3206
3236
|
this.isProcessing.set(true);
|
|
@@ -3214,7 +3244,10 @@ class CommandService {
|
|
|
3214
3244
|
this.history.update(h => [...h, { input: displayInput, result: historyResult, repeatCount: 1 }]);
|
|
3215
3245
|
}
|
|
3216
3246
|
})
|
|
3217
|
-
.finally(() =>
|
|
3247
|
+
.finally(() => {
|
|
3248
|
+
this.#finishRun();
|
|
3249
|
+
this.isProcessing.set(false);
|
|
3250
|
+
});
|
|
3218
3251
|
}
|
|
3219
3252
|
else {
|
|
3220
3253
|
if (resultOrPromise.isHelp && resultOrPromise.message) {
|
|
@@ -3224,6 +3257,7 @@ class CommandService {
|
|
|
3224
3257
|
if (!this.#coalesce(displayInput)) {
|
|
3225
3258
|
this.history.update(h => [...h, { input: displayInput, result: historyResult, repeatCount: 1 }]);
|
|
3226
3259
|
}
|
|
3260
|
+
this.#finishRun();
|
|
3227
3261
|
}
|
|
3228
3262
|
}
|
|
3229
3263
|
#coalesce(input) {
|