forked from Seann0425/OOP_Dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_size.cpp
87 lines (72 loc) · 2.23 KB
/
check_size.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <cctype>
#include <cstdlib>
#include <cstring>
#ifdef _WIN32
#include <ncurses/ncurses.h>
#include <windows.h>
#else
#include <ncurses.h>
#endif
// an interactive program helps the user to resize the terminal
#define GREEN 1
#define RED 2
int main() {
const int target_row = 30, target_col = 120;
initscr();
start_color();
cbreak();
noecho();
curs_set(0);
keypad(stdscr, TRUE);
int row, col, prev_row = -1, prev_col = -1;
int mid_row, print_start_col, exit_start_col;
init_pair(GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(RED, COLOR_RED, COLOR_BLACK);
const auto *const print_row = "Current Rows: ";
const auto *const print_col = ", Current Columns: ";
const auto print_len = static_cast<int>(std::strlen(print_row) + std::strlen(print_col) + 4);
const auto *const exit = "(Press Q when done)";
const auto exit_len = static_cast<int>(std::strlen(exit));
#ifdef _WIN32
CONSOLE_SCREEN_BUFFER_INFO csbi;
#endif
while (true) {
#ifdef _WIN32
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
col = csbi.srWindow.Right - csbi.srWindow.Left + 1;
row = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
#else
getmaxyx(stdscr, row, col);
#endif
if (row != prev_row || col != prev_col) {
mid_row = row >> 1;
print_start_col = (col - print_len) >> 1;
exit_start_col = (col - exit_len) >> 1;
clear();
move(mid_row, print_start_col);
// row
printw(print_row);
attron(COLOR_PAIR(row == target_row ? GREEN : RED));
printw("%d", row);
attroff(COLOR_PAIR(row == target_row ? GREEN : RED));
// col
printw(print_col);
attron(COLOR_PAIR(col == target_col ? GREEN : RED));
printw("%d", col);
attroff(COLOR_PAIR(col == target_col ? GREEN : RED));
// exit
mvprintw(mid_row + 1, exit_start_col, exit);
refresh();
prev_row = row;
prev_col = col;
}
if (std::toupper(getch()) == 'Q') break;
}
endwin();
#ifdef _WIN32
std::system("cls");
#else
std::system("clear");
#endif
return 0;
}