diff options
author | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> | 2013-10-09 19:31:40 +0300 |
---|---|---|
committer | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> | 2013-10-09 19:31:40 +0300 |
commit | cdc92baf2760260cc4238c99a03fe41d0c6ca991 (patch) | |
tree | 0a3fd5e177a67cad407e0416d36d7a3a29317bf2 | |
parent | b1668c39bb77fa5d0b9f0effc7646ee94948a3af (diff) |
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@gmail.com>
-rw-r--r-- | src/lib.cpp | 20 | ||||
-rw-r--r-- | src/lib.h | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/lib.cpp b/src/lib.cpp index f27ec2f..a8f3746 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -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)); +} @@ -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 |