FTXUI/src/ftxui/screen/terminal.cpp

41 lines
935 B
C++
Raw Normal View History

2020-04-20 03:00:37 +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.
2020-03-23 05:32:44 +08:00
#include "ftxui/screen/terminal.hpp"
2018-09-18 14:48:40 +08:00
#include <stdio.h>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#else
#include <sys/ioctl.h>
#include <unistd.h>
#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() {
#if defined(__EMSCRIPTEN__)
return Dimensions{80, 43};
#elif defined(_WIN32)
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};
#else
2018-09-18 14:48:40 +08:00
winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return Dimensions{w.ws_col, w.ws_row};
#endif
2018-09-18 14:48:40 +08:00
}
} // namespace ftxui