299#if defined(OS_WINDOWS)
301 HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
302 if (h_console == NULL) {
303 fprintf(stderr,
"[ERROR] Couldn't handle terminal\n");
308 CONSOLE_SCREEN_BUFFER_INFO console_info;
309 if (GetConsoleScreenBufferInfo(h_console, &console_info) == 0) {
310 fprintf(stderr,
"[ERROR] Couldn't get terminal info\n");
315 return console_info.dwSize.X;
316#elif defined(OS_UNIX)
317 struct winsize t_size;
319 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &t_size) == -1) {
320 fprintf(stderr,
"[ERROR] Couldn't get terminal info\n");
324 return (
short) t_size.ws_col;
376#if defined(OS_WINDOWS)
377 HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
378 if (h_console == NULL) {
379 fprintf(stderr,
"[ERROR] Couldn't handle terminal\n");
384 CONSOLE_SCREEN_BUFFER_INFO console_info;
385 if (GetConsoleScreenBufferInfo(h_console, &console_info) == 0) {
386 fprintf(stderr,
"[ERROR] Couldn't get terminal Y position\n");
391 return console_info.dwCursorPosition.Y;
392#elif defined(OS_UNIX)
393 struct termios old_attr, new_attr;
394 char ch, buf[30] = {0};
395 int i = 0, pow = 1, y = 0;
398 if (tcgetattr(STDIN_FILENO, &new_attr) == -1) {
399 fprintf(stderr,
"[ERROR] Couldn't get terminal attributes\n");
405 old_attr.c_lflag &= ~(ICANON | ECHO);
406 if (tcsetattr(STDIN_FILENO, TCSANOW, &old_attr) == -1) {
407 fprintf(stderr,
"[ERROR] Couldn't set terminal attributes\n");
412 if (write(STDOUT_FILENO,
"\033[6n", 4) != 4) {
413 fprintf(stderr,
"[ERROR] Couldn't get cursor information\n");
419 for (ch = 0; ch !=
'R'; i++) {
420 if (read(STDIN_FILENO, &ch, 1) != 1) {
421 fprintf(stderr,
"[ERROR] Couldn't read cursor information");
428 while (buf[i] !=
';') {
433 while (buf[i] !=
'[') {
434 y = y + (buf[i] -
'0') * pow;
440 if (tcsetattr(0, TCSANOW, &new_attr) == -1) {
441 fprintf(stderr,
"[ERROR] Couldn't reset terminal attributes\n");