kotter icon indicating copy to clipboard operation
kotter copied to clipboard

Allow configuring fonts if possible

Open bitspittle opened this issue 2 years ago • 2 comments

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 avatar Jul 19 '23 18:07 bitspittle

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.

KyleMcB avatar Dec 25 '24 08:12 KyleMcB

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

bitspittle avatar Dec 25 '24 18:12 bitspittle