# HG changeset patch # User Matti Hamalainen # Date 1578853059 -7200 # Node ID f2aa3c80924716d89acd11751c13c3fd4aae8602 # Parent ef71ef9b58621de8daac2c9ef4f9568f96fac6ee Use TIOCGWINSZ ioctl on *NIX to get terminal dimensions. diff -r ef71ef9b5862 -r f2aa3c809247 th_util.c --- a/th_util.c Sun Jan 12 19:30:05 2020 +0200 +++ b/th_util.c Sun Jan 12 20:17:39 2020 +0200 @@ -8,6 +8,9 @@ #include "th_util.h" #include #include +#ifdef TH_PLAT_UNIX +# include +#endif /* Default settings @@ -76,19 +79,35 @@ int th_term_width() { +#ifdef TH_PLAT_UNIX + struct winsize cwz; + ioctl(0, TIOCGWINSZ, &cwz); + if (cwz.ws_col < 5) + cwz.ws_col = 80; + return cwz.ws_col; +#else char *var = getenv("COLUMNS"); int res = (var != NULL) ? atoi(var) : 80; if (res < 5) res = 80; return res; +#endif } int th_term_height() { +#ifdef TH_PLAT_UNIX + struct winsize cwz; + ioctl(0, TIOCGWINSZ, &cwz); + if (cwz.ws_row < 5) + cwz.ws_row = 25; + return cwz.ws_row; +#else char *var = getenv("LINES"); int res = (var != NULL) ? atoi(var) : 25; if (res < 1) res = 1; return res; +#endif }