lib: introduce ui_notify_user()
Sergey Senozhatsky
PATCH 1/2 lib: introduce ui_notify_user()
ui_notify_user(frmt, ...) prints formatted notification string at (x:1, y:0) WINDOW position.
use fixed UI_NOTIFY_BUFF_SZ size buffer, because there seems to be no ncurses() *print function which takes int x, int y WINDOW coordinates and va_list.
Signed-off-by Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
--- src/lib.cpp | 20 ++++++++++++++++++++ src/lib.h | 2 ++ 2 files changed, 22 insertions(+)
src/lib.cpp +20 -0
@@ -528,3 +528,23 @@ int write_msr(int cpu, uint64_t offset, uint64_t value) return retval; } + +#define UI_NOTIFY_BUFF_SZ 2048 + +void ui_notify_user(const char *frmt, ...) +{ + char notify[UI_NOTIFY_BUFF_SZ]; + va_list list; + + start_color(); + init_pair(1, COLOR_BLACK, COLOR_WHITE); + attron(COLOR_PAIR(1)); + va_start(list, frmt); + /* there is no ncurses *print() function which takes + * int x, int y and va_list, this is why we use temp + * buffer */ + vsnprintf(notify, UI_NOTIFY_BUFF_SZ - 1, frmt, list); + va_end(list); + mvprintw(1, 0, notify); + attroff(COLOR_PAIR(1)); +}
src/lib.h +2 -0
@@ -78,4 +78,6 @@ extern int read_msr(int cpu, uint64_t offset, uint64_t *value);extern int write_msr (int cpu,uint64_t offset,uint64_t value);extern void align_string (char *buffer,size_t min_sz,size_t max_sz); + +extern void ui_notify_user (const char *frmt, ...);#endif