From 077892e9b4355a2e34b36bafb4fd701993c3aeaf Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 1 May 2001 22:49:31 +0000 Subject: Hop, une jolie interface :) --- lib/interface.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 17 deletions(-) (limited to 'lib/interface.c') diff --git a/lib/interface.c b/lib/interface.c index fc238b5..d0e2880 100644 --- a/lib/interface.c +++ b/lib/interface.c @@ -11,39 +11,110 @@ void supprime(char * ch) { } } -void insert(char * ch, char c) { +void inserer(char * ch, char c) { int i; - for (i = strlen(ch) - 1; i; i--) { + for (i = strlen(ch) - 1; i != -1; i--) { *(ch + i + 1) = *(ch + i); } - *ch = c; } void ifloop(void) { - int cread; - int gotesc = 0; - char buffer[BUFSIZ]; - int position; + int cread, i, insert = 0; + int gotesc = 0, quit = 0; + char buffer[BUFSIZ] = ""; + int position = 0; + + printf("> "); - while (1) { + while (!quit) { cread = fgetc(input); - printf("%u\n", cread); if (gotesc) { - } else { - switch(cread) { - case 27: /* Caractère ESC */ - gotesc = 1; - break; - case 8: /* Caractère <--- */ - if (position) { + switch (cread) { + case 91: + cread = fgetc(input); + switch (cread) { + case 49: /* Home */ + break; + case 50: /* Insert */ + insert ^= 1; + break; + case 52: /* End */ + break; + case 67: /* Droite */ + if (buffer[position]) { + printf("%c", buffer[position++]); + } + break; + case 68: /* Gauche */ + if (position) { + printf("\010"); + position--; + } + break; + default: + gotesc = 0; + break; } break; - case 127: /* Caractère Suppr */ + default: + gotesc = 0; break; } + if (gotesc) { + cread = fgetc(input); + gotesc = 0; + } + } + switch(cread) { + case 3: /* CTRL-C */ + quit = 1; + break; + case 8: /* backspace */ + if (position) { + supprime(&(buffer[--position])); + } + printf("\010%s ", &(buffer[position])); + for (i = 0; i <= strlen(&(buffer[position])); i++) { + printf("\010"); + } + break; + case 10: /* Entrée */ + printf("\n"); + parse_line(buffer); + position = 0; + buffer[0] = 0; + printf("> "); + break; + case 27: /* ESC */ + gotesc = 1; + break; + case 126: /* ~ */ + break; + case 127: /* Suppr */ + if (buffer[position]) { + supprime(&(buffer[position])); + } + printf("%s ", &(buffer[position])); + for (i = 0; i <= strlen(&(buffer[position])); i++) { + printf("\010"); + } + break; + default: + if (insert) { + inserer(&(buffer[position]), cread); + printf("%s", &(buffer[position])); + position++; + for (i = 0; i < strlen(&(buffer[position])); i++) { + printf("\010"); + } + } else { + printf("%c", cread); + buffer[position++] = cread; + } + break; } } } -- cgit v1.2.3