TSE: Linux: How to automatically set the TSE font?

4 views
Skip to first unread message

knud van eeden

unread,
Jul 1, 2025, 8:24:22 PMJul 1
to SemWare TSE Pro Text Editor
Hello,

Here already a proof of concept, that works:

1. Create and compile this C program (tested and compiled in Embarcadero C++ command line version 7.3)

---

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]) {
    // Defaults
    wchar_t fontNameW[LF_FACESIZE] = L"Courier New";
    int fontSizeY = 20;

    // Parse font name from argv[1]
    if (argc >= 2) {
        MultiByteToWideChar(CP_ACP, 0, argv[1], -1, fontNameW, LF_FACESIZE);
    }

    // Parse font size from argv[2]
    if (argc >= 3) {
        fontSizeY = atoi(argv[2]);
        if (fontSizeY <= 0 || fontSizeY > 100) {
            fprintf(stderr, "Invalid font size: %s\n", argv[2]);
            return 1;
        }
    }

    printf("Args: argc=%d\n", argc);
    for (int i = 0; i < argc; i++) {
     printf("argv[%d] = '%s'\n", i, argv[i]);
    }

    // Get console handle
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hConsole == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "Error: GetStdHandle failed.\n");
        return 2;
    }

    // Fill in CONSOLE_FONT_INFOEX
    CONSOLE_FONT_INFOEX cfi;
    memset(&cfi, 0, sizeof(cfi));
    cfi.cbSize = sizeof(cfi);
    cfi.nFont = 0;
    cfi.dwFontSize.X = 0;
    cfi.dwFontSize.Y = fontSizeY;
    cfi.FontFamily = FF_DONTCARE;
    cfi.FontWeight = FW_NORMAL;
    wcscpy_s(cfi.FaceName, LF_FACESIZE, fontNameW);

DWORD mode;
if (!GetConsoleMode(hConsole, &mode)) {
    fprintf(stderr, "Console handle is not interactive (detached or redirected).\n");
    return 6;
}

    // Apply font
    if (!SetCurrentConsoleFontEx(hConsole, FALSE, &cfi)) {
        fprintf(stderr, "Error: SetCurrentConsoleFontEx failed.\n");
        return 3;
    }

    wprintf(L"Font set to \"%s\" size %d.\n", fontNameW, fontSizeY);
    return 0;
}

---

2. Save it as set_console_font_arg.c e.g. in your working directory

3 So after compiling there is an executable set_console_font_arg.exe

4. Then create a batch file ddd.bat

5. Put it e.g. in your working directory.

---

@echo off
// C:\temp\tse_linux\knud\set_console_font_arg.exe "Courier New" 16
// C:\temp\tse_linux\knud\set_console_font_arg.exe "Courier" 16
// C:\temp\tse_linux\knud\set_console_font_arg.exe "Terminal" 9 // starts raster font
// C:\temp\tse_linux\knud\set_console_font_arg.exe "Consolas" 12
C:\temp\tse_linux\knud\set_console_font_arg.exe "Perfect DOS VGA 437" 16
wsl.exe ~/tse/e "/mnt/c/temp/tse_linux/knud/ddd.s"

---

6. Then start cmd.exe

7. Then run ddd.bat

8. It will then start TSE, e.g. loading the file ddd.s and set the font in this example automatically to 'Perfect DOS VGA 437'

Note: It seems at this moment IMPOSSIBLE to change the font from within TSE for Linux.

Tested successfully in TSE for Linux version 4.5.6 on WSL Linux 
Microsoft Windows 10 Professional
cmd.exe version 10.0.19045.5965
Source: ChatGPT

with friendly greetings
Knud van Eeden


Reply all
Reply to author
Forward
0 new messages