From a251024bffcb79cfaefd428860d821d54a945f52 Mon Sep 17 00:00:00 2001 From: PAVAN Date: Thu, 3 May 2018 19:42:04 +0530 Subject: [PATCH] fixes issue #110 - dynamic DEV column length, MIN=5, MAX=15 --- src/cui.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/cui.cpp b/src/cui.cpp index 15064a4..12c3c7d 100644 --- a/src/cui.cpp +++ b/src/cui.cpp @@ -176,7 +176,7 @@ static void mvaddstr_truncate_cmdline(int row, int col, const char *progname, } } -void Line::show(int row, unsigned int proglen,unsigned int devlen) { +void Line::show(int row, unsigned int proglen, unsigned int devlen) { assert(m_pid >= 0); assert(m_pid <= PID_MAX); @@ -225,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; @@ -336,21 +355,8 @@ void show_ncurses(Line *lines[], int nproc) { cols = PROGNAME_WIDTH; - //issue #110 - dynamic length devicename - 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; - + //issue #110 - maximum devicename length min=5, max=15 + int devlen = get_devlen(lines, nproc, rows); proglen = cols - 50 - devlen;