typing_10_fingers git · main
10 finger typing trainer (CMake)
C 97.4% Markdown 2.6%git clone https://git.christianimmanuel.de/web-tools/typing_10_fingers.gitwget https://git.christianimmanuel.de/web-tools/typing_10_fingers/archive/typing_10_fingers.tar.gzIn verschiedene Dateien aufgeteilt. Zwei der Bibs funktionieren unter Windows nicht.
.idea/.gitignore | 8 ++++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 ++++++ .idea/typing_10_fingers.iml | 2 ++ .idea/vcs.xml | 6 +++++ inout.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ inout.h | 11 ++++++++ main.c | 61 +----------------------------------------- 8 files changed, 104 insertions(+), 60 deletions(-) diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f1260b2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/typing_10_fingers.iml" filepath="$PROJECT_DIR$/.idea/typing_10_fingers.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/typing_10_fingers.iml b/.idea/typing_10_fingers.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/typing_10_fingers.iml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module classpath="CMake" type="CPP_MODULE" version="4" /> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/inout.c b/inout.c new file mode 100644 index 0000000..87ebbc6 --- /dev/null +++ b/inout.c @@ -0,0 +1,64 @@ +#include "inout.h" +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <termios.h> +#include <sys/ioctl.h> // window size +#include <string.h> +#include <time.h> + +void printAt(int x, int y, char c, int color){ + //printf("%c\033[0m", c); + printf("\033[%d;%dH", y, x); + if (color == RED) { + printf("\033[48;5;124m"); + } else { + printf("\033[48;5;28m"); + } + printf("%c\033[0m", c); +} + +void getLine(char* line, char* chars, int length, int wc){ + srand(time(NULL)); + int word_length = 3; + int count_word_chars = 0; + int i; + for (i = 0; i < length-1; i++, count_word_chars++) { + /* + if (i % wc == 0) { + line[i] = '\n'; + continue; + } + */ + if (count_word_chars == word_length) { + count_word_chars = 0; + line[i] = ' '; + word_length = rand() % 6 + 4; + continue; + } + int ran = rand() % 4 + 0; + line[i] = chars[ran]; + } + line[i] = '\0'; + +} + +void printChar(char* lines, int color, char c){ + printAt(position.x, position.y, lines[position.x-1], color); + if (c != lines[position.x-1]) { + printAt(position.x, position.y+1, c, RED); + } +} + +int readChar(){ + struct termios old_settings, new_settings; + + tcgetattr(STDIN_FILENO, &old_settings); + new_settings = old_settings; + + new_settings.c_lflag &= (~ICANON & ~ECHO); // disables output + tcsetattr(STDIN_FILENO, TCSANOW, &new_settings); + char c = getc(stdin); + tcsetattr(STDIN_FILENO, TCSANOW, &old_settings); + return c; +} \ No newline at end of file diff --git a/inout.h b/inout.h new file mode 100644 index 0000000..35c54c8 --- /dev/null +++ b/inout.h @@ -0,0 +1,11 @@ +#ifndef TYPING_10_FINGERS_INOUT_H +#define TYPING_10_FINGERS_INOUT_H + +enum color_b {RED, GREEN}; +struct position_s {int x; int y;} position = {1, 1}; + +void printAt(int x, int y, char c, int color); +void getLine(char* line, char* chars, int length, int wc); +int readChar(void); + +#endif //TYPING_10_FINGERS_INOUT_H diff --git a/main.c b/main.c index b77236d..5b8d475 100644 --- a/main.c +++ b/main.c @@ -5,66 +5,7 @@ #include <sys/ioctl.h> // window size #include <string.h> #include <time.h> - -enum color_b {RED, GREEN}; - -struct position_s {int x; int y;} position = {1, 1}; - -void printAt(int x, int y, char c, int color) { - //printf("%c\033[0m", c); - printf("\033[%d;%dH", y, x); - if (color == RED) { - printf("\033[48;5;124m"); - } else { - printf("\033[48;5;28m"); - } - printf("%c\033[0m", c); -} - -void getLine(char* line, char* chars, int length, int wc) { - srand(time(NULL)); - int word_length = 3; - int count_word_chars = 0; - int i; - for (i = 0; i < length-1; i++, count_word_chars++) { - /* - if (i % wc == 0) { - line[i] = '\n'; - continue; - } - */ - if (count_word_chars == word_length) { - count_word_chars = 0; - line[i] = ' '; - word_length = rand() % 6 + 4; - continue; - } - int ran = rand() % 4 + 0; - line[i] = chars[ran]; - } - line[i] = '\0'; - -} - -void printChar(char* lines, int color, char c) { - printAt(position.x, position.y, lines[position.x-1], color); - if (c != lines[position.x-1]) { - printAt(position.x, position.y+1, c, RED); - } -} - -int readChar() { - struct termios old_settings, new_settings; - - tcgetattr(STDIN_FILENO, &old_settings); - new_settings = old_settings; - - new_settings.c_lflag &= (~ICANON & ~ECHO); // disables output - tcsetattr(STDIN_FILENO, TCSANOW, &new_settings); - char c = getc(stdin); - tcsetattr(STDIN_FILENO, TCSANOW, &old_settings); - return c; -} +#include "inout.h" int runLevel(char *lines, int chars_max) { int c;