diff options
| author | Nakidai <nakidai@disroot.org> | 2025-06-12 04:59:37 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2025-06-12 04:59:37 +0300 |
| commit | fc1f60f6fc9d541290802990ac638b91f1fdf66d (patch) | |
| tree | 0ff3ad3130dc2c93d5e13fd838001335a28044bf /fp.c | |
| parent | dcd13cb0045cf12fddc867fad1e402c98edeec8b (diff) | |
| download | fp-fc1f60f6fc9d541290802990ac638b91f1fdf66d.tar.gz fp-fc1f60f6fc9d541290802990ac638b91f1fdf66d.zip | |
Fix output when exited by for example ^C
Also remove labels as they unneeded
Diffstat (limited to 'fp.c')
| -rw-r--r-- | fp.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/fp.c b/fp.c index 823a1d4..1ab7026 100644 --- a/fp.c +++ b/fp.c @@ -21,6 +21,7 @@ struct result char name[NAME_MAX+1]; } *results = 0; size_t amount = 0; +int ischosen = 1; struct termios state; int getch() @@ -43,11 +44,21 @@ int getch() void restore(void) { + fprintf(stderr, "\033[6B\r"); + if (ischosen) + { + fprintf(stderr, "You've chosen `"); + fflush(stderr); + fprintf(stdout, "%s", results[0].name); + fflush(stdout); + fprintf(stderr, "'!\n"); + } tcsetattr(0, TCSANOW, &state); } void getchhnd(int sig) { + ischosen = 0; exit(1); } @@ -141,27 +152,20 @@ int main(int argc, char **argv) switch (ch) { case -1: case 4: case '\n': case '\r': - goto end; + return 0; case 127: { if (!bufi) - goto cont; + continue; buf[--bufi] = 0; } break; default: { if (bufi == NAME_MAX) - goto cont; + continue; buf[bufi++] = ch; } break; } render(buf, bufi); -cont:; } -end: - fprintf(stderr, "\033[6B\rYou've chosen `"); - fflush(stderr); - fprintf(stdout, "%s", results[0].name); - fflush(stdout); - fprintf(stderr, "'!\n"); } |