Nimbin[12]?Web & Tools / typing_10_fingers / commits / 0b775fd

typing_10_fingers git · main

10 finger typing trainer (CMake)

typing terminal c cmake · first commit 2024-02-26 · last commit 2024-03-16 (2 years ago) · synced 3 days ago · upstream: git.ide3.de/chfis005/typing_10_fingers

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.gz

Für Windows angepasst.

Clostosus · 2024-02-27 08:50 · 0b775fd05ca4879753eda15878658254fb5055b5

 main.c | 82 +++++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 48 insertions(+), 34 deletions(-)

diff --git a/main.c b/main.c
index 5b8d475..f4d8890 100644
--- a/main.c
+++ b/main.c
@@ -1,72 +1,86 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <termios.h>
-#include <sys/ioctl.h> // window size
-#include <string.h>
-#include <time.h>
 #include "inout.h"
 
-int runLevel(char *lines, int chars_max) {
-    int c;
+void sysClear() {
+#ifdef _WIN32
+    system("cls");
+#else
+    system("clear");
+#endif
+}
+
+int runLevel(wchar_t *lines, int chars_max, struct position_s position) {
+    wchar_t c = L'\0';
     int mistakes = 0;
     do {
         c = readChar();
         int color = (c == lines[position.x-1]) ? GREEN : RED;
-        printChar(lines, color, c);
+        printChar(lines, color, c, position);
         if (c != lines[position.x-1])
             mistakes++;
         position.x++;
-    } while ( c != EOF && position.x < chars_max);
+    } while ((c != EOF) && position.x < chars_max);
     return mistakes;
 }
 
 
-char left[] = "asdfg";
-char left_t[] = "qwert";
-char left_b[] = "<yxcvb";
+wchar_t left[] = { L'a', L's', L'd', L'f', L'g', L'\0' };
+wchar_t left_t[] = { L'q', L'w', L'e', L'r', L't', L'\0' };
+wchar_t left_b[] = { L'<', L'y', L'x', L'c', L'v', L'b', L'\0' };
 
-char right[] = "jklöhä#";
-char right_t[] = "uiopüz+";
-char right_b[] = "m,.-n";
+wchar_t right[] = { L'j', L'k', L'l', L'ö', L'h', L'ä', L'#', L'\0' };
+wchar_t right_t[] = { L'u', L'i', L'o', L'p', L'ü', L'z', L'+', L'\0' };
+wchar_t right_b[] = { L'm', L',', L'.', L'-', L'n', L'\0' };
 
 
 
 int main() {
+    setlocale(LC_ALL, "");
+
+
+#ifdef WINDOWS
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
+    int window_cols = csbi.srWindow.Right - csbi.srWindow.Left +  1;
+    int window_rows = csbi.srWindow.Bottom - csbi.srWindow.Top +  1;
+    typedef struct windows_winsize{int ws_col,ws_row;}winsize_t;
+    winsize_t w;
+    w.ws_col=window_cols;  w.ws_row=window_rows;
+#else
     struct winsize w;
     ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
-    // window.cols = w.ws_col;
-    // window.rows = w.ws_row;
-
-
+    window.cols = w.ws_col;
+    window.rows = w.ws_row;
+#endif
+    struct position_s position = {1, 1};
 
     int chars_max = 15;
-    char lines[chars_max];
+    wchar_t lines[chars_max];
 
     int level = 1;
     int mistakes = 1;
-    char lvl_arr[100]; 
-    while(1) {
-        switch (level) {
-            case 1: 
-                strcpy(lvl_arr, left);
+    wchar_t lvl_arr[100];
+    while(1){
+        switch(level) {
+            case 1:
+                wcscpy(lvl_arr, left);
                 break;
-            case 2: 
-                strcpy(lvl_arr, right);
+            case 2:
+                wcscpy(lvl_arr, right);
                 break;
+            default:
+                fprintf(stderr,"Error selecting the level!\n");
         }
 
-        system("clear");
+        sysClear();
         position.x = 1, position.y = 1;
 
         getLine(lines, lvl_arr, chars_max, w.ws_col);
 
-        printf("\033[1;1H%s", lines);
+        wprintf(L"\033[1;1H%ls", lines);
 
-        mistakes = runLevel(lines, chars_max);
+        mistakes = runLevel(lines, chars_max, position);
         if (mistakes == 0)
             level++;
     }
-
     return 0;
-}
+}
\ No newline at end of file