Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erase Everything - How? #234

Open
juliuszfedyk opened this issue Apr 29, 2023 · 1 comment
Open

Erase Everything - How? #234

juliuszfedyk opened this issue Apr 29, 2023 · 1 comment

Comments

@juliuszfedyk
Copy link

Hi, I'm playing around with terminal-kit and what I'm trying to do is to create a navigation. Once the users submits on a menu I want to rewrite everything and draw a new document. However the menu never gets removed from the screen.

https://github.com/juliuszfedyk/termigram

@GothMetalhead
Copy link

you can use term.clear() or term.eraseDisplay() fo this things
Theres a code snippet for what you asked:

...
const menuOptions = {
    y: 1,
    style: term.inverse,
    selectedStyle: term.dim.blue.bgGreen,
    cancelable: true
};

function displayMenu() {
    term.clear();
    term.singleLineMenu(menuItems, menuOptions, function (error, response) {
        if (error) {
            term.red.bold('Error: %s\n', error);
            process.exit(1);
        }

        if (response.canceled) {
            term.red.bold('Menu canceled\n');
            process.exit();
        }

        // After selecting clear screen and write new content
        term.clear();

        switch (response.selectedText) {
            case 'Home':
                term.green('Welcome to the Home page!\n');
                break;
            case 'Settings':
                term.yellow('Here are the Settings.\n');
                break;
            case 'Profile':
                term.blue('This is your Profile.\n');
                break;
            case 'Exit':
                term.red('Exiting...\n');
                process.exit();
                break;
            default:
                term('Unknown selection.\n');
                break;
        }

        // after drawing new content return to the menu
        setTimeout(displayMenu, 2000); // after 2 secs show menu
    });
}

// show first menu
displayMenu();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants