thing: fix exit code when quitting
crispy-caesus crispy@crispy-caesus.eu
Wed, 09 Sep 2026 22:14:35 +0200
1 files changed,
13 insertions(+),
9 deletions(-)
jump to
M
thing/src/thing.c
→
thing/src/thing.c
@@ -1,10 +1,10 @@
+#include <libthingterm/menu.h> +#include <libthingterm/term.h> + #include <stdio.h> #include <termios.h> -#include <libthingterm/menu.h> -#include <libthingterm/term.h> - -int main() { +int main(void) { uint8_t ret = 0; struct termios old_term; setup_term(&old_term);@@ -13,13 +13,17 @@ static char *elements[] = {"hi", "hello", "what's up", "dang",
"this is cool"}; int seli = menu(elements, 5); - if (seli < 0) { - printf("ERROR: menu failed"); - ret = 1; - } return_term(&old_term); - if (ret == 0) { + + if (seli == -1) { + // menu was quit + } else if (seli < -1) { + // error + printf("ERROR: menu failed"); + ret = seli; + } else { + // print selected item printf("%s", elements[seli]); }