Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring fonts if possible #99

Open
bitspittle opened this issue Jul 19, 2023 · 2 comments
Open

Allow configuring fonts if possible #99

bitspittle opened this issue Jul 19, 2023 · 2 comments
Labels
enhancement New feature / functionality

Comments

@bitspittle
Copy link
Contributor

bitspittle commented Jul 19, 2023

This was a feature request from a user, who shared a way you can change fonts on Windows:

actual fun changeConsoleFonts() {
    platform.posix.system("chcp 65001")
    memScoped {
        val fontName = "Lucida Console"
        val hnd = GetStdHandle(STD_OUTPUT_HANDLE)
        if (hnd != INVALID_HANDLE_VALUE) {
            val info = alloc<CONSOLE_FONT_INFOEX>()
            info.cbSize = sizeOf<CONSOLE_FONT_INFOEX>().toUInt()
            val tt: Boolean
            // First determine whether there's already a TrueType font.
            if (GetCurrentConsoleFontEx(hnd, FALSE, info.ptr) == TRUE) {
//                tt = (info.FontFamily and TMPF_TRUETYPE.toUInt()).toInt() == TMPF_TRUETYPE
//                if (tt) {
//                    println("The console already is using a TrueType font.")
//                    return
//                }
                // Set console font to Lucida Console.
                val newInfo = alloc<CONSOLE_FONT_INFOEX>()
                newInfo.cbSize = sizeOf<CONSOLE_FONT_INFOEX>().toUInt()
                newInfo.FontFamily = TMPF_TRUETYPE.toUInt()
                newInfo.FaceName.writeBytes(fontName.encodeToByteArray())
                // Get some settings from current font.
                newInfo.dwFontSize.X = info.dwFontSize.X
                newInfo.dwFontSize.Y = info.dwFontSize.Y
                newInfo.FontWeight = info.FontWeight
                SetCurrentConsoleFontEx(hnd, FALSE, newInfo.ptr)
            } else {
                println("GetCurrentConsoleFontEx false.")
            }
        }
    }
}

Windows is actually pretty powerful with their console API. I'm not sure it's a standard feature, however.

So questions...

  • Is there a way to allow configuring fonts in a standard way across all terminals?
  • Is it worth exposing Kotter API bits that are platform specific?
@bitspittle bitspittle added the enhancement New feature / functionality label Jul 19, 2023
@KyleMcB
Copy link

KyleMcB commented Dec 25, 2024

I think there is no way via ansi to set the font. On *nix this setting is controlled by the terminal emulator. Perhaps a terminal emulator has it own special api for setting font. Would be cool for the app to make sure a nerd font is in use, in my opinion. Not sure if it is worth it to expose windows only api.
Kitty and alacritty save their font choice in a config file. I doubt that updates in real time, but maybe. That would be a global change though. not a nested font CSS style.

@bitspittle
Copy link
Contributor Author

Are there any examples of popular CLI applications out there that override the terminal font?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature / functionality
Projects
None yet
Development

No branches or pull requests

2 participants