add windows support
This commit is contained in:
		
							parent
							
								
									c5442a3294
								
							
						
					
					
						commit
						4cdbc32365
					
				
							
								
								
									
										105
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								src/main.c
									
									
									
									
									
								
							@ -1,7 +1,13 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
    #include <sys/ioctl.h>
 | 
			
		||||
    #include <unistd.h>
 | 
			
		||||
#elif _WIN32
 | 
			
		||||
    #include <windows.h>
 | 
			
		||||
    #include <conio.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// import sub programme
 | 
			
		||||
#include "test_prog.h"
 | 
			
		||||
@ -15,8 +21,29 @@ Version: 0.1
 | 
			
		||||
Datum: 04.12.2024
 | 
			
		||||
Änderungen:
 | 
			
		||||
0.1 04.12.2024 Dokument erstellt
 | 
			
		||||
0.2 09.12.2024 Willkommensnachricht
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
void get_terminal_size_linux(int argc, char **argv, int *width, int *height){
 | 
			
		||||
    struct winsize w;
 | 
			
		||||
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
 | 
			
		||||
 | 
			
		||||
    *height = w.ws_row;
 | 
			
		||||
    *width = w.ws_col;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif _WIN32
 | 
			
		||||
void get_terminal_size_windows(int argc, char **argv, int *width, int *height){
 | 
			
		||||
    CONSOLE_SCREEN_BUFFER_INFO csbi;
 | 
			
		||||
    int columns, rows;
 | 
			
		||||
 | 
			
		||||
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
 | 
			
		||||
    *width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
 | 
			
		||||
    *height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void print_wellcome_line(char line[100], int spaces){
 | 
			
		||||
    for(int i = 0; i < spaces; i++){
 | 
			
		||||
        printf(" ");
 | 
			
		||||
@ -24,14 +51,30 @@ void print_wellcome_line(char line[100], int spaces){
 | 
			
		||||
    printf("%s\n", line);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void print_wellcome(int terminal_with, int terminal_higt){
 | 
			
		||||
void clear_terminal(){
 | 
			
		||||
    #ifdef __linux__
 | 
			
		||||
        printf("\e[1;1H\e[2J");
 | 
			
		||||
    #elif _WIN32
 | 
			
		||||
        system("cls");
 | 
			
		||||
    #endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    for(int i = 0; i < (terminal_higt - 10) / 2; i++){
 | 
			
		||||
void sleep_universal(int t){
 | 
			
		||||
    #ifdef __linux__
 | 
			
		||||
        sleep(t);
 | 
			
		||||
    #elif _WIN32
 | 
			
		||||
        Sleep(t * 1000);
 | 
			
		||||
    #endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void print_wellcome(int terminal_width, int terminal_height){
 | 
			
		||||
    clear_terminal();
 | 
			
		||||
 | 
			
		||||
    for(int i = 0; i < (terminal_height - 10) / 2; i++){
 | 
			
		||||
        printf("\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int spaces = (terminal_with - 83) / 2;
 | 
			
		||||
    int spaces = (terminal_width - 83) / 2;
 | 
			
		||||
    print_wellcome_line("__        ___ _ _ _                                                                        ", spaces);
 | 
			
		||||
    print_wellcome_line("\\ \\      / (_) | | | _____  _ __ ___  _ __ ___   ___ _ __      _____   _ _ __ ___        ", spaces);
 | 
			
		||||
    print_wellcome_line(" \\ \\ /\\ / /| | | | |/ / _ \\| '_ ` _ \\| '_ ` _ \\ / _ \\ '_ \\    |_  / | | | '_ ` _ \\", spaces);
 | 
			
		||||
@ -44,7 +87,7 @@ void print_wellcome(int terminal_with, int terminal_higt){
 | 
			
		||||
    print_wellcome_line("|  __/| | | | (_) | |_| | | | (_) | | | | | (__\\__ \\   |  _  |  __/ |  _|  __/ |         ", spaces);
 | 
			
		||||
    print_wellcome_line("|_|   |_| |_|\\___/ \\__|_| |_|\\___/|_| |_|_|\\___|___/   |_| |_|\\___|_|_|  \\___|_|     ", spaces);
 | 
			
		||||
 | 
			
		||||
    sleep(3);
 | 
			
		||||
    sleep_universal(3);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    printf("__        ___ _ _ _                                                                ");
 | 
			
		||||
@ -58,42 +101,38 @@ void print_wellcome(int terminal_with, int terminal_higt){
 | 
			
		||||
    printf("| |_) | '_ \ / _ \| __| '_ \ / _ \| '_ \| |/ __/ __|   | |_| |/ _ \ | |_ / _ \ '__|");
 | 
			
		||||
    printf("|  __/| | | | (_) | |_| | | | (_) | | | | | (__\__ \   |  _  |  __/ |  _|  __/ |   ");
 | 
			
		||||
    printf("|_|   |_| |_|\___/ \__|_| |_|\___/|_| |_|_|\___|___/   |_| |_|\___|_|_|  \___|_|   ");
 | 
			
		||||
 | 
			
		||||
    printf("__        ___ _ _ _                                                                         \n");
 | 
			
		||||
    printf("\\ \\      / (_) | | | _____  _ __ ___  _ __ ___   ___ _ __      _____   _ _ __ ___         \n");
 | 
			
		||||
    printf(" \\ \\ /\\ / /| | | | |/ / _ \\| '_ ` _ \\| '_ ` _ \\ / _ \\ '_ \\    |_  / | | | '_ ` _ \\ \n");
 | 
			
		||||
    printf("  \\ V  V / | | | |   < (_) | | | | | | | | | | |  __/ | | |    / /| |_| | | | | | |        \n");
 | 
			
		||||
    printf("   \\_/\\_/  |_|_|_|_|\\_\\___/|_| |_| |_|_| |_| |_|\\___|_| |_|   /___|\\__,_|_| |_| |_|   \n");
 | 
			
		||||
    printf("                                                                                            \n");
 | 
			
		||||
    printf(" ____  _           _   _                 _              _   _      _  __                    \n");
 | 
			
		||||
    printf("|  _ \\| |__   ___ | |_| |__   ___  _ __ (_) ___ ___    | | | | ___| |/ _| ___ _ __         \n");
 | 
			
		||||
    printf("| |_) | '_ \\ / _ \\| __| '_ \\ / _ \\| '_ \\| |/ __/ __|   | |_| |/ _ \\ | |_ / _ \\ '__|  \n");
 | 
			
		||||
    printf("|  __/| | | | (_) | |_| | | | (_) | | | | | (__\\__ \\   |  _  |  __/ |  _|  __/ |          \n");
 | 
			
		||||
    printf("|_|   |_| |_|\\___/ \\__|_| |_|\\___/|_| |_|_|\\___|___/   |_| |_|\\___|_|_|  \\___|_|      \n");
 | 
			
		||||
    */
 | 
			
		||||
                                                                           
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv){
 | 
			
		||||
    int width = 0;
 | 
			
		||||
    int height = 0;
 | 
			
		||||
    int os = 0;  // 0 == None, 1 = linux, 2 = windows
 | 
			
		||||
 | 
			
		||||
    // 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
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    // int x = test_gruppe_programmname();
 | 
			
		||||
 | 
			
		||||
    // int terminal_size();
 | 
			
		||||
 | 
			
		||||
    struct winsize w;
 | 
			
		||||
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
 | 
			
		||||
    printf ("lines %d\n", height);
 | 
			
		||||
    printf ("columns %d\n", width);
 | 
			
		||||
 | 
			
		||||
    printf ("lines %d\n", w.ws_row);
 | 
			
		||||
    printf ("columns %d\n", w.ws_col);
 | 
			
		||||
    // neues terminal öffnen (nur linux)
 | 
			
		||||
    system("tput smcup");
 | 
			
		||||
 | 
			
		||||
    // print wellcome message
 | 
			
		||||
    print_wellcome(width, height);
 | 
			
		||||
 | 
			
		||||
    print_wellcome(w.ws_col, w.ws_row);
 | 
			
		||||
 | 
			
		||||
    // zürück zum alten terminal (nur linux)
 | 
			
		||||
    system("tput rmcup");
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user