SBoudrias/Inquirer.js

Do not show the selected option again / closes automatically

Bes-js opened this issue · 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?

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

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();
};
20240216-2103-14.4707216.mp4

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.

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

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

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