diff options
author | Pixel <Pixel> | 2001-05-01 22:49:31 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-05-01 22:49:31 +0000 |
commit | 077892e9b4355a2e34b36bafb4fd701993c3aeaf (patch) | |
tree | bcd9aac03043fc79eb1245ca410d89e6eeaf302c | |
parent | 6e3a9d191ccb901823d8b1b5c1b789deabb57abb (diff) |
Hop, une jolie interface :)
-rw-r--r-- | lib/interface.c | 105 |
1 files changed, 88 insertions, 17 deletions
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; } } } |