New monitor layout

This commit is contained in:
Adrien Bourmault 2021-08-05 15:14:59 +02:00
parent d2a3f7cbf0
commit 8500cddbf3
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
3 changed files with 51 additions and 23 deletions

View File

@ -26,6 +26,7 @@
//char *CmdHelp(char **, Server_t *);
char *CmdModel(char*, char**, Server_t*);
char *CmdShutdown(char*, char**, Server_t*);
char *CmdHelp(char*, char**, Server_t*);
struct {
const char *name;
@ -35,7 +36,7 @@ struct {
Command_t cmdList[] =
{
//{"help", CmdHelp, "Help command"},
{"help", CmdHelp, "Help command"},
{"model", CmdModel, "Model command"},
{"shutdown", CmdShutdown, "Shutdown command"},
};

View File

@ -126,35 +126,58 @@ static inline int getch(bool nonBlocking)
return buf;
}
//
// Get the screen size
//
void getScreenSize(int signum)
//
// Get the screen size
//
void getScreenSize(int signum)
{
// Get current terminal size
ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminalSize);
}
//
// Print monitor screen
//
void decorateMonitor(int signum)
//
// Set cursor location
//
void setCursorLocation(char x, char y)
{
printf("\x1b[%d;%dH", y, x);
}
//
// Print monitor screen
//
void decorateMonitor(int signum)
{
getScreenSize(signum);
printf(C_CLEARSCREEN "\n");
fflush(stdout);
printf(C_CLEARSCREEN);
for (int i = 0;
i < (terminalSize.ws_row * terminalSize.ws_col);
i++) {
if ((i < terminalSize.ws_col) ||
(i > terminalSize.ws_row * (terminalSize.ws_col - 1)))
printf(C_COLOR_REVERSE " " C_COLOR_NORMAL);
else
printf(C_COLOR_NORMAL " " C_COLOR_NORMAL);
setCursorLocation(1,1);
printf("%sMONITOR",
C_COLOR_GREEN C_COLOR_REVERSE
);
for (int i = 0; i < terminalSize.ws_col - sizeof("MONITOR") + 1; i++) {
printf(" ");
}
printf(C_COLOR_NORMAL);
setCursorLocation(1,terminalSize.ws_row - 1);
printf("%s",
C_COLOR_GREEN C_COLOR_REVERSE
);
for (int i = 0; i < terminalSize.ws_col; i++) {
printf(" ");
}
printf("%sQ%s Quit\t%sS%s Start/Stop",
C_COLOR_NORMAL C_COLOR_REVERSE,
C_COLOR_NORMAL,
C_COLOR_REVERSE,
C_COLOR_NORMAL);
setCursorLocation(1, 2);
fflush(stdout);
}
@ -182,10 +205,6 @@ int connectedMonitor(int sockfd)
// Read command from terminal
curChar = getch(NON_BLOCKING);
if (curChar > 0) {
printLog("Char detected : %d\n", curChar);
}
switch (curChar) {
case 'q':
pleaseStop = true;
@ -212,6 +231,7 @@ int connectedMonitor(int sockfd)
/* // Invalid command */
/* } */
}
printf(C_CLEARSCREEN);
printf("%sEnd of monitoring session\n\e[0m", C_COLOR_YELLOW);
return 0;

View File

@ -187,3 +187,10 @@ char *CmdShutdown(char *buf, char **argv, Server_t *args)
return buf;
}
char *CmdHelp(char *buf, char **argv, Server_t *args)
{
strcat(buf, "List of known commands:\n");
return buf;
}