diff --git a/src/cli.c b/src/cli.c index 62ca381..6fe9211 100644 --- a/src/cli.c +++ b/src/cli.c @@ -37,13 +37,16 @@ #define SERVER_IP_ADDR "127.0.0.1" #define SERVER_PORT 9000 -#define KEY_ESCAPE 27 -#define KEY_DIRECTIONS 91 +#define KEY_ESCAPE_1 27 +#define KEY_ESCAPE_2 91 +#define KEY_ESCAPE_3 51 #define KEY_ARROW_UP 65 #define KEY_ARROW_DOWN 66 #define KEY_ARROW_RIGHT 67 #define KEY_ARROW_LEFT 68 -#define KEY_DELETE 127 +#define KEY_BACKSPACE 127 +#define KEY_DELETE 126 +// KEY_SUPPR = séquence: 27 91 51 (KEY_ESCAPE_1, 2, 3) puis 126 (KEY_DELETE) #define C_CLEARSCREEN "\e[2J" #define C_CLEARLINE "\e[2K" @@ -261,7 +264,7 @@ void connectedCommandLine(int sockfd) continueReadLine = 0; break; - case KEY_DELETE: + case KEY_BACKSPACE: if (strlen(sendBuff) == 0) break; @@ -289,8 +292,8 @@ void connectedCommandLine(int sockfd) } break; - case KEY_ESCAPE: - if (getch(0) == KEY_DIRECTIONS) { + case KEY_ESCAPE_1: + if (getch(0) == KEY_ESCAPE_2) { switch(getch(0)) { @@ -349,6 +352,37 @@ void connectedCommandLine(int sockfd) curPosition++; } break; + + case KEY_ESCAPE_3: + if (getch(0) == KEY_DELETE) { + if (strlen(sendBuff) == 0) + break; + + // Delete next char + sendBuff[++curPosition] = 0; + curLineLength--; + + if (curLineLength >= 0) { + + printf("%s", C_SAVE_CURSORPOS); + + memmove(sendBuff + curPosition, sendBuff + curPosition + 1, + SEND_BUFFER_SIZE); + + //sendBuff[curLineLength--] = 0; + + printf("%s\r%s%s", + C_CLEARLINE, + promptString, + sendBuff + ); + + printf("%s", C_RESTORE_CURSORPOS); + printf("%s", C_CURSORRIGHT); + } + } + break; + } } break;