Skip to content

Instantly share code, notes, and snippets.

@tqbf
Created August 18, 2026 03:24
Show Gist options
  • Select an option

  • Save tqbf/064b87a76ce000bcdd4b366ed141d9bc to your computer and use it in GitHub Desktop.

Select an option

Save tqbf/064b87a76ce000bcdd4b366ed141d9bc to your computer and use it in GitHub Desktop.
curses.c
#include <curses.h>
int main(void)
{
initscr();
cbreak(); /* keys immediately, but ^C etc. still work */
noecho(); /* don't let getch() print them */
keypad(stdscr, TRUE); /* decode arrows/F-keys into KEY_* */
/* curs_set(0); */ /* optionally hide hardware cursor */
for (;;) {
erase();
mvaddstr(0, 0, "hello");
attron(A_REVERSE);
mvaddstr(LINES - 2, 0, " ^X Exit ^O Write Out ");
attroff(A_REVERSE);
move(0, 5); /* where physical cursor should end up */
refresh();
int c = getch();
if (c == 24) /* ^X */
break;
switch (c) {
case KEY_UP:
break;
case KEY_DOWN:
break;
case KEY_LEFT:
break;
case KEY_RIGHT:
break;
}
}
endwin();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment