-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprint2screen.c
More file actions
134 lines (119 loc) · 3.82 KB
/
print2screen.c
File metadata and controls
134 lines (119 loc) · 3.82 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "print2screen.h"
void print_end_delimiter(int x, int y){
if(x == y-1){
printw(">");
};
}
void print2screen(
threadData_t *ta,
threadData_t *tb,
threadData_t *tc,
threadData_t *td,
threadData_t *te,
int active_thread_n
){
int is_activeA = 0;
int is_activeB = 0;
int is_activeC = 0;
int is_activeD = 0;
int is_activeE = 0;
int i;
int row;
int col;
int MAXROW;
int MAXCOL;
int P_BAR_WIDTH;
float progressA;
float progressB;
float progressC;
float progressD;
float progressE;
if(active_thread_n == 0){
is_activeA = 1;
}else if(active_thread_n == 0){
is_activeA = 1;
}else if(active_thread_n == 1){
is_activeB = 1;
}else if(active_thread_n == 2){
is_activeC = 1;
}else if(active_thread_n == 3){
is_activeD = 1;
}else if(active_thread_n == 4){
is_activeE = 1;
}else{
is_activeA = 1;
}
////////////////////////////////////////
// Print to screen
////////////////////////////////////////
//Clear stdscr
clear();
// Get terminal dimensions
getmaxyx(stdscr,MAXROW,MAXCOL);
printw("\rAthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
ta->currPiValue, ta->currTerm, ta->totalTerms, is_activeA);
printw("\rBthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
tb->currPiValue, tb->currTerm, tb->totalTerms, is_activeB);
printw("\rCthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
tc->currPiValue, tc->currTerm, tc->totalTerms, is_activeC);
printw("\rDthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
td->currPiValue, td->currTerm, td->totalTerms, is_activeD);
printw("\rEthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
te->currPiValue, te->currTerm, te->totalTerms, is_activeE);
//Percentage of completion
progressA = (ta->currTerm/ta->totalTerms)*100;
progressB = (tb->currTerm/tb->totalTerms)*100;
progressC = (tc->currTerm/tc->totalTerms)*100;
progressD = (td->currTerm/td->totalTerms)*100;
progressE = (te->currTerm/te->totalTerms)*100;
//Number of steps per percent
P_BAR_WIDTH = 60; // recommend 90 width
int total_ticks = P_BAR_WIDTH-6;
int progress_ticksA = (progressA*total_ticks)/100;
int progress_ticksB = (progressB*total_ticks)/100;
int progress_ticksC = (progressC*total_ticks)/100;
int progress_ticksD = (progressD*total_ticks)/100;
int progress_ticksE = (progressE*total_ticks)/100;
printw("\rProgress A: %d %% [", (int) progressA);
for(i = 0 ; i < (int) progress_ticksA; i++){
printw("=");
print_end_delimiter(i,(int) progress_ticksA);
};
getyx(stdscr, row, col);
mvaddstr(row, total_ticks+20, "]");
printw("\n");
printw("\rProgress B: %d %% [", (int) progressB);
for(i = 0 ; i < (int) progress_ticksB; i++){
printw("=");
print_end_delimiter(i,(int) progress_ticksB);
};
getyx(stdscr, row, col);
mvaddstr(row, total_ticks+20, "]");
printw("\n");
printw("\rProgress C: %d %% [", (int) progressC);
for(i = 0 ; i < (int) progress_ticksC; i++){
printw("=");
print_end_delimiter(i,(int) progress_ticksC);
};
getyx(stdscr, row, col);
mvaddstr(row, total_ticks+20, "]");
printw("\n");
printw("\rProgress D: %d %% [", (int) progressD);
for(i = 0 ; i < (int) progress_ticksD; i++){
printw("=");
print_end_delimiter(i,(int) progress_ticksD);
};
getyx(stdscr, row, col);
mvaddstr(row, total_ticks+20, "]");
printw("\n");
printw("\rProgress E: %d %% [", (int) progressE);
for(i = 0 ; i < (int) progress_ticksE; i++){
printw("=");
print_end_delimiter(i,(int) progress_ticksE);
};
getyx(stdscr, row, col);
mvaddstr(row, total_ticks+20, "]");
printw("\n");
//refresh stdscr
refresh();
}