Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

using context signal: currentAbortController.signal, the error does not contain the last selected/ current selected

Open BananaAcid opened this issue 8 months ago • 3 comments

The abort error does not pass the last highlighted or selected elements along.

Problem: Last state is unknown.

For legacy Inquirer there was some rxjs way of accessing the options? or selections? Is there something similar to work araound this issue?

import { select, checkbox } from '@inquirer/prompts';

let currentAbortController = new AbortController();
setTimeout(_ => currentAbortController.abort(), 2000);

let selection = await checkbox({
    message: 'Select something',
    choices: choices,
}, {
    signal: currentAbortController.signal,
    clearPromptOnDone: true
}).catch(e => {errorWith: error.lastSelected}) ;  // <-- this would be missing: error.lastSelected

if (selection.errorWith) {
    console.log('errored');
    selection = selection.errorWith;
}

console.log('selection', selection);

BananaAcid avatar Apr 17 '25 18:04 BananaAcid

Hi, I hadn't considered this use-case. I think it's valid, but it'll need some architecting and to give some thoughts to properly typing this so it doesn't lead to undue complexity.

SBoudrias avatar Apr 17 '25 20:04 SBoudrias

Possible use case: This would be useful to be able to continue a prompt (some text already written) or selection (checkboxes or alike) later, if it was aborted due to outside circumstances that need another prompt due to some intervention.

BananaAcid avatar Apr 17 '25 20:04 BananaAcid

I wonder if instead of adding the value to the error, we should add an option to not throw but return the selected option once the signal exit. That'd also clean the user code VS having to catch and handle.

SBoudrias avatar Apr 17 '25 21:04 SBoudrias