-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_writer.h
118 lines (95 loc) · 3.46 KB
/
console_writer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (C) 2015 Mountassir El Hafi, ([email protected])
*
* Writer.h: Part of gmonitor
*
* gmonitor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* gmonitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with gmonitor. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONSOLE_WRITER_H_
#define CONSOLE_WRITER_H_
#include <vector>
#include "constants.h"
using namespace std;
const int DEFAULT_ROW_N = 100; //default terminal window vertical size
const int DEFAULT_COL_N = 100; //default terminal window hotizontal size
const int DEFAULT_RES = 1; //default resolution, '|' represents one % / c
/*
* consoleWriter class: prints gpu states on the terminal
*/
class ConsoleWriter
{
private:
int terminalRows; //total rows of the terminal
int terminalColms; //total columns of the terminal
int resolution; //how many unites a column represents
int combinedBarSize;
//return a coloured text
string colourText(Color color, const string &text);
string inRed(const string &text);
string inGreen(const string &text);
string inYellow(const string &text);
string inBlue(const string &text);
string inLightBlue(const string &text);
//return the correct color for a value (0 - 100)
Color getColorByValue(int value);
//return the correct color for a state
Color getColorByState(States toPrint);
//get the pre and post labels for each state;
//GPU for gpu usage, VRAM for video RAM ...
//% for percentage value and c for temperature
void getLabelsByState(States state,
string *preLabel,
string *postLabel);
//print a line of '='
string printSeperator(int length = 0);
//refresh the available terminal size to print on
void refreshTerminalDimensions();
//get the current window size
void getTerminalDim(int *xDim, int *yDim);
//update the size of the terminal window
void updateTerminalDimensions(int colms, int rows);
//print one state, value is represented by a list
//of '|', 10 -> |||||||||| (for resolution = 1)
string printOneStateInOneLine(States state,
int value);
//print one state, value is represented by a list
//of '|', resolution depends on the line size
string printOneHistoryStateInOneLine(States state,
int value,
double lineSize);
//print heading for history view
//GPU~~~ VRAM~~~ ...
string printHistoryStatesHeading(States state, int barSize);
public:
//constructors
ConsoleWriter(int rows, int colms, int res)
: terminalRows(rows),
terminalColms(colms),
resolution(res),
combinedBarSize(0) {};
ConsoleWriter()
: terminalRows(DEFAULT_ROW_N),
terminalColms(DEFAULT_COL_N),
resolution(DEFAULT_RES),
combinedBarSize(0) {};
//clear the terminal
void clearConsole();
//print gpu identifiers
void printGpuIdentifier(const string &gpuId,
const string &gpuName,
int totalAvailableMemory);
//print the current state of the gpu
void printCurrentGpuState(const GpuStates &state);
//print all previous states of the gpu
void printHistoryStates(const vector<GpuStates> &states);
};
#endif