typing_10_fingers git · main
git clone https://git.christianimmanuel.de/tools/typing_10_fingers.gitwget https://git.christianimmanuel.de/tools/typing_10_fingers/archive/typing_10_fingers.tar.gzinout.c raw
#include "inout.h"
void printAt(int x, int y, wchar_t c, int color){
//printf("%c\033[0m", c);
if (color == RED){
wprintf(L"\033[%d;%dH\033[48;5;124m%lc\033[0m", y, x, c);
} else {
wprintf(L"\033[%d;%dH\033[48;5;28m%lc\033[0m", y, x, c);
}
}
void getLine(wchar_t* line, wchar_t* 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() % (wcslen(chars));
line[i] = chars[ran];
}
line[i] = L'\0';
}
void printChar(wchar_t* lines, int color, wchar_t c, struct position_s position){
printAt(position.x, position.y, lines[position.x-1], color);
if (c != lines[position.x-1]) {
printAt(position.x, position.y+1, c, RED);
}
}
wchar_t readChar() {
wchar_t c = L'\0';
#ifndef WINDOWS
struct termios old_settings, new_settings;
tcgetattr(STDIN_FILENO, &old_settings);
new_settings = old_settings;
new_settings.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &new_settings);
c = fgetwc(stdin);
tcsetattr(STDIN_FILENO, TCSANOW, &old_settings);
#else //readChar für Windows
c=fgetwc(stdin);
#endif
return c;
}