tmux-mem-cpu-load/graph.cc
2015-01-04 17:23:05 +01:00

37 lines
761 B
C++

#include <string>
#include <cstring>
#include "graph.h"
char * getGraphByPercentage(unsigned value, unsigned len) {
unsigned step = 0;
char * bars = new char[len + 1];
unsigned barCount = (static_cast<float>(value) / 99.9 * len);
for(step; step < barCount; step++)
bars[step] = '|';
for(step; step < len; step++)
bars[step] = ' ';
bars[len]='\0';
return bars;
}
char * getGraphByValue(unsigned value, unsigned max, unsigned len) {
unsigned step = 0;
char * bars = new char[len + 1];
unsigned barCount = (static_cast<float>(value / (max - 0.1)) * len);
for(step; step < barCount; step++)
bars[step] = '|';
for(step; step < len; step++)
bars[step] = ' ';
bars[len]='\0';
return bars;
}