get the screen size Screen::rows and Screen::cols, returns Screen::cols
| 155 | |
| 156 | // get the screen size Screen::rows and Screen::cols, returns Screen::cols |
| 157 | size_t Screen::getsize() |
| 158 | { |
| 159 | // get current window size from ioctl |
| 160 | #if defined(OS_WIN) |
| 161 | CONSOLE_SCREEN_BUFFER_INFO info; |
| 162 | if (GetConsoleScreenBufferInfo(hConOut, &info)) |
| 163 | { |
| 164 | rows = info.dwSize.Y; |
| 165 | cols = info.dwSize.X; |
| 166 | } |
| 167 | else |
| 168 | #elif defined(TIOCGWIN) |
| 169 | struct winsize winsize; |
| 170 | if (ioctl(tty, TIOCGWIN, &winsize) == 0) |
| 171 | { |
| 172 | rows = winsize.ts_lines; |
| 173 | cols = winsize.ts_cols; |
| 174 | } |
| 175 | else |
| 176 | #elif defined(TIOCGWINSZ) |
| 177 | struct winsize winsize; |
| 178 | if (ioctl(tty, TIOCGWINSZ, &winsize) == 0) |
| 179 | { |
| 180 | rows = winsize.ws_row; |
| 181 | cols = winsize.ws_col; |
| 182 | } |
| 183 | else |
| 184 | #endif |
| 185 | { |
| 186 | // save cursor position, reset window scroll margins, move cursor to 999;999 |
| 187 | put("\0337\033[r\033[999;999H", 15); |
| 188 | |
| 189 | int row = -1; |
| 190 | int col = -1; |
| 191 | |
| 192 | // get cursor position 0 <= row <= 999 and 0 <= col <= 999 |
| 193 | getpos(&row, &col); |
| 194 | |
| 195 | if (row > 0 && col > 0) |
| 196 | { |
| 197 | rows = row + 1; |
| 198 | cols = col + 1; |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | rows = 24; |
| 203 | cols = 80; |
| 204 | |
| 205 | #ifndef OS_WIN |
| 206 | const char *env; |
| 207 | env = getenv("LINES"); |
| 208 | if (env != NULL) |
| 209 | { |
| 210 | rows = atoi(env); |
| 211 | if (row <= 1) |
| 212 | rows = 24; |
| 213 | } |
| 214 | env = getenv("COLUMNS"); |
nothing calls this directly
no outgoing calls
no test coverage detected