Created
July 29, 2014 08:21
-
-
Save alan-mushi/140a3988cd47c28dca37 to your computer and use it in GitHub Desktop.
Simple wrapping of mvwprintw-like using va_list in ncurses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is a simple example of va_list function in ncurses. | |
* I use it to wrap mvwprintw() and print something in a footer. | |
* | |
* How to run: | |
* gcc -o test va_list_ncurses.c -lncurses | |
*/ | |
#include <ncurses.h> | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <assert.h> | |
static WINDOW *win; | |
void print_in_footer(bool is_error, const char *fmt, ...) | |
{ | |
va_list args; | |
mvwprintw(win, 22, 1, (is_error ? "[ERROR] " : "[INFO] ")); | |
va_start(args, fmt); | |
assert(fmt != NULL); | |
assert(args != NULL); | |
vwprintw(win, fmt, args); | |
va_end(args); | |
wprintw(win, "\n"); | |
wrefresh(win); | |
} | |
int main() | |
{ | |
int ch; | |
bool err = false; | |
initscr(); | |
noecho(); | |
cbreak(); | |
win = newwin(24, 80, 0, 0); | |
box(win, 0, 0); | |
refresh(); | |
print_in_footer(false, "Press q to exit and any other key to print" | |
" something in the footer."); | |
while ((ch = getch()) != 'q') | |
print_in_footer((err = !err), "hello %d, %s" , 23, "hey"); | |
endwin(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment