Getting terminal size in c for windows?

This prints the size of the console, not the buffer: #include <windows.h> int main(int argc, char *argv[]) { CONSOLE_SCREEN_BUFFER_INFO csbi; int columns, rows; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); columns = csbi.srWindow.Right – csbi.srWindow.Left + 1; rows = csbi.srWindow.Bottom – csbi.srWindow.Top + 1; printf(“columns: %d\n”, columns); printf(“rows: %d\n”, rows); return 0; } This code works because srWindow “contains the … Read more

Preventing MSYS ‘bash’ from killing processes that trap ^C

I had the exact same problem – I had written a program with a SIGINT/SIGTERM handler. That handler did clean-up work which sometimes took awhile. When I ran the program from within msys bash, ctrl-c would cause my SIGINT handler to fire, but it would not finish – the program was terminated (“from the outside”, … Read more

Console App Terminating Before async Call Completion

Yes. Use a ManualResetEvent, and have the async callback call event.Set(). If the Main routine blocks on event.WaitOne(), it won’t exit until the async code completes. The basic pseudo-code would look like: static ManualResetEvent resetEvent = new ManualResetEvent(false); static void Main() { CallAsyncMethod(); resetEvent.WaitOne(); // Blocks until “set” } void DownloadDataCallback() { // Do your … Read more

Output Unicode strings in Windows console

I have verified a solution here using Visual Studio 2010. Via this MSDN article and MSDN blog post. The trick is an obscure call to _setmode(…, _O_U16TEXT). Solution: #include <iostream> #include <io.h> #include <fcntl.h> int wmain(int argc, wchar_t* argv[]) { _setmode(_fileno(stdout), _O_U16TEXT); std::wcout << L”Testing unicode — English — Ελληνικά — Español.” << std::endl; } … Read more

Colored text output in PowerShell console using ANSI / VT100 codes

Note: The following applies to regular console windows on Windows (provided by conhost.exe), which are used by default, including when a console application is launched from a GUI application. By contrast, the console windows (terminals) provided by Windows Terminal as well as Visual Studio Code’s integrated terminal provide support for VT / ANSI escape sequences … Read more

Displaying Unicode in Powershell

Note: On Windows, with respect to rendering Unicode characters, it is primarily the choice of font / console (terminal) application that matters. Nowadays, using Windows Terminal, which is distributed and updated via the Microsoft Store since Windows 10, is a good replacement for the legacy console host (console windows provided by conhost.exe), providing superior Unicode … Read more