2020-03-23 05:32:44 +08:00
|
|
|
#include "ftxui/screen/terminal.hpp"
|
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
#include <stdio.h>
|
2020-03-21 23:18:15 +08:00
|
|
|
|
2020-03-25 15:54:03 +08:00
|
|
|
#if defined(_WIN32)
|
2020-08-16 06:24:18 +08:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define NOMINMAX
|
|
|
|
#include <Windows.h>
|
2020-03-21 23:18:15 +08:00
|
|
|
#else
|
2020-08-16 06:24:18 +08:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
2020-03-21 23:18:15 +08:00
|
|
|
#endif
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-03-23 05:32:44 +08:00
|
|
|
#include <iostream>
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
|
|
|
Terminal::Dimensions Terminal::Size() {
|
2020-03-21 23:18:15 +08:00
|
|
|
#if defined(__EMSCRIPTEN__)
|
2019-06-23 23:47:33 +08:00
|
|
|
return Dimensions{80, 43};
|
2020-03-25 15:54:03 +08:00
|
|
|
#elif defined(_WIN32)
|
2020-03-21 23:18:15 +08:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
int columns, rows;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
|
|
|
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
|
|
|
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
|
|
|
return Dimensions{columns, rows};
|
2019-02-02 08:59:48 +08:00
|
|
|
#else
|
2018-09-18 14:48:40 +08:00
|
|
|
winsize w;
|
|
|
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
|
|
return Dimensions{w.ws_col, w.ws_row};
|
2019-02-02 08:59:48 +08:00
|
|
|
#endif
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2019-06-23 23:47:33 +08:00
|
|
|
} // namespace ftxui
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|