CLI : monitor command; get terminal size and print screen

This commit is contained in:
Adrien Bourmault 2021-07-15 23:28:28 +02:00
parent a95279b7ef
commit 7561ae646d
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
1 changed files with 6 additions and 5 deletions

View File

@ -55,6 +55,7 @@
#define C_COLOR_YELLOW "\e[00;33m" #define C_COLOR_YELLOW "\e[00;33m"
#define C_COLOR_GREEN "\e[00;32m" #define C_COLOR_GREEN "\e[00;32m"
#define C_COLOR_BLUE "\e[01;34m" #define C_COLOR_BLUE "\e[01;34m"
#define C_COLOR_REVERSE "\e[7m"
#define C_COLOR_NORMAL "\e[0m" #define C_COLOR_NORMAL "\e[0m"
#define NON_BLOCKING 1 #define NON_BLOCKING 1
@ -123,7 +124,7 @@ static inline int getch(bool nonBlocking)
} }
// //
// Decorations // Print monitor screen
// //
void decorateMonitor(struct winsize *terminalSize) void decorateMonitor(struct winsize *terminalSize)
{ {
@ -131,7 +132,7 @@ static inline int getch(bool nonBlocking)
// print decorations // print decorations
for (int i = 0; i < terminalSize->ws_col; i++) { for (int i = 0; i < terminalSize->ws_col; i++) {
printf("*"); printf(C_COLOR_REVERSE " " C_COLOR_NORMAL);
} }
for (int i = 0; for (int i = 0;
@ -139,13 +140,13 @@ static inline int getch(bool nonBlocking)
i++) { i++) {
if ((i % terminalSize->ws_col == 0) || if ((i % terminalSize->ws_col == 0) ||
(i % terminalSize->ws_col == terminalSize->ws_col - 1)) (i % terminalSize->ws_col == terminalSize->ws_col - 1))
printf("|"); printf(C_COLOR_REVERSE " " C_COLOR_NORMAL);
else else
printf(" "); printf(C_COLOR_NORMAL " " C_COLOR_NORMAL);
} }
for (int i = 0; i < terminalSize->ws_col; i++) { for (int i = 0; i < terminalSize->ws_col; i++) {
printf("*"); printf(C_COLOR_REVERSE " " C_COLOR_NORMAL);
} }
fflush(stdout); fflush(stdout);