Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keys for more CPUs #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,55 @@ int main(int argc, char** argv)
if(focus->surrounding.down != NULL)
focus = focus->surrounding.down;
break;
case '!':
focus->dataType = CPUData;
focus->dataSource = 10;
break;
case '@':
focus->dataType = CPUData;
focus->dataSource = 11;
break;
case '#':
focus->dataType = CPUData;
focus->dataSource = 12;
break;
case '$':
focus->dataType = CPUData;
focus->dataSource = 13;
break;
case '%':
focus->dataType = CPUData;
focus->dataSource = 14;
break;
case '^':
focus->dataType = CPUData;
focus->dataSource = 15;
break;
case '&':
focus->dataType = CPUData;
focus->dataSource = 16;
break;
case '*':
focus->dataType = CPUData;
focus->dataSource = 17;
break;
case '(':
focus->dataType = CPUData;
focus->dataSource = 18;
break;
case ')':
focus->dataType = CPUData;
focus->dataSource = 19;
break;
}
if(c >= '0' && c <= '9')
{ // Do this outside the switch so I can specify a range without 10 cases.
if(c - '0' < numCPUs + 1)
{
// Make sure the type is set to CPU
focus->dataType = CPUData;
focus->dataSource = c - '0';
}
// Make sure the type is set to CPU
focus->dataType = CPUData;
focus->dataSource = c - '0';
}

if(focus->dataSource > numCPUs)
focus->dataSource = 0;
if(argCtr <= argLen)
{
argCtr++;
Expand Down
35 changes: 27 additions & 8 deletions src/windowlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "windowlist.h"
#include "common.h"


#define DRAW_UNIT ACS_DIAMOND
#define UNUSED(x) (void)(x)

/**
* void drawScreen(struct windowlist* win)
* win is a window to draw.
Expand Down Expand Up @@ -40,7 +44,7 @@ void drawScreen(struct windowlist* win)
for(int j = 0; j < height; j++)
{
if(j >= indexes[i])
mvwaddch(win->contentwin, j, i, ACS_PLUS);
mvwaddch(win->contentwin, j, i, DRAW_UNIT);
else
mvwaddch(win->contentwin, j, i, ' ');
}
Expand All @@ -53,7 +57,7 @@ void drawScreen(struct windowlist* win)
if(axes[j] < indexes[i])
mvwaddch(win->contentwin, axes[j], i, ACS_HLINE); // Draw a line.
else
mvwaddch(win->contentwin, axes[j], i, ACS_PLUS); // We still want to see a point if was on a grid line.
mvwaddch(win->contentwin, axes[j], i, DRAW_UNIT); // We still want to see a point if was on a grid line.
wattroff(win->contentwin, COLOR_PAIR(1));
}
}
Expand Down Expand Up @@ -228,7 +232,7 @@ void splitV(struct windowlist* old)
struct windowlist* new;
bool odd;

if(old->frame.size.height < 4)
if(old->frame.size.height < 6)
return;

new = addWin(&old);
Expand Down Expand Up @@ -446,14 +450,25 @@ void refreshAll(struct windowlist* wins, struct windowlist* focus)
// Turn on color for the focused window.
if(ptr == focus)
wattron(ptr->titlewin, COLOR_PAIR(2));

int mx,my,offset;

getmaxyx(ptr->titlewin, my, mx);
UNUSED(my);

if(ptr->dataType == CPUData)
{
strcpy(ptr->title, "CPU ");
if(mx > 10) {
strcpy(ptr->title, "CPU ");
offset = 4;
} else {
strcpy(ptr->title, "");
offset = 0;
}
if(ptr->dataSource == 0)
strcat(ptr->title, "Summary"); // "CPU Summary"
else
sprintf(ptr->title + 4, "%d", ptr->dataSource); // "CPU 1"
if(mx > 5)
sprintf(ptr->title + offset, "%d", ptr->dataSource); // "CPU 1"
}
else if(ptr->dataType == MemData)
{
Expand All @@ -465,7 +480,8 @@ void refreshAll(struct windowlist* wins, struct windowlist* focus)

if(ptr->flags & wf_ExpandedTitle)
{
strcat(ptr->title, " - ");
if(strlen(ptr->title) > 0)
strcat(ptr->title, " ");
sprintf(ptr->title + strlen(ptr->title), "%.2f%%", ptr->data[ptr->dataLen-1]); // "CPU Summary - 17.26%"

if((ptr->flags & wf_ShowMax) && ptr->dataType == MemData)
Expand All @@ -492,7 +508,10 @@ void refreshAll(struct windowlist* wins, struct windowlist* focus)
ptr->title[39] = '\0'; // Null terminate title.

// Actually print title. (not actually, just schedule it for the next refresh() call.)
mvwaddstr(ptr->titlewin, 0, 3, ptr->title);
int ff = 0;
if (mx > 7)
ff = 1;
mvwaddstr(ptr->titlewin, 0, ff, ptr->title);

// Turn off color if it was on.
if(ptr == focus)
Expand Down