#include #include "defs.h" #include "visualise.h" #define CLEARSCREEN() printf("%c%c%c%c", 0x1B, '[', '2', 'J'); #define CURSERHOME() printf("%c%c%d%c%d%c", 0x1B, '[', 0, ';', 0, 'H'); #define CURSERXY(x,y) printf("%c%c%d%c%d%c", 0x1B, '[', y, ';', x, 'H'); #define SETFIELDATTR(x) printf("%c%c%d%c", 0x1B, '[', x, 'm'); #define BOLD 1 #define REVERSE 7 #define RESETFIELDATTR() printf("%c%c%d%c", 0x1B, '[', 0, 'm'); int visualise() { struct list_head *lh, *tlh; struct __Process *p; int i; if ( Options.continuous ) { printf("%3u.%u%% user, %3u.%u%% system, %3u.%u%% nice, %3u.%u%% idle\n", CPULoad.user/10, CPULoad.user%10, CPULoad.system/10, CPULoad.system%10, CPULoad.nice/10, CPULoad.nice%10, CPULoad.idle/10, CPULoad.idle%10); list_for_each_safe(lh, tlh, &Root) { p=list_entry(lh, struct __Process, list); if ( !(Options.summarize && !(p->user || p->system)) ) { printf("\tPID: %10d, %3u.%u%% user, %3u.%u%% system, (%s)\n", p->pid, p->user/10, p->user%10, p->system/10, p->system%10, p->command); } } printf("\n"); } else { CLEARSCREEN() CURSERHOME(); printf("CPU: "); SETFIELDATTR(BOLD); printf("%3u.%u%% ", CPULoad.user/10, CPULoad.user%10); RESETFIELDATTR(); printf("user, "); SETFIELDATTR(BOLD); printf("%3u.%u%% ", CPULoad.system/10, CPULoad.system%10); RESETFIELDATTR(); printf("system, "); SETFIELDATTR(BOLD); printf("%3u.%u%% ", CPULoad.nice/10, CPULoad.nice%10); RESETFIELDATTR(); printf("nice, "); SETFIELDATTR(BOLD); printf("%3u.%u%% ", CPULoad.idle/10, CPULoad.idle%10); RESETFIELDATTR(); printf("idle\n"); SETFIELDATTR(REVERSE); printf(" PID USER SYSTEM COMMAND "); RESETFIELDATTR(); i=3; list_for_each_safe(lh, tlh, &Root) { p=list_entry(lh, struct __Process, list); if ( !(Options.summarize && !(p->user || p->system)) ) { CURSERXY(0, i); printf("%5d %3u.%u%% %3u.%u%% %-15s\n", p->pid, p->user/10, p->user%10, p->system/10, p->system%10, p->command); i++; } } } return NERROR; }