index — thing @ 087b8f718661f612ad52e764cfde5a8331476444

A little something I'm working on

thing: fix exit code when quitting
crispy-caesus crispy@crispy-caesus.eu
Wed, 09 Sep 2026 22:14:35 +0200
commit

087b8f718661f612ad52e764cfde5a8331476444

parent

5cfe7bd91b206d1f023d0bbcf40490d1fe3ead9f

1 files changed, 13 insertions(+), 9 deletions(-)

jump to
M thing/src/thing.cthing/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]); }