From 8b0e7f5bbe5791410b9609276ffd6c4dbff46c8f Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Sun, 25 Jan 2026 12:22:34 +0000 Subject: [PATCH] Fix xterm.js font override using canvas monkey-patch The previous approach tried to access container.terminal which doesn't exist since textual.js doesn't expose the terminal instance to the DOM. New approach monkey-patches CanvasRenderingContext2D.prototype.font setter BEFORE textual.js loads to intercept all canvas font assignments and replace xterm.js default font with our custom monospace stack. Bump version to 0.3.16 --- pyproject.toml | 2 +- src/textual_webterm/local_server.py | 75 +++++++++++++++-------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1f4c346..5f631f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual-webterm" -version = "0.3.15" +version = "0.3.16" description = "Serve terminal sessions over the web" authors = ["Will McGugan "] license = "MIT" diff --git a/src/textual_webterm/local_server.py b/src/textual_webterm/local_server.py index e875961..42052fb 100644 --- a/src/textual_webterm/local_server.py +++ b/src/textual_webterm/local_server.py @@ -838,63 +838,64 @@ class LocalServer: ws_url = self._get_ws_url_from_request(request, route_key) page_title = available_app.name if available_app else "Textual Web Terminal" + # Custom monospace font stack for terminals + custom_font = ( + 'ui-monospace, "SFMono-Regular", "FiraCode Nerd Font", ' + '"FiraMono Nerd Font", "Fira Code", "Roboto Mono", Menlo, Monaco, ' + 'Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace' + ) + # Font to replace in xterm.js canvas rendering + old_font = "'Roboto Mono', Monaco, 'Courier New', monospace" html_content = f""" {page_title} +