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

Do not show the selected option again / closes automatically

Open Bes-js opened this issue 1 year ago • 8 comments

I use list and it works in a function called mainMenu. I run this function at startup. After selecting an action from it, it sends it to another list section and produces a list to return. After returning from here, I run the mainMenu function again, but when I select the same option, it closes for no reason. The solution to this is are there?

Bes-js avatar Feb 16 '24 20:02 Bes-js

Hi, this is unlikely an issue coming from inquirer. Do you have code example?

SBoudrias avatar Feb 16 '24 20:02 SBoudrias

mainMenu function

async function mainMenu(){

    child_process.execSync('cls');

    await db.prepare('CREATE TABLE IF NOT EXISTS lang (value TEXT)').run();
   
    var langData = await db.prepare('SELECT * FROM lang').get();
    if(langData)lang.setLang(langData.value);
    if(!langData){
    var newLang = await setNewLanguage();
    await db.prepare('INSERT INTO lang (value) VALUES (?) ').run(newLang);
    lang.setLang(newLang);
    };

    var mainMenu = await select({
    message: lang.getText('main_menu'),
    theme:{ icon: { cursor: '=>' }},
    loop: false,
    choices: getChoices(arr)
    });

    import(`./events/${mainMenu}.mjs`);
   // arr.push(mainMenu);
    
};

selected list function

import { returnMainMenu, lang, setNewLanguage } from '../cli.js';
import db from '../services/database.js';
import child_process from 'child_process';


const select_new_lang = async () => {
var newLang = await setNewLanguage();
await db.prepare('UPDATE lang SET value = ? ').run(newLang);
lang.setLang(newLang);
child_process.execSync('cls');
return returnMainMenu();
};
select_new_lang();

return mainMenu function

async function returnMainMenu(){
child_process.execSync('cls');
var value = await select({
    message: lang.getText('return_to_main_menu'),
    choices: [
        {name:lang.getText('yes'),value:'return'},
        {name:lang.getText('no'),value:'exit'}
    ]
});
if(value == 'exit')child_process.execSync('exit');
if(value == 'return')mainMenu();
};

Bes-js avatar Feb 16 '24 20:02 Bes-js

https://github.com/SBoudrias/Inquirer.js/assets/89789101/78b76f18-3918-44cd-9c4e-015eb8ae10b2

Bes-js avatar Feb 16 '24 21:02 Bes-js

@SBoudrias

Bes-js avatar Feb 17 '24 10:02 Bes-js

Hi @Bes-js, there's a lot going on there.

What might help you is to simplify the case. Only make a recursive prompt with inquirer - see it works. Then add pieces by pieces and you'll likely find out where it breaks.

SBoudrias avatar Feb 18 '24 17:02 SBoudrias

When I opened a new project and tried just select from scratch, the same problem occurred again.

Bes-js avatar Feb 20 '24 13:02 Bes-js

It looks like a problem with the package, but when I tried such things in other languages it didn't cause any problems.

Bes-js avatar Feb 20 '24 13:02 Bes-js

Can you share your new project reproduction so I can run it?

SBoudrias avatar Feb 20 '24 15:02 SBoudrias