mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-19 17:46:46 +02:00
Merge pull request #10738 from poweredbypie/mingw-windowSize
Implement `updateWindowSize` for Windows
This commit is contained in:
commit
43dc575fd7
2 changed files with 16 additions and 8 deletions
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
|
# define WIN32_LEAN_AND_MEAN
|
||||||
|
# include <windows.h>
|
||||||
# define isatty _isatty
|
# define isatty _isatty
|
||||||
#else
|
#else
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
|
@ -97,17 +99,26 @@ std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int w
|
||||||
static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
|
static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
|
||||||
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
void updateWindowSize()
|
void updateWindowSize()
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
if (ioctl(2, TIOCGWINSZ, &ws) == 0) {
|
if (ioctl(2, TIOCGWINSZ, &ws) == 0) {
|
||||||
auto windowSize_(windowSize.lock());
|
auto windowSize_(windowSize.lock());
|
||||||
windowSize_->first = ws.ws_row;
|
windowSize_->first = ws.ws_row;
|
||||||
windowSize_->second = ws.ws_col;
|
windowSize_->second = ws.ws_col;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||||
|
// From https://stackoverflow.com/a/12642749
|
||||||
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info) != 0) {
|
||||||
|
auto windowSize_(windowSize.lock());
|
||||||
|
// From https://github.com/libuv/libuv/blob/v1.48.0/src/win/tty.c#L1130
|
||||||
|
windowSize_->first = info.srWindow.Bottom - info.srWindow.Top + 1;
|
||||||
|
windowSize_->second = info.dwSize.X;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<unsigned short, unsigned short> getWindowSize()
|
std::pair<unsigned short, unsigned short> getWindowSize()
|
||||||
|
|
|
@ -21,16 +21,13 @@ std::string filterANSIEscapes(std::string_view s,
|
||||||
bool filterAll = false,
|
bool filterAll = false,
|
||||||
unsigned int width = std::numeric_limits<unsigned int>::max());
|
unsigned int width = std::numeric_limits<unsigned int>::max());
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recalculate the window size, updating a global variable. Used in the
|
* Recalculate the window size, updating a global variable.
|
||||||
* `SIGWINCH` signal handler.
|
*
|
||||||
|
* Used in the `SIGWINCH` signal handler on Unix, for example.
|
||||||
*/
|
*/
|
||||||
void updateWindowSize();
|
void updateWindowSize();
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the number of rows and columns of the terminal.
|
* @return the number of rows and columns of the terminal.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue