How to make win32 console recognize ANSI/VT100 escape sequences in `c`?

[UPDATE] For latest Windows 10 please read useful contribution by @brainslugs83, just below in the comments to this answer. While for versions before Windows 10 Anniversary Update: ANSI.SYS has a restriction that it can run only in the context of the MS-DOS sub-system under Windows 95-Vista. Microsoft KB101875 explains how to enable ANSI.SYS in a … Read more

ncurses multi colors on screen

Here’s a working version: #include <curses.h> int main(void) { initscr(); start_color(); init_pair(1, COLOR_BLACK, COLOR_RED); init_pair(2, COLOR_BLACK, COLOR_GREEN); attron(COLOR_PAIR(1)); printw(“This should be printed in black with a red background!\n”); attron(COLOR_PAIR(2)); printw(“And this in a green background!\n”); refresh(); getch(); endwin(); } Notes: you need to call start_color() after initscr() to use color. you have to use the … Read more

Qt macro keywords cause name collisions

You can define the QT_NO_KEYWORDS macro, that disables the “signals” and “slots” macros. If you use QMake: CONFIG += no_keywords (Qt Documentation here) If you’re using another build system, do whatever it needs to pass -DQT_NO_KEYWORDS to the compiler. Defining QT_NO_KEYWORDS will require you to change occurrences of signals to Q_SIGNALS and slots to Q_SLOTS … Read more

Printing a Unicode Symbol in C

Two problems: first of all, a wchar_t must be printed with %lc format, not %c. The second one is that unless you call setlocale the character set is not set properly, and you probably get ? instead of your star. The following code seems to work though: #include <stdio.h> #include <wchar.h> #include <locale.h> int main() … Read more

Non-blocking getch(), ncurses

The curses library is a package deal. You can’t just pull out one routine and hope for the best without properly initializing the library. Here’s a code that correctly blocks on getch(): #include <curses.h> int main(void) { initscr(); timeout(-1); int c = getch(); endwin(); printf (“%d %c\n”, c, c); return 0; }

Ncurses and Qt Interoperability

Use QSocketNotifier to be notified of things being available on stdin. Call nonblocking getch() in a loop until no more input is available. This is vitally important: the notifier will notify only when new data is available, but this doesn’t mean that it notifies on every character! If you receive multiple characters at a time, … Read more