Introduce library routine get_user_input(char *buf, unsigned sz), which is used to obtain user input.
Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com> --- lib.cpp | 13 +++++++++++++ lib.h | 1 + 2 files changed, 14 insertions(+) diff --git a/lib.cpp b/lib.cpp index 109c48e..53638dd 100644 --- a/lib.cpp +++ b/lib.cpp @@ -56,6 +56,7 @@ extern "C" { #endif #include <limits> #include <math.h> +#include <ncurses.h> static int kallsyms_read = 0; @@ -400,3 +401,15 @@ void process_directory(const char *d_name, callback fn) closedir(dir); } + +int get_user_input(char *buf, unsigned sz) +{ + fflush(stdout); + echo(); + /* Upon successful completion, these functions return OK. Otherwise, they return ERR. */ + int ret = getnstr(buf, sz); + noecho(); + fflush(stdout); + /* to distinguish between getnstr error and empty line */ + return ret || strlen(buf); +} diff --git a/lib.h b/lib.h index 1282225..c345985 100644 --- a/lib.h +++ b/lib.h @@ -79,5 +79,6 @@ extern int equals(double a, double b); typedef void (*callback)(const char*); extern void process_directory(const char *d_name, callback fn); extern int utf_ok; +extern int get_user_input(char *buf, unsigned sz); #endif _______________________________________________ Power mailing list Power@bughost.org https://bughost.org/mailman/listinfo/power