Skip to content

Commit

Permalink
Merge pull request #157 from pavan02/DEV-Column
Browse files Browse the repository at this point in the history
fixes issue #110 - DEV colum length to 15
  • Loading branch information
raboof committed May 3, 2018
2 parents 7093964 + a251024 commit 33fab67
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/cui.cpp
Expand Up @@ -54,7 +54,8 @@ extern unsigned refreshcount;

const int COLUMN_WIDTH_PID = 7;
const int COLUMN_WIDTH_USER = 8;
const int COLUMN_WIDTH_DEV = 5;
const int MAX_COLUMN_WIDTH_DEV = 15;
const int MIN_COLUMN_WIDTH_DEV = 5;
const int COLUMN_WIDTH_SENT = 11;
const int COLUMN_WIDTH_RECEIVED = 11;
const int COLUMN_WIDTH_UNIT = 6;
Expand All @@ -79,16 +80,16 @@ class Line {
assert(m_pid >= 0);
}

void show(int row, unsigned int proglen);
void show(int row, unsigned int proglen, unsigned int devlen);
void log();

double sent_value;
double recv_value;
const char *devicename;

private:
const char *m_name;
const char *m_cmdline;
const char *devicename;
pid_t m_pid;
uid_t m_uid;
};
Expand Down Expand Up @@ -175,15 +176,15 @@ static void mvaddstr_truncate_cmdline(int row, int col, const char *progname,
}
}

void Line::show(int row, unsigned int proglen) {
void Line::show(int row, unsigned int proglen, unsigned int devlen) {
assert(m_pid >= 0);
assert(m_pid <= PID_MAX);

const int column_offset_pid = 0;
const int column_offset_user = column_offset_pid + COLUMN_WIDTH_PID + 1;
const int column_offset_program = column_offset_user + COLUMN_WIDTH_USER + 1;
const int column_offset_dev = column_offset_program + proglen + 2;
const int column_offset_sent = column_offset_dev + COLUMN_WIDTH_DEV + 1;
const int column_offset_sent = column_offset_dev + devlen + 1;
const int column_offset_received = column_offset_sent + COLUMN_WIDTH_SENT + 1;
const int column_offset_unit =
column_offset_received + COLUMN_WIDTH_RECEIVED + 1;
Expand Down Expand Up @@ -224,6 +225,25 @@ void Line::log() {
std::cout << '/' << m_pid << '/' << m_uid << "\t" << sent_value << "\t" << recv_value << std::endl;
}

int get_devlen(Line *lines[], int nproc, int rows)
{
int devlen = MIN_COLUMN_WIDTH_DEV; int curlen;
for (int i = 0; i < nproc; i++) {
if (i + 3 < rows)
{
curlen = strlen(lines[i]->devicename);
if(curlen > devlen)
curlen = devlen;
}
}

if(devlen > MAX_COLUMN_WIDTH_DEV)
devlen = MAX_COLUMN_WIDTH_DEV;

return devlen;
}


int GreatestFirst(const void *ma, const void *mb) {
Line **pa = (Line **)ma;
Line **pb = (Line **)mb;
Expand Down Expand Up @@ -334,30 +354,33 @@ void show_ncurses(Line *lines[], int nproc) {
if (cols > PROGNAME_WIDTH)
cols = PROGNAME_WIDTH;

proglen = cols - 55;

//issue #110 - maximum devicename length min=5, max=15
int devlen = get_devlen(lines, nproc, rows);

proglen = cols - 50 - devlen;

erase();
mvprintw(0, 0, "%s", caption->c_str());
attron(A_REVERSE);
mvprintw(2, 0,
" PID USER %-*.*s DEV SENT RECEIVED ",
proglen, proglen, "PROGRAM");
" PID USER %-*.*s %-*.*s SENT RECEIVED ",
proglen, proglen, "PROGRAM",devlen,devlen,"DEV");
attroff(A_REVERSE);

/* print them */
int i;
for (i = 0; i < nproc; i++) {
if (i + 3 < rows)
lines[i]->show(i + 3, proglen);
lines[i]->show(i + 3, proglen,devlen);
recv_global += lines[i]->recv_value;
sent_global += lines[i]->sent_value;
delete lines[i];
}

attron(A_REVERSE);
int totalrow = std::min(rows - 1, 3 + 1 + i);
mvprintw(totalrow, 0, " TOTAL %-*.*s %11.3f %11.3f ",
proglen, proglen, " ", sent_global, recv_global);
mvprintw(totalrow, 0, " TOTAL %-*.*s %-*.*s %11.3f %11.3f ",
proglen, proglen, "", devlen,devlen, "", sent_global, recv_global);
if (viewMode == VIEWMODE_KBPS) {
mvprintw(3 + 1 + i, cols - COLUMN_WIDTH_UNIT, "KB/sec ");
} else if (viewMode == VIEWMODE_TOTAL_B) {
Expand Down

0 comments on commit 33fab67

Please sign in to comment.