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

In Windows console, the progress bar does not stay on the same line #131

Open
arklev opened this issue Mar 25, 2024 · 3 comments
Open

In Windows console, the progress bar does not stay on the same line #131

arklev opened this issue Mar 25, 2024 · 3 comments

Comments

@arklev
Copy link

arklev commented Mar 25, 2024

image

The code used for this bar:
indicators::IndeterminateProgressBar bar{ indicators::option::BarWidth{40}, indicators::option::Start{"["}, indicators::option::Fill{"·"}, indicators::option::Lead{"<==>"}, indicators::option::End{"]"}, indicators::option::PostfixText{"Waiting For Mission Ready"}, indicators::option::ForegroundColor{indicators::Color::yellow}, indicators::option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}, indicators::option::Stream{std::cout} };

When running the program inside the new "Windows Terminal" it works as expected, but the CMD is not,
Is it the expected result or there is some hidden option to trigger for it to work?
I am on windows 10.

@tnnnnt
Copy link

tnnnnt commented Jul 24, 2024

Hi, I have the same problem as you, have you solved it?

@arklev
Copy link
Author

arklev commented Jul 24, 2024

Hi, I have the same problem as you, have you solved it?

Yes, i was able to make it work by setting the ENABLE_VIRTUAL_TERMINAL_PROCESSING.

Run this code before you initialize the bar.

        HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	if (hOut != INVALID_HANDLE_VALUE)
	{
		DWORD dwOriginalOutMode = 0;
		GetConsoleMode(hOut, &dwOriginalOutMode);

		// Enable ANSI escape code processing
		DWORD dwRequestedOutModes = dwOriginalOutMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
		if (!SetConsoleMode(hOut, dwRequestedOutModes)) {
			SetConsoleMode(hOut, dwOriginalOutMode);
		}
	}

@tnnnnt
Copy link

tnnnnt commented Jul 25, 2024

Thanks, that was a great help!

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