#include #include #ifndef _WIN32 #include #include #endif #include "util.h" int getTerminalWidth() { // デフォルト値として80を設定 int width = 80; #ifndef _WIN32 // Unix系OSの場合、ioctlでターミナルサイズを取得 struct winsize w; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) { width = w.ws_col; } #endif return width; } int getTerminalHeight() { // デフォルト値として12を設定 int height = 12; #ifndef _WIN32 // Unix系OSの場合、ioctlでターミナルサイズを取得 struct winsize w; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) { height = w.ws_row; } #endif return height; } void csleep(const double i) { clock_t g; g = i * CLOCKS_PER_SEC + clock(); while (g > clock()) ; } int min(const int a, const int b) { if (a >= b) { return b; } return a; }