From 9cea3342edceb34b1381a1fafda7815eb1d6deb0 Mon Sep 17 00:00:00 2001 From: MuedeHydra Date: Tue, 10 Dec 2024 16:07:51 +0100 Subject: [PATCH] brock terminal size --- src/main.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index 5db5b58..4cfc5b8 100644 --- a/src/main.c +++ b/src/main.c @@ -198,21 +198,30 @@ void print_help(){ // getchar(); } +void get_terminal_size(int argc, char **argv, int *width, int *height){ + do{ + #ifdef __linux__ + get_terminal_size_linux(argc, argv, width, height); + #elif _WIN32 + get_terminal_size_windows(argc, argv, width, height); + #endif + + if (*width < 100 || *height < 20){ + clear_terminal(); + printf("Terminal zu klein!"); + // sleep_universal(1); + } + }while(*width < 100 || *height < 20); +} + int main(int argc, char **argv){ int width = 0; int height = 0; - int os = 0; // 0 == None, 1 = linux, 2 = windows int line = 0; bool run = true; // Terminal grösse herauslesen - #ifdef __linux__ - os = 1; - get_terminal_size_linux(argc, argv, &width, &height); - #elif _WIN32 - os = 2; - get_terminal_size_windows(argc, argv, &width, &height); - #endif + get_terminal_size(argc, argv, &width, &height); // int x = test_gruppe_programmname(); @@ -227,11 +236,14 @@ int main(int argc, char **argv){ #endif // print wellcome message - // print_wellcome(width, height); + print_wellcome(width, height); // print_game_over(width, height); - print_menu(width, height, line); + // print_menu(width, height, line); while(run){ - char key_input = (char)getch(); + get_terminal_size(argc, argv, &width, &height); + print_menu(width, height, line); + // char key_input = (char)getch(); + char key_input = (char)0; switch (key_input) { case 'k': line--; break; @@ -253,7 +265,7 @@ int main(int argc, char **argv){ } if(line < 0){line = 4;} if(line > 4){line = 0;} - print_menu(width, height, line); + // print_menu(width, height, line); } // zürück zum alten terminal (nur linux) #ifdef __linux__