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

CliLocalSession waits for keypress when exiting #209

Open
marcogmaia opened this issue Aug 20, 2023 · 4 comments
Open

CliLocalSession waits for keypress when exiting #209

marcogmaia opened this issue Aug 20, 2023 · 4 comments

Comments

@marcogmaia
Copy link
Contributor

marcogmaia commented Aug 20, 2023

I'm running the software on Window10.

The following snippet reproduces the behavior:

int main() {
  std::atexit([]() { std::cout << "Exiting from main."; });

  auto cli = cli::Cli(std::make_unique<cli::Menu>("cli"));
  cli.ExitAction([](auto &out) { out << "Waiting for extra keypress...\n"; });

  auto scheduler = cli::LoopScheduler();
  auto session = cli::CliLocalSession(cli, scheduler, std::cout, 400);
  session.ExitAction([&scheduler](auto &out) {
    scheduler.Stop();
    out << "Stopping scheduler...\n";
  });

  scheduler.Run();

  return 0;
}

produces the following behavior when exiting

cli> exit 
Stopping scheduler...
Waiting for extra keypress...

but the expected is:

cli> exit 
Stopping scheduler...
Waiting for extra keypress...
Exiting from main.
@daniele77
Copy link
Owner

Hi @marcogmaia ,

first of all, thank you very much for using this library.

I tried your code in the following environment:

  • visual studio 2022, Debug build
  • visual studio 2022, Release build
  • linux kubuntu, GCC v. 11.4.0

In all three cases, I've got the expected output:

c:\Progetti\github\esempi_cli\cli_example\x64\Release>cli_example.exe
cli> exit
Stopping scheduler...
Waiting for extra keypress...
Exiting from main.
c:\Progetti\github\esempi_cli\cli_example\x64\Release>

(no extra keypress needed, by the way: I've just entered "exit" followed by key).

The complete code is:

#include <cli/loopscheduler.h>
#include "cli/clilocalsession.h"
#include "cli/cli.h"

int main() {
    std::atexit([]() { std::cout << "Exiting from main."; });

    auto cli = cli::Cli(std::make_unique<cli::Menu>("cli"));
    cli.ExitAction([](auto& out) { out << "Waiting for extra keypress...\n"; });

    auto scheduler = cli::LoopScheduler();
    auto session = cli::CliLocalSession(cli, scheduler, std::cout, 400);
    session.ExitAction([&scheduler](auto& out) {
        scheduler.Stop();
        out << "Stopping scheduler...\n";
    });

    scheduler.Run();

    return 0;
}

using C++20 standard and the latest version of cli library (i.e., v. 2.1).

Please, let me know what differs from your environment.

@marcogmaia
Copy link
Contributor Author

marcogmaia commented Sep 1, 2023

@daniele77, thanks man. I'll test with your configs when I get the time. I compiled with clang on windows.

@marcogmaia
Copy link
Contributor Author

It seems to correctly work with PowerShell, the issue that I was experiencing was with some integrated terminals, like the VSCode integrated terminal and Windows terminal, but if the application is used in a standalone mode it works correctly.
I've tested with msvc2022 and clang17.

@marcogmaia
Copy link
Contributor Author

clitest_vid.mp4

An example using the code that you've provided.

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

No branches or pull requests

2 participants