55 lines
1.0 KiB
C
55 lines
1.0 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <Windows.h>
|
|
|
|
int z__b_stream_is_tty(FILE *fp)
|
|
{
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
HANDLE console = (HANDLE)_get_osfhandle(fileno(fp));
|
|
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
|
|
|
|
return status == TRUE ? 1 : 0;
|
|
}
|
|
|
|
int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h)
|
|
{
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
HANDLE console = (HANDLE)_get_osfhandle(fileno(fp));
|
|
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
|
|
|
|
if (status == FALSE) {
|
|
return -1;
|
|
}
|
|
|
|
if (w) {
|
|
*w = csbi.dwMaximumWindowSize.X;
|
|
}
|
|
|
|
if (h) {
|
|
*h = csbi.dwMaximumWindowSize.Y;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
|
|
{
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
HANDLE console = (HANDLE)_get_osfhandle(fileno(in));
|
|
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
|
|
|
|
if (status == FALSE) {
|
|
return -1;
|
|
}
|
|
|
|
if (x) {
|
|
*x = csbi.dwCursorPosition.X;
|
|
}
|
|
|
|
if (y) {
|
|
*y = csbi.dwCursorPosition.Y;
|
|
}
|
|
|
|
return 0;
|
|
}
|