Use Console API to get terminal size on Windows

Co-authored-by: Mikael Olenfalk <mikael@olenfalk.se>
Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Mikael Olenfalk 2020-03-21 16:18:15 +01:00 committed by ArthurSonzogni
parent 539ec45036
commit 9e71c467f6

View File

@ -1,16 +1,31 @@
#include "ftxui/screen/terminal.hpp"
#include <stdio.h>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#else
#include <sys/ioctl.h>
#include <unistd.h>
#endif
#include <iostream>
namespace ftxui {
Terminal::Dimensions Terminal::Size() {
#ifdef __EMSCRIPTEN__
#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
winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);