From 5a466ade18526328455dfa88dcf8391752039f1a Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 18 Jun 2020 10:29:00 -0400 Subject: [PATCH] ncneofetch: get cpu info #550 --- src/fetch/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/fetch/main.c b/src/fetch/main.c index ee5807255..5d594f753 100644 --- a/src/fetch/main.c +++ b/src/fetch/main.c @@ -27,6 +27,8 @@ typedef struct fetched_info { char* shell; // getenv("SHELL") char* term; // getenv("TERM") int dimy, dimx; // extracted from xrandr + char* cpu_model; // FIXME don't handle hetero setups yet + int core_count; } fetched_info; static int @@ -52,6 +54,25 @@ static distro_info distros[] = { }, }; +static int +fetch_cpu_info(fetched_info* fi){ + FILE* cpuinfo = fopen("/proc/cpuinfo", "re"); + char buf[BUFSIZ]; + while(fgets(buf, sizeof(buf), cpuinfo)){ +#define TAG "model name\t:" + if(strncmp(buf, TAG, strlen(TAG)) == 0){ + if(fi->cpu_model == NULL){ + char* nl = strchr(buf + strlen(TAG), '\n'); + *nl = '\0'; + fi->cpu_model = strdup(buf + strlen(TAG)); + } + ++fi->core_count; + } +#undef TAG + } + return 0; +} + static char* pipe_getline(const char* cmdline){ FILE* p = popen(cmdline, "re"); @@ -304,6 +325,8 @@ infoplane(struct notcurses* nc, const fetched_info* fi){ ncplane_printf_aligned(infop, 3, NCALIGN_RIGHT, "Shell: %s ", fi->shell); ncplane_printf_aligned(infop, 4, NCALIGN_LEFT, " TERM: %s", fi->term); ncplane_printf_aligned(infop, 4, NCALIGN_RIGHT, "Screen0: %dx%d ", fi->dimx, fi->dimy); + ncplane_set_attr(infop, NCSTYLE_ITALIC); + ncplane_printf_aligned(infop, 6, NCALIGN_CENTER, "%s (%d cores)", fi->cpu_model, fi->core_count); cell ul = CELL_TRIVIAL_INITIALIZER; cell ur = CELL_TRIVIAL_INITIALIZER; cell ll = CELL_TRIVIAL_INITIALIZER; cell lr = CELL_TRIVIAL_INITIALIZER; cell hl = CELL_TRIVIAL_INITIALIZER; cell vl = CELL_TRIVIAL_INITIALIZER; @@ -385,6 +408,7 @@ ncneofetch(struct notcurses* nc){ } fetch_env_vars(&fi); fetch_x_props(&fi); + fetch_cpu_info(&fi); sem_wait(&display_marshal.sem); if(infoplane(nc, &fi)){ return -1;