-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSize.mpp
More file actions
37 lines (32 loc) · 1.15 KB
/
Size.mpp
File metadata and controls
37 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module;
#include <CppUtils/System/Windows.hpp>
#if defined(OS_LINUX) or defined(OS_MACOS)
# include <sys/ioctl.h>
# include <unistd.h>
#endif
export module CppUtils.Terminal.Size;
import std;
import CppUtils.Container.Size;
export namespace CppUtils::Terminal
{
#if defined(OS_WINDOWS)
[[nodiscard]] inline auto getTerminalSize() -> Container::Size2
{
auto consoleScreenBufferInfo = CONSOLE_SCREEN_BUFFER_INFO{};
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), std::addressof(consoleScreenBufferInfo));
return Container::Size2{
static_cast<std::size_t>(consoleScreenBufferInfo.srWindow.Right - consoleScreenBufferInfo.srWindow.Left + 1),
static_cast<std::size_t>(consoleScreenBufferInfo.srWindow.Bottom - consoleScreenBufferInfo.srWindow.Top + 1)};
}
#elif defined(OS_LINUX) or defined(OS_MACOS)
[[nodiscard]] inline auto getTerminalSize() -> Container::Size2
{
auto terminalSize = winsize{};
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, std::addressof(terminalSize)) == -1)
return Container::Size2{0, 0};
return Container::Size2{
static_cast<std::size_t>(terminalSize.ws_col),
static_cast<std::size_t>(terminalSize.ws_row)};
}
#endif
}