-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.c
71 lines (31 loc) · 791 Bytes
/
screen.c
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
// this file contains screen functions. They are used to display
// sound levels on a PUTTY screen as a bar chart
#include <stdio.h>
#include "screen.h"
void barChart(int db[]){
int i, j;
for(i=0; i<COL; i++){ // for 80 columns
for(j=0; j<db[i]/3; j++){
if(db[i]>60 && j>20) setColors(WHITE, bg(YELLOW));
else setColors(RED, bg(YELLOW));
printf("\033[%d;%dH", 35-j, i+1);
#ifdef UNICODE // conditional compilation
printf("%s", BAR);
#else
printf("%c", '*');
#endif
}
}
}
void clearScreen(void){
printf("\033[2J");
fflush(stdout); // for remote terminal (such as PUTTY)
}
void setColors(short bg, short fg){
printf("\033[%d;%d;1m", bg, fg);
fflush(stdout);
}
void resetColors(void){
printf("\033[0m");
fflush(stdout);
}