New monitor layout
This commit is contained in:
parent
d2a3f7cbf0
commit
8500cddbf3
|
@ -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"},
|
||||
};
|
||||
|
|
48
src/cli.c
48
src/cli.c
|
@ -135,6 +135,14 @@ static inline int getch(bool nonBlocking)
|
|||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminalSize);
|
||||
}
|
||||
|
||||
//
|
||||
// Set cursor location
|
||||
//
|
||||
void setCursorLocation(char x, char y)
|
||||
{
|
||||
printf("\x1b[%d;%dH", y, x);
|
||||
}
|
||||
|
||||
//
|
||||
// Print monitor screen
|
||||
//
|
||||
|
@ -142,19 +150,34 @@ static inline int getch(bool nonBlocking)
|
|||
{
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue