New monitor layout
This commit is contained in:
parent
d2a3f7cbf0
commit
8500cddbf3
|
@ -26,6 +26,7 @@
|
||||||
//char *CmdHelp(char **, Server_t *);
|
//char *CmdHelp(char **, Server_t *);
|
||||||
char *CmdModel(char*, char**, Server_t*);
|
char *CmdModel(char*, char**, Server_t*);
|
||||||
char *CmdShutdown(char*, char**, Server_t*);
|
char *CmdShutdown(char*, char**, Server_t*);
|
||||||
|
char *CmdHelp(char*, char**, Server_t*);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -35,7 +36,7 @@ struct {
|
||||||
|
|
||||||
Command_t cmdList[] =
|
Command_t cmdList[] =
|
||||||
{
|
{
|
||||||
//{"help", CmdHelp, "Help command"},
|
{"help", CmdHelp, "Help command"},
|
||||||
{"model", CmdModel, "Model command"},
|
{"model", CmdModel, "Model command"},
|
||||||
{"shutdown", CmdShutdown, "Shutdown command"},
|
{"shutdown", CmdShutdown, "Shutdown command"},
|
||||||
};
|
};
|
||||||
|
|
48
src/cli.c
48
src/cli.c
|
@ -135,6 +135,14 @@ static inline int getch(bool nonBlocking)
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminalSize);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set cursor location
|
||||||
|
//
|
||||||
|
void setCursorLocation(char x, char y)
|
||||||
|
{
|
||||||
|
printf("\x1b[%d;%dH", y, x);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Print monitor screen
|
// Print monitor screen
|
||||||
//
|
//
|
||||||
|
@ -142,19 +150,34 @@ static inline int getch(bool nonBlocking)
|
||||||
{
|
{
|
||||||
getScreenSize(signum);
|
getScreenSize(signum);
|
||||||
|
|
||||||
printf(C_CLEARSCREEN "\n");
|
printf(C_CLEARSCREEN);
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
for (int i = 0;
|
setCursorLocation(1,1);
|
||||||
i < (terminalSize.ws_row * terminalSize.ws_col);
|
|
||||||
i++) {
|
printf("%sMONITOR",
|
||||||
if ((i < terminalSize.ws_col) ||
|
C_COLOR_GREEN C_COLOR_REVERSE
|
||||||
(i > terminalSize.ws_row * (terminalSize.ws_col - 1)))
|
);
|
||||||
printf(C_COLOR_REVERSE " " C_COLOR_NORMAL);
|
|
||||||
else
|
for (int i = 0; i < terminalSize.ws_col - sizeof("MONITOR") + 1; i++) {
|
||||||
printf(C_COLOR_NORMAL " " C_COLOR_NORMAL);
|
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);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,10 +205,6 @@ int connectedMonitor(int sockfd)
|
||||||
// Read command from terminal
|
// Read command from terminal
|
||||||
curChar = getch(NON_BLOCKING);
|
curChar = getch(NON_BLOCKING);
|
||||||
|
|
||||||
if (curChar > 0) {
|
|
||||||
printLog("Char detected : %d\n", curChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (curChar) {
|
switch (curChar) {
|
||||||
case 'q':
|
case 'q':
|
||||||
pleaseStop = true;
|
pleaseStop = true;
|
||||||
|
@ -212,6 +231,7 @@ int connectedMonitor(int sockfd)
|
||||||
/* // Invalid command */
|
/* // Invalid command */
|
||||||
/* } */
|
/* } */
|
||||||
}
|
}
|
||||||
|
printf(C_CLEARSCREEN);
|
||||||
printf("%sEnd of monitoring session\n\e[0m", C_COLOR_YELLOW);
|
printf("%sEnd of monitoring session\n\e[0m", C_COLOR_YELLOW);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -187,3 +187,10 @@ char *CmdShutdown(char *buf, char **argv, Server_t *args)
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *CmdHelp(char *buf, char **argv, Server_t *args)
|
||||||
|
{
|
||||||
|
strcat(buf, "List of known commands:\n");
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue