Maipa's Standard Library Extension 1.5.6
mstd
Loading...
Searching...
No Matches
terminal_management.hpp
1/*
2 * mstd - Maipa's Standard Library
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/mstd/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _MSTD_TERMINAL_MANAGEMENT_HPP_
12 #define _MSTD_TERMINAL_MANAGEMENT_HPP_
13
14 #include <mstd/config.hpp>
15
17_MSTD_WARNING("this is only available for c++17 and greater!");
18 #else
19
20 #include <mstd/terminal_types.hpp>
21
22// TODO: dodac kolorowanie
23
24namespace mstd {
25 inline void get_terminal_size(int& width, int& height) {
26 #ifdef _WIN32
27 width = 0;
28 height = 0;
29
30 CONSOLE_SCREEN_BUFFER_INFO csbi;
31 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
32 width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
33 height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
34 #elif defined(__linux__) || defined(__APPLE__)
35 struct winsize w;
36 ioctl(fileno(stdout), TIOCGWINSZ, &w);
37 width = static_cast<int>(w.ws_col);
38 height = static_cast<int>(w.ws_row);
39 #endif
40 }
41
42 inline void clear_terminal() {
43 #ifdef _WIN32
44 system("cls"); // Windows: czysci ekran i historie
45 #else
46 system("clear && printf '\\e[3J'"); // Linux/macOS: czysci ekran i usuwa historie
47 #endif
48 }
49} // namespace mstd
50
51 #endif
52#endif
#define _MSTD_HAS_CXX17
Definition config.hpp:45
Definition arithmetic_types.hpp:23
void get_terminal_size(int &width, int &height)
Definition terminal_management.hpp:25
void clear_terminal()
Definition terminal_management.hpp:42