void printgraphw(WINDOW *win, char *name, unsigned long *array, unsigned long max, bool siunits, int lines, int cols, int color) { int y, x; werase(win); box(win, 0, 0); mvwvline(win, 0, 1, '-', lines-1); if (name) mvwprintw(win, 0, cols - 5 - strlen(name), "[ %s ]",name); mvwprintw(win, 0, 1, "[ %s/s ]", bytestostr(max, siunits)); mvwprintw(win, lines-1, 1, "[ %s/s ]", bytestostr(0.0, siunits)); wattron(win, color); for (y = 0; y < (lines - 2); y++) { for (x = 0; x < (cols - 3); x++) { if (array[x] && max) { if (lines - 3 - ((double) array[x] / max * lines) < y) mvwaddch(win, y + 1, x + 2, '*'); } } } wattroff(win, color); wnoutrefresh(win); }
void printstatsw(WINDOW *win, char *name, unsigned long cur, unsigned long avg, unsigned long max, unsigned long long total, bool siunits, int cols) { char *str; werase(win); box(win, 0, 0); if (name) mvwprintw(win, 0, 1, "[ %s ]", name); mvwprintw(win, 1, 1, "current:"); str = bytestostr(cur, siunits); mvwprintw(win, 1, cols - 3 - strlen(str), "%s/s", str); mvwprintw(win, 2, 1, "average:"); str = bytestostr(avg, siunits); mvwprintw(win, 2, cols - 3 - strlen(str), "%s/s", str); mvwprintw(win, 3, 1, "maximum:"); str = bytestostr(max, siunits); mvwprintw(win, 3, cols - 3 - strlen(str), "%s/s", str); mvwprintw(win, 4, 1, "total:"); str = bytestostr(total, siunits); mvwprintw(win, 4, cols - 1 - strlen(str), "%s", str); wnoutrefresh(win); }
static void test_bytestostr(void **state) { char *ans_1 = "this is how the world ends..."; char *ans_2 = "the quick brown fox jumps over the lazy dog"; char *ans_3 = "that's all folks"; struct bytes *b_1 = bytes_init_from_str(ans_1); struct bytes *b_2 = bytes_init_from_str(ans_2); struct bytes *b_3 = bytes_init_from_str(ans_3); char *res_1 = malloc(b_1->len * sizeof(*res_1) + 1); char *res_2 = malloc(b_2->len * sizeof(*res_2) + 1); char *res_3 = malloc(b_3->len * sizeof(*res_3) + 1); bytestostr(res_1, b_1); bytestostr(res_2, b_2); bytestostr(res_3, b_3); assert_memory_equal(res_1, ans_1, strlen(ans_1)); assert_memory_equal(res_2, ans_2, strlen(ans_2)); assert_memory_equal(res_3, ans_3, strlen(ans_3)); free(res_1); free(res_2); free(res_3); bytes_put(b_1); bytes_put(b_2); bytes_put(b_3); }
void printstatsw(WINDOW *win, struct iface ifa, bool siunits, int cols) { int colrx, coltx; char *fmt; int line = 0; werase(win); fmt = "%6s %s/s"; colrx = cols / 4 - 8; coltx = colrx + cols / 2 + 1; mvwprintw(win, line, colrx, fmt, "RX:", bytestostr(ifa.rxs[cols-1], siunits)); mvwprintw(win, line++, coltx, fmt, "TX:", bytestostr(ifa.txs[cols-1], siunits)); mvwprintw(win, line, colrx, fmt, "avg:", bytestostr(ifa.rxavg, siunits)); mvwprintw(win, line++, coltx, fmt, "avg:", bytestostr(ifa.txavg, siunits)); mvwprintw(win, line, colrx, fmt, "max:", bytestostr(ifa.rxmax, siunits)); mvwprintw(win, line++, coltx, fmt, "max:", bytestostr(ifa.txmax, siunits)); fmt = "%6s %s"; mvwprintw(win, line, colrx, fmt, "total:", bytestostr(ifa.rx, siunits)); mvwprintw(win, line++, coltx, fmt, "total:", bytestostr(ifa.tx, siunits)); wnoutrefresh(win); }
void printgraphw(WINDOW *win, long *array, double max, bool siunits, int lines, int cols, bool hidescale, int color) { int y, x; werase(win); if (!hidescale) { wborder(win, '-', ' ', ' ', ' ', ' ', ' ', ' ', ' '); mvwprintw(win, 0, 0, "%s/s", bytestostr(max, siunits)); mvwprintw(win, lines-1, 0, "%s/s", 0.0, bytestostr(0.0, siunits)); } wattron(win, color); for (y = 0; y < lines; y++) for (x = 0; x < cols; x++) if (lines - 1 - array[x] / max * lines < y) mvwaddch(win, y, x, '*'); wattroff(win, color); wnoutrefresh(win); }
void printstatsw(WINDOW *win, char *name, unsigned long cur, unsigned long min, unsigned long avg, unsigned long max, unsigned long long total) { werase(win); box(win, 0, 0); if (name) mvwprintw(win, 0, 1, "[ %s ]", name); mvwprintw(win, 1, 1, "Current:"); printrightw(win, "%s/s", bytestostr(cur)); mvwprintw(win, 2, 1, "Maximum:"); printrightw(win, "%s/s", bytestostr(max)); mvwprintw(win, 3, 1, "Average:"); printrightw(win, "%s/s", bytestostr(avg)); mvwprintw(win, 4, 1, "Minimum:"); printrightw(win, "%s/s", bytestostr(min)); mvwprintw(win, 5, 1, "Total:"); printrightw(win, "%s", bytestostr(total)); wnoutrefresh(win); }
void printgraphw(WINDOW *win, char *name, char *ifname, int color, unsigned long *array, unsigned long min, unsigned long max) { int y, x; int i, j; double height; getmaxyx(win, y, x); werase(win); box(win, 0, 0); mvwvline(win, 0, 1, '-', y - 1); if (name) mvwprintw(win, 0, x - 5 - strlen(name), "[ %s ]",name); mvwprintw(win, 0, 1, "[ %s/s ]", bytestostr(max)); if (minimum) mvwprintw(win, y - 1, 1, "[ %s/s ]", bytestostr(min)); else mvwprintw(win, y - 1, 1, "[ %s/s ]", bytestostr(0)); if (ifname) printcenterw(win, "[ nbwmon-%s | interface: %s ]", VERSION, ifname); wattron(win, color); for (i = 0; i < (y - 2); i++) { for (j = 0; j < (x - 3); j++) { if (array[j] && max) { if (minimum) height = y - 3 - (((double) array[j] - min) / (max - min) * y); else height = y - 3 - ((double) array[j] / max * y); if (height < i) mvwaddch(win, i + 1, j + 2, '*'); } } } wattroff(win, color); wnoutrefresh(win); }