CPPConsole
Loading...
Searching...
No Matches
dimensions.hpp
Go to the documentation of this file.
1#ifndef __CPP_CONSOLE_DIMENSIONS_HPP__
2#define __CPP_CONSOLE_DIMENSIONS_HPP__
3
4#ifdef __WIN32
5#include <Windows.h>
6#else
7#include <stdio.h>
8#include <sys/ioctl.h>
9#include <termios.h>
10#include <unistd.h>
11#endif
12
16namespace console {
20typedef struct {
21 int width;
22 int height;
24
31#ifdef __WIN32
32 CONSOLE_SCREEN_BUFFER_INFO csbi;
33 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
34 return {csbi.srWindow.Right - csbi.srWindow.Left + 1,
35 csbi.srWindow.Bottom - csbi.srWindow.Top + 1};
36#else
37 struct winsize w;
38 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
39 return {w.ws_row, w.ws_col};
40#endif
41}
42} // namespace console
43
44#endif
Namespace Containing all console commands.
Definition ansi.hpp:16
Dimensions getDimensions()
Gets the width and height of the console.
Definition dimensions.hpp:30
A structure representing the dimensions of the console.
Definition dimensions.hpp:20
int width
Definition dimensions.hpp:21
int height
Definition dimensions.hpp:22