diff options
author | Tahsincan Köse | 2021-11-30 20:46:24 +0300 |
---|---|---|
committer | Tahsincan Köse | 2021-11-30 20:48:39 +0300 |
commit | ef2c1793d943c43fa1ebe2aa632270aa308012a2 (patch) | |
tree | e6628375eceed2f9929c1ace1d604dddd532df40 /src | |
parent | 48bf54c46c3061d9344f89d2dab3bd4613ec3a17 (diff) |
Refresh in place capability.
Diffstat (limited to 'src')
-rw-r--r-- | src/zenmonitor-cli.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/zenmonitor-cli.c b/src/zenmonitor-cli.c index 6792d02..a89c14b 100644 --- a/src/zenmonitor-cli.c +++ b/src/zenmonitor-cli.c @@ -4,6 +4,7 @@ #include <time.h> #include <unistd.h> #include <signal.h> +#include <ncurses.h> #include "msr.h" #include "os.h" #include "zenpower.h" @@ -14,6 +15,7 @@ gdouble delay = 0.5; gchar *file = ""; SensorDataStore *store; int quit = 0; +int refresh_in_place = 0; int output_once = 0; static GOptionEntry options[] = { @@ -23,6 +25,8 @@ static GOptionEntry options[] = { "Interval of refreshing informations", "SECONDS"}, {"coreid", 'c', 0, G_OPTION_ARG_NONE, &display_coreid, "Display core_id instead of core index", NULL}, + {"refresh-in-place", 'r', 0, G_OPTION_ARG_NONE, &refresh_in_place, + "Whether to flush stdout block in-place.", NULL}, {"output-once", 'o', 0, G_OPTION_ARG_NONE, &output_once, "Output CPU information once and quit", NULL}, {NULL}}; @@ -141,7 +145,7 @@ void update_data() const SensorInit *sensorData; sensor_data_store_keep_time(store); - + int i = 1; //ncurses uses 1-based indexing. for(source = sensor_sources; source->drv; source++) { if(source->enabled) @@ -151,11 +155,19 @@ void update_data() { node = source->sensors; - while(node) + while (node) { - sensorData = (SensorInit*)node->data; + sensorData = (SensorInit *)node->data; sensor_data_store_add_data(store, sensorData->label, *sensorData->value); - printf("%s\t%f\n", sensorData->label, *sensorData->value); + if (refresh_in_place) + { + mvprintw(i++, 0, "%s\t%f", sensorData->label, *sensorData->value); + refresh(); + } + else + { + printf("%s\t%f\n", sensorData->label, *sensorData->value); + } node = node->next; } } @@ -196,7 +208,16 @@ int main(int argc, char *argv[]) store = sensor_data_store_new(); init_sensors(); + if (refresh_in_place) + { + initscr(); + curs_set(0); + } start_watching(); + if (refresh_in_place) + { + endwin(); + } sensor_data_store_free(store); return EXIT_SUCCESS; |