From a8afaf3b805e5efd1a154e1ad53ec164e3f0a4e3 Mon Sep 17 00:00:00 2001 From: Gahow Wang Date: Sat, 3 Oct 2026 16:10:42 +0800 Subject: [PATCH] feat(terminal): add persistent browser font size controls --- deploy/nginx.user-8443.conf | 5 +++ public/app.js | 14 +++++++ public/index.html | 8 +++- public/styles.css | 3 ++ public/terminal-preferences.js | 27 ++++++++++++++ public/terminal-settings.css | 32 ++++++++++++++++ public/terminal-settings.js | 62 +++++++++++++++++++++++++++++++ test/terminal-preferences.test.js | 29 +++++++++++++++ 8 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 public/terminal-preferences.js create mode 100644 public/terminal-settings.css create mode 100644 public/terminal-settings.js create mode 100644 test/terminal-preferences.test.js diff --git a/deploy/nginx.user-8443.conf b/deploy/nginx.user-8443.conf index 627afc9..feb0abb 100644 --- a/deploy/nginx.user-8443.conf +++ b/deploy/nginx.user-8443.conf @@ -57,6 +57,11 @@ http { auth_request /api/auth/check; error_page 401 = @term_login; proxy_pass http://127.0.0.1:7681; + # Add controls to ttyd's existing client without rebuilding its embedded frontend. + proxy_set_header Accept-Encoding ""; + sub_filter '' ''; + sub_filter '' ''; + sub_filter_once on; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; diff --git a/public/app.js b/public/app.js index 98afdcb..67fa8e8 100644 --- a/public/app.js +++ b/public/app.js @@ -1,3 +1,5 @@ +import { MIN_FONT_SIZE, MAX_FONT_SIZE, FONT_SIZE_KEY, readFontSize, saveFontSize } from './terminal-preferences.js'; + let state = { gpus: [], liveAgents: { ok: false, agents: [] }, @@ -342,5 +344,17 @@ $('liveAgentForm').addEventListener('submit', async (event) => { } }); +const terminalFontSize = $('terminalFontSize'); +for (let size = MIN_FONT_SIZE; size <= MAX_FONT_SIZE; size++) { + terminalFontSize.add(new Option(`${size} px`, String(size))); +} +terminalFontSize.value = String(readFontSize()); +terminalFontSize.addEventListener('change', () => { + if (!saveFontSize(terminalFontSize.value)) toast('无法保存终端字号,请允许浏览器存储设置。', 'error'); +}); +window.addEventListener('storage', (event) => { + if (event.key === FONT_SIZE_KEY || event.key === null) terminalFontSize.value = String(readFontSize()); +}); + refresh(); setInterval(refresh, 60000); diff --git a/public/index.html b/public/index.html index e3826fc..decfc62 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ Local Kanban - + @@ -55,6 +55,10 @@

Live Agents

+