From efc32fd973768d4b1fbc4945d9ffa0dcbdf5e55a Mon Sep 17 00:00:00 2001 From: Txus Ordorika Date: Thu, 21 Feb 2019 00:20:44 +0100 Subject: [PATCH] basic example with ncurses --- .gitignore | 2 ++ src/main.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .gitignore create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6cc789e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +a.out diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..39f4c58 --- /dev/null +++ b/src/main.c @@ -0,0 +1,31 @@ +#include + +int main() { + int ch; + + initscr(); /* Start curses mode */ + raw(); /* Line buffering disabled */ + keypad(stdscr, TRUE); /* We get F1, F2 etc.. */ + noecho(); /* Don't echo() while we do getch */ + + printw("Type any character to see it in bold\n"); + ch = getch(); /* If raw() hadn't been called + * we have to press enter before it + * gets to the program */ + if (ch == KEY_F(1)) /* Without keypad enabled this will */ + printw("F1 Key pressed"); /* not get to us either */ + /* Without noecho() some ugly escape + * charachters might have been printed + * on screen */ + else { + printw("The pressed key is "); + attron(A_BOLD); + printw("%c", ch); + attroff(A_BOLD); + } + refresh(); /* Print it on to the real screen */ + getch(); /* Wait for user input */ + endwin(); /* End curses mode */ + + return 0; +}