[Powertop] [PATCH 1/2] lib: introduce ui_notify_user()

Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
Newsgroups dev.linux.lists.powertop
Message-ID <[email protected]>
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(+)

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));
+}
diff --git a/src/lib.h b/src/lib.h
index 2caf12f..adcc4a2 100644
--- a/src/lib.h
+++ b/src/lib.h
@@ -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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.