crossterm
crossterm copied to clipboard
Make crossterm implement terminal font support
Task Description
Controlling, getting, the terminal font, would be a nice feature to have.
Task Todo
-
The font types supported by different terminals may be different, but they should all support adjusting the font size.
-
One idea is that we provide an interface to help the user detect which fonts are supported by the current terminal, and then the user can select one of these fonts as needed.
-
The font size setting should be a generic interface, which will give the terminal more possibilities.
-
[ ] Research how we can control the font with windows consols
-
[ ] Research how we can control the font with linux terminals
Notices
windows
struct CONSOLE_FONT
{
DWORD index;
COORD dim;
};
typedef BOOL (WINAPI *PROCSETCONSOLEFONT)(HANDLE, DWORD);
typedef BOOL (WINAPI *PROCGETCONSOLEFONTINFO)(HANDLE,BOOL,DWORD,CONSOLE_FONT*);
typedef COORD (WINAPI *PROCGETCONSOLEFONTSIZE)(HANDLE,DWORD);
typedef DWORD (WINAPI *PROCGETNUMBEROFCONSOLEFONTS)();
typedef BOOL (WINAPI *PROCGETCURRENTCONSOLEFONT)(HANDLE,BOOL,CONSOLE_FONT*);
PROCSETCONSOLEFONT SetConsoleFont;
PROCGETCONSOLEFONTINFO GetConsoleFontInfo;
PROCGETCONSOLEFONTSIZE GConsoleFontSize;
PROCGETNUMBEROFCONSOLEFONTS GetNumberOfConsoleFonts;
PROCGETCURRENTCONSOLEFONT GCurrentConsoleFont;
int _tmain(int argc, _TCHAR* argv[])
{
int nNumFont;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
HMODULE hKernel32 = GetModuleHandle(L"kernel32");
SetConsoleFont = (PROCSETCONSOLEFONT)GetProcAddress(hKernel32,"SetConsoleFont");
GetConsoleFontInfo = (PROCGETCONSOLEFONTINFO)GetProcAddress(hKernel32,"GetConsoleFontInfo");
GConsoleFontSize = (PROCGETCONSOLEFONTSIZE)GetProcAddress(hKernel32,"GetConsoleFontSize");
GetNumberOfConsoleFonts = (PROCGETNUMBEROFCONSOLEFONTS)GetProcAddress(hKernel32,"GetNumberOfConsoleFonts");
GCurrentConsoleFont = (PROCGETCURRENTCONSOLEFONT)GetProcAddress(hKernel32,"GetCurrentConsoleFont");
nNumFont = GetNumberOfConsoleFonts();
CONSOLE_FONT *pFonts = new CONSOLE_FONT[nNumFont];
GetConsoleFontInfo(hConsole, 0, nNumFont, pFonts);
SetConsoleFont(hConsole, pFonts[5].index);
cout << "This is Console C++!" << endl;
return 0;
}