termsetup/return: use alt buffer
crispy-caesus crispy@crispy-caesus.eu
Fri, 29 May 2026 23:14:34 +0200
1 files changed,
15 insertions(+),
6 deletions(-)
jump to
M
main.c
→
main.c
@@ -39,12 +39,16 @@ new.c_lflag &= ~(ECHO | ICANON);
new.c_cc[VMIN] = 0; // bytes read to return new.c_cc[VTIME] = 0; // time before return + printf("\x1B[?1049h"); tcsetattr(STDIN_FILENO, TCSANOW, &new); return old; } -void return_term(struct termios *old) { tcsetattr(STDIN_FILENO, TCSANOW, old); } +void return_term(struct termios *old) { + tcsetattr(STDIN_FILENO, TCSANOW, old); + printf("\x1B[?1049l"); +} int menu(char **elements, int len) { struct pollfd poller[1];@@ -88,17 +92,22 @@ }
} int main() { + uint8_t ret = 0; struct termios old = setup_term(); - static char *elements[] = {"hi", "hello", "what's up"}; + static char *elements[] = {"hi", "hello", "what's up", "dang", + "this is cool"}; - int seli = menu(elements, 3); + int seli = menu(elements, 5); if (seli < 0) { printf("ERROR: menu failed"); - return 1; + ret = 1; } return_term(&old); - printf("%s", elements[seli]); - return 0; + if (ret == 0) { + printf("%s", elements[seli]); + } + + return ret; }