mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-07 21:50:08 +01:00
TerminalSize: add new module
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_terminalsize_terminalsize
|
||||
#define FF_INCLUDED_detection_terminalsize_terminalsize
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
typedef struct FFTerminalSizeResult
|
||||
{
|
||||
uint16_t rows;
|
||||
uint16_t columns;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
} FFTerminalSizeResult;
|
||||
|
||||
bool ffDetectTerminalSize(FFTerminalSizeResult* result);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "terminalsize.h"
|
||||
#include "common/io/io.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool ffDetectTerminalSize(FFTerminalSizeResult* result)
|
||||
{
|
||||
struct winsize winsize = {};
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize);
|
||||
|
||||
if (winsize.ws_row == 0 || winsize.ws_col == 0)
|
||||
ffGetTerminalResponse("\033[18t", "\033[8;%hu;%hut", &winsize.ws_row, &winsize.ws_col);
|
||||
|
||||
if (winsize.ws_ypixel == 0 || winsize.ws_xpixel == 0)
|
||||
ffGetTerminalResponse("\033[14t", "\033[4;%hu;%hut", &winsize.ws_ypixel, &winsize.ws_xpixel);
|
||||
|
||||
if (winsize.ws_row == 0 && winsize.ws_col == 0)
|
||||
return false;
|
||||
|
||||
result->rows = winsize.ws_row;
|
||||
result->columns = winsize.ws_col;
|
||||
result->width = winsize.ws_xpixel;
|
||||
result->height = winsize.ws_ypixel;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "terminalsize.h"
|
||||
#include "common/io/io.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
bool ffDetectTerminalSize(FFTerminalSizeResult* result)
|
||||
{
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
||||
{
|
||||
result->columns = (uint16_t) (csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
||||
result->rows = (uint16_t) (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffGetTerminalResponse("\033[18t", "\033[8;%hu;%hut", &result->rows, &result->columns);
|
||||
}
|
||||
}
|
||||
|
||||
if (result->columns == 0 && result->rows == 0)
|
||||
return false;
|
||||
|
||||
{
|
||||
CONSOLE_FONT_INFO cfi;
|
||||
if(GetCurrentConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi)) // Only works for ConHost
|
||||
{
|
||||
result->width = result->columns * (uint16_t) cfi.dwFontSize.X;
|
||||
result->height = result->rows * (uint16_t) cfi.dwFontSize.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Pending https://github.com/microsoft/terminal/issues/8581
|
||||
// if (result->width == 0 && result->height == 0)
|
||||
// ffGetTerminalResponse("\033[14t", "\033[4;%hu;%hut", &result->height, &result->width);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return result->columns > 0 && result->rows > 0;
|
||||
}
|
||||
Reference in New Issue
Block a user