forked from zwickethomas/Photonics-Helfer
add help
parent
b18c263913
commit
dc9fb47460
119
src/main.c
119
src/main.c
|
@ -27,6 +27,25 @@ Datum: 04.12.2024
|
||||||
0.2 09.12.2024 Willkommensnachricht
|
0.2 09.12.2024 Willkommensnachricht
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
int getch(){
|
||||||
|
int ch;
|
||||||
|
struct termios oldattr, newattr;
|
||||||
|
|
||||||
|
tcgetattr(STDIN_FILENO, &oldattr);
|
||||||
|
newattr = oldattr;
|
||||||
|
newattr.c_lflag &= ~ICANON;
|
||||||
|
newattr.c_lflag &= ~ECHO;
|
||||||
|
newattr.c_cc[VMIN] = 1;
|
||||||
|
newattr.c_cc[VTIME] = 0;
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
|
||||||
|
ch = getchar();
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
void get_terminal_size_linux(int argc, char **argv, int *width, int *height){
|
void get_terminal_size_linux(int argc, char **argv, int *width, int *height){
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
|
@ -95,7 +114,7 @@ void print_wellcome(int terminal_width, int terminal_height){
|
||||||
print_line("| __/| | | | (_) | |_| | | | (_) | | | | | (__\\__ \\ | _ | __/ | _| __/ | ", spaces, ";37");
|
print_line("| __/| | | | (_) | |_| | | | (_) | | | | | (__\\__ \\ | _ | __/ | _| __/ | ", spaces, ";37");
|
||||||
print_line("|_| |_| |_|\\___/ \\__|_| |_|\\___/|_| |_|_|\\___|___/ |_| |_|\\___|_|_| \\___|_| ", spaces, ";37");
|
print_line("|_| |_| |_|\\___/ \\__|_| |_|\\___/|_| |_|_|\\___|___/ |_| |_|\\___|_|_| \\___|_| ", spaces, ";37");
|
||||||
|
|
||||||
sleep_universal(3);
|
sleep_universal(2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
printf("__ ___ _ _ _ ");
|
printf("__ ___ _ _ _ ");
|
||||||
|
@ -125,7 +144,8 @@ void print_game_over(int terminal_width, int terminal_height){
|
||||||
|
|
||||||
print_blank_lines(2);
|
print_blank_lines(2);
|
||||||
print_line("Press a key to contine: ", spaces, ";37");
|
print_line("Press a key to contine: ", spaces, ";37");
|
||||||
getchar();
|
char key_input = (char)getch();
|
||||||
|
// getchar();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,51 +155,48 @@ void print_menu(int terminal_width, int terminal_height, int line){
|
||||||
int spaces = (terminal_width - 41) / 2;
|
int spaces = (terminal_width - 41) / 2;
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
print_line("┃ Programm 1 ┃", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
print_line("┃ Programm 1 ┃", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (0 <= line && line < 2) ? ";31": ";37");
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (0 <= line && line < 2) ? ";31": ";37");
|
||||||
print_line("┃ Programm 1 ┃", spaces, (1 <= line && line < 2) ? ";31": ";37");
|
print_line("┃ Programm 1 ┃", spaces, (1 <= line && line < 2) ? ";31": ";37");
|
||||||
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (1 <= line && line < 3) ? ";31": ";37");
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (1 <= line && line < 3) ? ";31": ";37");
|
||||||
print_line("┃ Programm 1 ┃", spaces, (2 <= line && line < 3) ? ";31": ";37");
|
print_line("┃ Programm 1 ┃", spaces, (2 <= line && line < 3) ? ";31": ";37");
|
||||||
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37");
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37");
|
||||||
print_line("┃ Programm 1 ┃", spaces, (3 <= line && line < 4) ? ";31": ";37");
|
print_line("┃ Programm 1 ┃", spaces, (3 <= line && line < 4) ? ";31": ";37");
|
||||||
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37");
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37");
|
||||||
print_line("┃ ┃", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
print_line("┃ ┃", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
print_line("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
print_line("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
#elif _WIN32
|
#elif _WIN32
|
||||||
print_line("+---------------------------------------+", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
print_line("+---------------------------------------+", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
print_line("| Programm 1 |", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
print_line("| Programm 1 |", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
print_line("+---------------------------------------+", spaces, (0 <= line && line < 2) ? ";31": ";37");
|
print_line("+---------------------------------------+", spaces, (0 <= line && line < 2) ? ";31": ";37");
|
||||||
print_line("| Programm 1 |", spaces, (1 <= line && line < 2) ? ";31": ";37");
|
print_line("| Programm 1 |", spaces, (1 <= line && line < 2) ? ";31": ";37");
|
||||||
print_line("+---------------------------------------+", spaces, (1 <= line && line < 3) ? ";31": ";37");
|
print_line("+---------------------------------------+", spaces, (1 <= line && line < 3) ? ";31": ";37");
|
||||||
print_line("| Programm 1 |", spaces, (2 <= line && line < 3) ? ";31": ";37");
|
print_line("| Programm 1 |", spaces, (2 <= line && line < 3) ? ";31": ";37");
|
||||||
print_line("+---------------------------------------+", spaces, (2 <= line && line < 4) ? ";31": ";37");
|
print_line("+---------------------------------------+", spaces, (2 <= line && line < 4) ? ";31": ";37");
|
||||||
print_line("| Programm 1 |", spaces, (3 <= line && line < 4) ? ";31": ";37");
|
print_line("| Programm 1 |", spaces, (3 <= line && line < 4) ? ";31": ";37");
|
||||||
print_line("+---------------------------------------+", spaces, (3 <= line && line < 5) ? ";31": ";37");
|
print_line("+---------------------------------------+", spaces, (3 <= line && line < 5) ? ";31": ";37");
|
||||||
print_line("| |", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
print_line("| |", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
print_line("+---------------------------------------+", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
print_line("+---------------------------------------+", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
int getch(){
|
|
||||||
int ch;
|
|
||||||
struct termios oldattr, newattr;
|
|
||||||
|
|
||||||
tcgetattr(STDIN_FILENO, &oldattr);
|
|
||||||
newattr = oldattr;
|
|
||||||
newattr.c_lflag &= ~ICANON;
|
|
||||||
newattr.c_lflag &= ~ECHO;
|
|
||||||
newattr.c_cc[VMIN] = 1;
|
|
||||||
newattr.c_cc[VTIME] = 0;
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
|
|
||||||
ch = getchar();
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
|
|
||||||
|
|
||||||
return ch;
|
void print_help(){
|
||||||
|
clear_terminal();
|
||||||
|
printf("? \t Diese Hilfe anzeigen\n");
|
||||||
|
printf("gg \t zum obersten Programm springen\n");
|
||||||
|
printf("G \t zum untersten Programm springen\n");
|
||||||
|
printf("j \t Ein Programm nach unten\n");
|
||||||
|
printf("k \t Ein Programm nach oben\n");
|
||||||
|
printf("Enter \t Um das ausgewählte Programm zu starten\n");
|
||||||
|
printf("q \t Um das Programm zu beenden\n");
|
||||||
|
printf("\nDrücke eine Taste um zurück zu kommen\n");
|
||||||
|
char key_input = (char)getch();
|
||||||
|
// getchar();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
@ -205,10 +222,12 @@ int main(int argc, char **argv){
|
||||||
printf ("columns %d\n", width);
|
printf ("columns %d\n", width);
|
||||||
|
|
||||||
// neues terminal öffnen (nur linux)
|
// neues terminal öffnen (nur linux)
|
||||||
system("tput smcup");
|
#ifdef __linux__
|
||||||
|
system("tput smcup");
|
||||||
|
#endif
|
||||||
|
|
||||||
// print wellcome message
|
// print wellcome message
|
||||||
print_wellcome(width, height);
|
// print_wellcome(width, height);
|
||||||
// print_game_over(width, height);
|
// print_game_over(width, height);
|
||||||
print_menu(width, height, line);
|
print_menu(width, height, line);
|
||||||
while(run){
|
while(run){
|
||||||
|
@ -217,15 +236,29 @@ int main(int argc, char **argv){
|
||||||
switch (key_input) {
|
switch (key_input) {
|
||||||
case 'k': line--; break;
|
case 'k': line--; break;
|
||||||
case 'j': line++; break;
|
case 'j': line++; break;
|
||||||
|
case 'g': {
|
||||||
|
char key_input = (char)getch();
|
||||||
|
if (key_input == 'g'){
|
||||||
|
line = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'G': line = 4; break;
|
||||||
|
|
||||||
|
case '?': print_help(); break;
|
||||||
|
|
||||||
case 'q': run = false;
|
case 'q': run = false; break;
|
||||||
|
case '\n': printf(" Es wurde die Enter Taste gedrückt"); getchar(); break;
|
||||||
|
default: printf(" Es wurde die Taste: %c gedrückt", key_input);
|
||||||
}
|
}
|
||||||
if(line < 0){line = 4;}
|
if(line < 0){line = 4;}
|
||||||
if(line > 4){line = 0;}
|
if(line > 4){line = 0;}
|
||||||
print_menu(width, height, line);
|
print_menu(width, height, line);
|
||||||
}
|
}
|
||||||
// zürück zum alten terminal (nur linux)
|
// zürück zum alten terminal (nur linux)
|
||||||
system("tput rmcup");
|
#ifdef __linux__
|
||||||
|
system("tput rmcup");
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue