WIP: del key

This commit is contained in:
Jean Sirmai 2021-07-21 20:30:35 +02:00
parent a95279b7ef
commit 1d0e33e4fd
Signed by untrusted user who does not match committer: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 40 additions and 6 deletions

View File

@ -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;