townmouse 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +196 -0
- package/DESIGN.md +153 -0
- package/LICENSE +661 -0
- package/README.md +600 -2
- package/SECURITY.md +60 -0
- package/TOWNMOUSE.md +91 -0
- package/assets/brand/mascot/README.md +23 -0
- package/assets/brand/mascot/townmouse-aristocrat.png +0 -0
- package/assets/brand/mascot/townmouse-icon.svg +1 -0
- package/assets/brand/mascot/townmouse-monocled.png +0 -0
- package/bin/townmouse +68 -0
- package/docs/PACKAGING.md +371 -0
- package/docs/browser-workspace.md +237 -0
- package/docs/panes.md +442 -0
- package/native/TownmouseApp.swift +108 -0
- package/npm-shrinkwrap.json +1282 -0
- package/package.json +93 -4
- package/public/apple-touch-icon.png +0 -0
- package/public/brand/floydslabs-credit.png +0 -0
- package/public/brand/floydslabs-credit.webp +0 -0
- package/public/brand/townmouse-aristocrat.webp +0 -0
- package/public/brand/townmouse-monocled.webp +0 -0
- package/public/browser-picture.mjs +159 -0
- package/public/clipboard-text.mjs +5 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/favicon.svg +1 -0
- package/public/features/app-version.mjs +35 -0
- package/public/features/autosave.mjs +80 -0
- package/public/features/clipboard.mjs +69 -0
- package/public/features/command-palette.mjs +181 -0
- package/public/features/desktop-palette.mjs +19 -0
- package/public/features/export.mjs +37 -0
- package/public/features/file-drop.mjs +77 -0
- package/public/features/floating-palette.mjs +113 -0
- package/public/features/fontsize.mjs +72 -0
- package/public/features/haptic-keys.mjs +42 -0
- package/public/features/history-undo.mjs +102 -0
- package/public/features/keepalive.mjs +36 -0
- package/public/features/keybar-config.mjs +70 -0
- package/public/features/keyboard-shortcuts.mjs +74 -0
- package/public/features/links.mjs +139 -0
- package/public/features/multi-window-sync.mjs +76 -0
- package/public/features/osc-bridge.mjs +64 -0
- package/public/features/phone-landscape-focus.mjs +157 -0
- package/public/features/recent-commands.mjs +100 -0
- package/public/features/search.mjs +134 -0
- package/public/features/session-lock.mjs +96 -0
- package/public/features/session-manager.mjs +251 -0
- package/public/features/settings-sync.mjs +77 -0
- package/public/features/shortcut-help.mjs +85 -0
- package/public/features/smart-completions.mjs +101 -0
- package/public/features/smart-suggest.mjs +124 -0
- package/public/features/snippets.mjs +85 -0
- package/public/features/split-view.mjs +102 -0
- package/public/features/status-metrics.mjs +137 -0
- package/public/features/stylus-support.mjs +124 -0
- package/public/features/swipe-history.mjs +141 -0
- package/public/features/swipe-sessions.mjs +85 -0
- package/public/features/tab-reorder.mjs +70 -0
- package/public/features/theme-system.mjs +51 -0
- package/public/features/toast-status.mjs +118 -0
- package/public/features/two-finger-menu.mjs +87 -0
- package/public/features/voice-input.mjs +244 -0
- package/public/features/wake-fullscreen.mjs +67 -0
- package/public/features/window-title.mjs +47 -0
- package/public/features/zoom.mjs +80 -0
- package/public/icon-128.png +0 -0
- package/public/icon-180.png +0 -0
- package/public/icon-192.png +0 -0
- package/public/icon-48.png +0 -0
- package/public/icon-512-maskable.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +1 -0
- package/public/index.html +2304 -0
- package/public/input-chunks.mjs +22 -0
- package/public/input-guard.mjs +218 -0
- package/public/manifest.json +56 -0
- package/public/panes.css +1433 -0
- package/public/panes.html +211 -0
- package/public/panes.mjs +3183 -0
- package/public/service-worker.js +67 -0
- package/public/workspace.css +1621 -0
- package/public/workspace.mjs +1715 -0
- package/scripts/install-service.sh +303 -0
- package/scripts/node-runtime.sh +138 -0
- package/scripts/panes +568 -0
- package/scripts/prepare-native.sh +35 -0
- package/scripts/retire-legacy-service.sh +76 -0
- package/scripts/run-hooks +69 -0
- package/scripts/townmouse.sh +152 -0
- package/scripts/uninstall-service.sh +65 -0
- package/src/agent-guide.js +329 -0
- package/src/attachments.js +128 -0
- package/src/browser-dom.js +548 -0
- package/src/browser-workspace.js +1733 -0
- package/src/chrome-resolve.js +80 -0
- package/src/owner-page.js +43 -0
- package/src/pty-permissions.js +99 -0
- package/src/regex-worker.js +13 -0
- package/src/replay-text.js +189 -0
- package/src/request-boundary.js +58 -0
- package/src/safe-regex.js +87 -0
- package/src/server.js +1582 -0
- package/src/shell-resolve.js +42 -0
- package/src/static-deps.js +61 -0
- package/src/workspace-panes.js +1431 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice input — push-to-talk speech capture into the terminal input line.
|
|
3
|
+
*
|
|
4
|
+
* Captures a short utterance with getUserMedia + MediaRecorder, sends it over
|
|
5
|
+
* the existing JSON WebSocket as bounded base64 chunks, then injects the final
|
|
6
|
+
* server transcript exactly once through T1.sendData(). It never sends Enter.
|
|
7
|
+
*/
|
|
8
|
+
const MAX_RECORDING_MS = 20_000;
|
|
9
|
+
const DANGEROUS_COMMAND_RE = /\b(rm\s+-rf|mkfs|dd\s+if=|:\(\)\s*\{|diskutil\s+erase|shutdown|reboot)\b/i;
|
|
10
|
+
|
|
11
|
+
export function init(T1) {
|
|
12
|
+
T1.ui.addStyle(`
|
|
13
|
+
.t1voice-button.listening,
|
|
14
|
+
.t1voice-key.listening {
|
|
15
|
+
background: #e2a69e;
|
|
16
|
+
color: #14171b;
|
|
17
|
+
border-color: #e2a69e;
|
|
18
|
+
}
|
|
19
|
+
.t1voice-button.transcribing,
|
|
20
|
+
.t1voice-key.transcribing {
|
|
21
|
+
background: #dcc38b;
|
|
22
|
+
color: #14171b;
|
|
23
|
+
border-color: #dcc38b;
|
|
24
|
+
}
|
|
25
|
+
.t1voice-key {
|
|
26
|
+
min-width: 64px;
|
|
27
|
+
}
|
|
28
|
+
`);
|
|
29
|
+
|
|
30
|
+
let recorder = null;
|
|
31
|
+
let stream = null;
|
|
32
|
+
let state = 'idle';
|
|
33
|
+
let stopTimer = 0;
|
|
34
|
+
let pendingChunks = Promise.resolve();
|
|
35
|
+
const buttons = new Set();
|
|
36
|
+
|
|
37
|
+
function supported() {
|
|
38
|
+
return !!(navigator.mediaDevices?.getUserMedia && window.MediaRecorder && window.isSecureContext);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function wsOpen() {
|
|
42
|
+
const sock = T1.ws;
|
|
43
|
+
return sock && sock.readyState === WebSocket.OPEN ? sock : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function setState(next) {
|
|
47
|
+
state = next;
|
|
48
|
+
for (const button of buttons) {
|
|
49
|
+
button.classList.toggle('listening', state === 'recording');
|
|
50
|
+
button.classList.toggle('transcribing', state === 'transcribing');
|
|
51
|
+
button.disabled = state === 'transcribing' || !supported();
|
|
52
|
+
button.setAttribute('aria-pressed', state === 'recording' ? 'true' : 'false');
|
|
53
|
+
button.textContent = state === 'recording' ? 'Stop' : state === 'transcribing' ? 'Wait' : 'Voice';
|
|
54
|
+
button.title = supported() ? 'Voice input' : 'Voice input needs a secure connection and a supported browser';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function pickMimeType() {
|
|
59
|
+
const candidates = [
|
|
60
|
+
'audio/webm;codecs=opus',
|
|
61
|
+
'audio/webm',
|
|
62
|
+
'audio/mp4',
|
|
63
|
+
'audio/ogg;codecs=opus'
|
|
64
|
+
];
|
|
65
|
+
for (const type of candidates) {
|
|
66
|
+
try {
|
|
67
|
+
if (MediaRecorder.isTypeSupported?.(type)) return type;
|
|
68
|
+
} catch (_) {}
|
|
69
|
+
}
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function arrayBufferToBase64(buffer) {
|
|
74
|
+
const bytes = new Uint8Array(buffer);
|
|
75
|
+
let binary = '';
|
|
76
|
+
const stride = 0x8000;
|
|
77
|
+
for (let i = 0; i < bytes.length; i += stride) {
|
|
78
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + stride));
|
|
79
|
+
}
|
|
80
|
+
return btoa(binary);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function normalizeTranscript(text) {
|
|
84
|
+
return String(text || '')
|
|
85
|
+
.trim()
|
|
86
|
+
.replace(/\s+/g, ' ')
|
|
87
|
+
.replace(/\s+([|/.-])/g, '$1')
|
|
88
|
+
.replace(/\bpipe\b/gi, '|')
|
|
89
|
+
.replace(/\bslash\b/gi, '/')
|
|
90
|
+
.replace(/\bdash dash\b/gi, '--')
|
|
91
|
+
.replace(/\bdot\b/gi, '.')
|
|
92
|
+
.replace(/[.!?]+$/g, '');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function sendJson(payload) {
|
|
96
|
+
const sock = wsOpen();
|
|
97
|
+
if (!sock) {
|
|
98
|
+
T1.toast('Voice input needs an active terminal connection', 'warn');
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
sock.send(JSON.stringify(payload));
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function sendBlob(blob) {
|
|
106
|
+
if (!blob || blob.size === 0) return;
|
|
107
|
+
const b64 = arrayBufferToBase64(await blob.arrayBuffer());
|
|
108
|
+
sendJson({ type: 'voice-chunk', b64 });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function cleanupRecording() {
|
|
112
|
+
if (stopTimer) {
|
|
113
|
+
clearTimeout(stopTimer);
|
|
114
|
+
stopTimer = 0;
|
|
115
|
+
}
|
|
116
|
+
if (stream) {
|
|
117
|
+
for (const track of stream.getTracks()) track.stop();
|
|
118
|
+
}
|
|
119
|
+
stream = null;
|
|
120
|
+
recorder = null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function start() {
|
|
124
|
+
if (state !== 'idle') return;
|
|
125
|
+
if (!supported()) {
|
|
126
|
+
T1.toast('Voice input needs a secure connection and a supported browser', 'warn');
|
|
127
|
+
setState('idle');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let serverVoiceStarted = false;
|
|
131
|
+
try {
|
|
132
|
+
stream = await navigator.mediaDevices.getUserMedia({
|
|
133
|
+
audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true }
|
|
134
|
+
});
|
|
135
|
+
const mimeType = pickMimeType();
|
|
136
|
+
recorder = new MediaRecorder(stream, mimeType ? { mimeType } : undefined);
|
|
137
|
+
if (!sendJson({ type: 'voice-start', mimeType: recorder.mimeType || mimeType })) {
|
|
138
|
+
cleanupRecording();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
serverVoiceStarted = true;
|
|
142
|
+
pendingChunks = Promise.resolve();
|
|
143
|
+
recorder.addEventListener('dataavailable', (event) => {
|
|
144
|
+
pendingChunks = pendingChunks.then(() => sendBlob(event.data)).catch((err) => {
|
|
145
|
+
T1.toast(`Voice chunk failed: ${err.message || err}`, 'error');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
recorder.addEventListener('stop', async () => {
|
|
149
|
+
setState('transcribing');
|
|
150
|
+
await pendingChunks;
|
|
151
|
+
sendJson({ type: 'voice-end' });
|
|
152
|
+
cleanupRecording();
|
|
153
|
+
}, { once: true });
|
|
154
|
+
recorder.start(500);
|
|
155
|
+
setState('recording');
|
|
156
|
+
stopTimer = setTimeout(() => stop(), MAX_RECORDING_MS);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
if (serverVoiceStarted) sendJson({ type: 'voice-end' });
|
|
159
|
+
cleanupRecording();
|
|
160
|
+
setState('idle');
|
|
161
|
+
T1.toast(`Microphone unavailable: ${err.message || err}`, 'error');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function stop() {
|
|
166
|
+
if (state !== 'recording' || !recorder) return;
|
|
167
|
+
if (stopTimer) {
|
|
168
|
+
clearTimeout(stopTimer);
|
|
169
|
+
stopTimer = 0;
|
|
170
|
+
}
|
|
171
|
+
try { recorder.stop(); }
|
|
172
|
+
catch (err) {
|
|
173
|
+
cleanupRecording();
|
|
174
|
+
setState('idle');
|
|
175
|
+
T1.toast(`Voice stop failed: ${err.message || err}`, 'error');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function toggle() {
|
|
180
|
+
if (state === 'recording') stop();
|
|
181
|
+
else if (state === 'idle') start();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function registerButton(button) {
|
|
185
|
+
if (!button || buttons.has(button)) return button;
|
|
186
|
+
buttons.add(button);
|
|
187
|
+
button.addEventListener('click', toggle);
|
|
188
|
+
setState(state);
|
|
189
|
+
return button;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const toolbar = T1.ui.toolbar();
|
|
193
|
+
if (toolbar) {
|
|
194
|
+
const button = T1.ui.makeButton('Voice', 'Voice input');
|
|
195
|
+
button.classList.add('t1voice-button');
|
|
196
|
+
button.setAttribute('aria-pressed', 'false');
|
|
197
|
+
toolbar.appendChild(registerButton(button));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function ensureKeybarButtons() {
|
|
201
|
+
for (const button of Array.from(buttons)) {
|
|
202
|
+
if (!button.isConnected) buttons.delete(button);
|
|
203
|
+
}
|
|
204
|
+
const device = T1.device;
|
|
205
|
+
const ids = device === 'iphone' ? ['keybarIphone'] : device === 'ipad' ? ['keybarIpad'] : [];
|
|
206
|
+
for (const id of ids) {
|
|
207
|
+
const bar = document.getElementById(id);
|
|
208
|
+
if (!bar || bar.querySelector('.t1voice-key')) continue;
|
|
209
|
+
const group = document.createElement('div');
|
|
210
|
+
group.className = 'kb-group t1voice-group';
|
|
211
|
+
const button = document.createElement('button');
|
|
212
|
+
button.type = 'button';
|
|
213
|
+
button.className = 'kb-key t1voice-key';
|
|
214
|
+
group.appendChild(registerButton(button));
|
|
215
|
+
bar.appendChild(group);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
ensureKeybarButtons();
|
|
219
|
+
window.addEventListener('orientationchange', () => setTimeout(ensureKeybarButtons, 250));
|
|
220
|
+
|
|
221
|
+
window.addEventListener('t1:voice-transcript', (event) => {
|
|
222
|
+
const text = normalizeTranscript(event.detail?.text);
|
|
223
|
+
setState('idle');
|
|
224
|
+
if (!text) {
|
|
225
|
+
T1.toast('No speech detected', 'warn');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (DANGEROUS_COMMAND_RE.test(text) && !confirm(`Insert potentially dangerous command?\n\n${text}`)) {
|
|
229
|
+
T1.toast('Voice command discarded', 'warn');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
T1.sendData(text);
|
|
233
|
+
T1.toast('Voice transcript inserted');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
window.addEventListener('t1:voice-error', (event) => {
|
|
237
|
+
setState('idle');
|
|
238
|
+
const code = event.detail?.code || 'VOICE_ERROR';
|
|
239
|
+
const message = event.detail?.message || 'Voice input failed';
|
|
240
|
+
T1.toast(`${code}: ${message}`, 'error');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
window.__terminalOneVoiceInput = { start, stop, toggle, supported, normalizeTranscript };
|
|
244
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wake lock + fullscreen — keep the screen awake during long-running commands
|
|
3
|
+
* and toggle fullscreen for more terminal space. Both APIs are optional on
|
|
4
|
+
* mobile WebKit, so each control disables itself or toasts when unsupported.
|
|
5
|
+
*/
|
|
6
|
+
export function init(T1) {
|
|
7
|
+
const tb = T1.ui.toolbar();
|
|
8
|
+
if (!tb) return;
|
|
9
|
+
|
|
10
|
+
// ── Screen Wake Lock ──
|
|
11
|
+
let sentinel = null, wakeEnabled = false;
|
|
12
|
+
|
|
13
|
+
const wake = T1.ui.makeButton('Wake', 'Keep screen awake', async () => {
|
|
14
|
+
if (wakeEnabled) await disableWake();
|
|
15
|
+
else await enableWake();
|
|
16
|
+
});
|
|
17
|
+
if (!('wakeLock' in navigator)) {
|
|
18
|
+
wake.disabled = true;
|
|
19
|
+
wake.title = 'Wake lock not supported';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function acquire() {
|
|
23
|
+
sentinel = await navigator.wakeLock.request('screen');
|
|
24
|
+
wake.classList.add('active');
|
|
25
|
+
sentinel.addEventListener('release', () => { wake.classList.remove('active'); });
|
|
26
|
+
}
|
|
27
|
+
async function enableWake() {
|
|
28
|
+
try { await acquire(); wakeEnabled = true; }
|
|
29
|
+
catch (_) { T1.toast('Could not acquire wake lock', 'warn'); }
|
|
30
|
+
}
|
|
31
|
+
async function disableWake() {
|
|
32
|
+
wakeEnabled = false;
|
|
33
|
+
wake.classList.remove('active');
|
|
34
|
+
try { if (sentinel) await sentinel.release(); } catch (_) {}
|
|
35
|
+
sentinel = null;
|
|
36
|
+
}
|
|
37
|
+
// Wake locks are auto-released when the tab is hidden; re-acquire on return.
|
|
38
|
+
document.addEventListener('visibilitychange', async () => {
|
|
39
|
+
if (document.visibilityState === 'visible' && wakeEnabled && !sentinel) {
|
|
40
|
+
try { await acquire(); } catch (_) {}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ── Fullscreen ──
|
|
45
|
+
const fs = T1.ui.makeButton('Fullscreen', 'Toggle fullscreen', async () => {
|
|
46
|
+
try {
|
|
47
|
+
if (document.fullscreenElement) {
|
|
48
|
+
if (document.exitFullscreen) await document.exitFullscreen();
|
|
49
|
+
} else {
|
|
50
|
+
const target = T1.ui.appShell() || document.documentElement;
|
|
51
|
+
if (target.requestFullscreen) await target.requestFullscreen();
|
|
52
|
+
else T1.toast('Fullscreen not supported', 'warn');
|
|
53
|
+
}
|
|
54
|
+
} catch (_) { T1.toast('Fullscreen blocked', 'warn'); }
|
|
55
|
+
});
|
|
56
|
+
const fsTarget = T1.ui.appShell() || document.documentElement;
|
|
57
|
+
if (!fsTarget.requestFullscreen && !document.exitFullscreen) {
|
|
58
|
+
fs.disabled = true;
|
|
59
|
+
fs.title = 'Fullscreen not supported';
|
|
60
|
+
}
|
|
61
|
+
document.addEventListener('fullscreenchange', () => {
|
|
62
|
+
fs.classList.toggle('active', !!document.fullscreenElement);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
tb.appendChild(wake);
|
|
66
|
+
tb.appendChild(fs);
|
|
67
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Window title reflects shell cwd and the running version.
|
|
3
|
+
*
|
|
4
|
+
* The server sends cwd via the ready/footer metadata. We update document.title
|
|
5
|
+
* to "Townmouse <version> — ~/path" whenever either changes.
|
|
6
|
+
*/
|
|
7
|
+
import { currentVersion } from './app-version.mjs';
|
|
8
|
+
|
|
9
|
+
export function init(T1) {
|
|
10
|
+
function basename(path) {
|
|
11
|
+
if (!path) return '';
|
|
12
|
+
// Normalize to a user-friendly tilde path if under $HOME.
|
|
13
|
+
const home = (typeof process !== 'undefined' && process.env?.HOME) || '';
|
|
14
|
+
let p = path.replace(/\/$/, '') || '/';
|
|
15
|
+
if (home && p.startsWith(home)) p = '~' + p.slice(home.length);
|
|
16
|
+
// Strip the trailing segment from the footer text if it includes command info.
|
|
17
|
+
return p.split('/').pop() || p;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseCwd(text) {
|
|
21
|
+
if (!text) return null;
|
|
22
|
+
// Footer formats: "command · cwd" or "Resumed · cwd" or "Process exited · ..."
|
|
23
|
+
const parts = text.split('·').map((s) => s.trim());
|
|
24
|
+
if (parts.length >= 2 && !text.includes('exited')) return parts[parts.length - 1];
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function update() {
|
|
29
|
+
const footer = document.getElementById('footerMeta')?.textContent || '';
|
|
30
|
+
const cwd = parseCwd(footer);
|
|
31
|
+
// The version rides in the title, so the window itself says what is running.
|
|
32
|
+
const version = currentVersion();
|
|
33
|
+
const name = version ? `Townmouse ${version}` : 'Townmouse';
|
|
34
|
+
if (cwd) document.title = `${name} — ${basename(cwd)}`;
|
|
35
|
+
else if (version) document.title = name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const footerEl = document.getElementById('footerMeta');
|
|
39
|
+
if (footerEl) {
|
|
40
|
+
const mo = new MutationObserver(update);
|
|
41
|
+
mo.observe(footerEl, { childList: true });
|
|
42
|
+
}
|
|
43
|
+
document.addEventListener('townmouse:version', update);
|
|
44
|
+
update();
|
|
45
|
+
|
|
46
|
+
window.__terminalOneWindowTitle = { update, parseCwd, basename };
|
|
47
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zoom / pinch-to-zoom font size for TerminalOne.
|
|
3
|
+
*
|
|
4
|
+
* ShellFish parity: pinch to zoom the terminal text.
|
|
5
|
+
*/
|
|
6
|
+
const LS_ZOOM = 'terminalone.fontSize';
|
|
7
|
+
|
|
8
|
+
function responsiveDefault() {
|
|
9
|
+
const width = window.innerWidth;
|
|
10
|
+
if (width <= 430) return 11;
|
|
11
|
+
if (width <= 820) return 12;
|
|
12
|
+
return 14;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function init(T1) {
|
|
16
|
+
const stored = T1.storage.get(LS_ZOOM, null);
|
|
17
|
+
const hasStored = stored !== null && stored !== undefined && stored !== '';
|
|
18
|
+
let current = hasStored ? (parseInt(stored, 10) || responsiveDefault()) : responsiveDefault();
|
|
19
|
+
|
|
20
|
+
function apply(size, persist = false) {
|
|
21
|
+
current = Math.max(8, Math.min(32, size));
|
|
22
|
+
const term = T1.term;
|
|
23
|
+
if (term) {
|
|
24
|
+
term.options.fontSize = current;
|
|
25
|
+
T1.fit();
|
|
26
|
+
}
|
|
27
|
+
if (persist) T1.storage.set(LS_ZOOM, String(current));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Listen to keyboard-shortcuts action events.
|
|
31
|
+
window.addEventListener('t1:action', (e) => {
|
|
32
|
+
const { action } = e.detail || {};
|
|
33
|
+
if (action === 'font-increase') { apply(current + 1, true); T1.toast(`Font size ${current}px`); }
|
|
34
|
+
if (action === 'font-decrease') { apply(current - 1, true); T1.toast(`Font size ${current}px`); }
|
|
35
|
+
if (action === 'font-reset') { T1.storage.del(LS_ZOOM); apply(responsiveDefault()); T1.toast('Font size reset'); }
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// With no explicit choice, follow the viewport across rotations and window
|
|
39
|
+
// resizes so a phone keeps readable columns instead of 14px at 393px.
|
|
40
|
+
window.addEventListener('resize', () => {
|
|
41
|
+
if (!T1.storage.get(LS_ZOOM, null)) apply(responsiveDefault());
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Pinch-to-zoom on the terminal element.
|
|
45
|
+
T1.onTermReady((term) => {
|
|
46
|
+
const el = term.element;
|
|
47
|
+
if (!el) return;
|
|
48
|
+
let startDist = 0;
|
|
49
|
+
let startSize = current;
|
|
50
|
+
function onTouchStart(e) {
|
|
51
|
+
if (e.touches.length === 2) {
|
|
52
|
+
startDist = Math.hypot(
|
|
53
|
+
e.touches[0].clientX - e.touches[1].clientX,
|
|
54
|
+
e.touches[0].clientY - e.touches[1].clientY
|
|
55
|
+
);
|
|
56
|
+
startSize = current;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function onTouchMove(e) {
|
|
60
|
+
if (e.touches.length === 2) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
const dist = Math.hypot(
|
|
63
|
+
e.touches[0].clientX - e.touches[1].clientX,
|
|
64
|
+
e.touches[0].clientY - e.touches[1].clientY
|
|
65
|
+
);
|
|
66
|
+
const ratio = dist / (startDist || 1);
|
|
67
|
+
apply(Math.round(startSize * ratio), true);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
el.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
71
|
+
el.addEventListener('touchmove', onTouchMove, { passive: false });
|
|
72
|
+
return () => {
|
|
73
|
+
el.removeEventListener('touchstart', onTouchStart);
|
|
74
|
+
el.removeEventListener('touchmove', onTouchMove);
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Make sure the initial persisted zoom is applied after term is ready.
|
|
79
|
+
T1.onTermReady(() => apply(current));
|
|
80
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|