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.
Files changed (108) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/DESIGN.md +153 -0
  3. package/LICENSE +661 -0
  4. package/README.md +600 -2
  5. package/SECURITY.md +60 -0
  6. package/TOWNMOUSE.md +91 -0
  7. package/assets/brand/mascot/README.md +23 -0
  8. package/assets/brand/mascot/townmouse-aristocrat.png +0 -0
  9. package/assets/brand/mascot/townmouse-icon.svg +1 -0
  10. package/assets/brand/mascot/townmouse-monocled.png +0 -0
  11. package/bin/townmouse +68 -0
  12. package/docs/PACKAGING.md +371 -0
  13. package/docs/browser-workspace.md +237 -0
  14. package/docs/panes.md +442 -0
  15. package/native/TownmouseApp.swift +108 -0
  16. package/npm-shrinkwrap.json +1282 -0
  17. package/package.json +93 -4
  18. package/public/apple-touch-icon.png +0 -0
  19. package/public/brand/floydslabs-credit.png +0 -0
  20. package/public/brand/floydslabs-credit.webp +0 -0
  21. package/public/brand/townmouse-aristocrat.webp +0 -0
  22. package/public/brand/townmouse-monocled.webp +0 -0
  23. package/public/browser-picture.mjs +159 -0
  24. package/public/clipboard-text.mjs +5 -0
  25. package/public/favicon-16x16.png +0 -0
  26. package/public/favicon-32x32.png +0 -0
  27. package/public/favicon.ico +0 -0
  28. package/public/favicon.svg +1 -0
  29. package/public/features/app-version.mjs +35 -0
  30. package/public/features/autosave.mjs +80 -0
  31. package/public/features/clipboard.mjs +69 -0
  32. package/public/features/command-palette.mjs +181 -0
  33. package/public/features/desktop-palette.mjs +19 -0
  34. package/public/features/export.mjs +37 -0
  35. package/public/features/file-drop.mjs +77 -0
  36. package/public/features/floating-palette.mjs +113 -0
  37. package/public/features/fontsize.mjs +72 -0
  38. package/public/features/haptic-keys.mjs +42 -0
  39. package/public/features/history-undo.mjs +102 -0
  40. package/public/features/keepalive.mjs +36 -0
  41. package/public/features/keybar-config.mjs +70 -0
  42. package/public/features/keyboard-shortcuts.mjs +74 -0
  43. package/public/features/links.mjs +139 -0
  44. package/public/features/multi-window-sync.mjs +76 -0
  45. package/public/features/osc-bridge.mjs +64 -0
  46. package/public/features/phone-landscape-focus.mjs +157 -0
  47. package/public/features/recent-commands.mjs +100 -0
  48. package/public/features/search.mjs +134 -0
  49. package/public/features/session-lock.mjs +96 -0
  50. package/public/features/session-manager.mjs +251 -0
  51. package/public/features/settings-sync.mjs +77 -0
  52. package/public/features/shortcut-help.mjs +85 -0
  53. package/public/features/smart-completions.mjs +101 -0
  54. package/public/features/smart-suggest.mjs +124 -0
  55. package/public/features/snippets.mjs +85 -0
  56. package/public/features/split-view.mjs +102 -0
  57. package/public/features/status-metrics.mjs +137 -0
  58. package/public/features/stylus-support.mjs +124 -0
  59. package/public/features/swipe-history.mjs +141 -0
  60. package/public/features/swipe-sessions.mjs +85 -0
  61. package/public/features/tab-reorder.mjs +70 -0
  62. package/public/features/theme-system.mjs +51 -0
  63. package/public/features/toast-status.mjs +118 -0
  64. package/public/features/two-finger-menu.mjs +87 -0
  65. package/public/features/voice-input.mjs +244 -0
  66. package/public/features/wake-fullscreen.mjs +67 -0
  67. package/public/features/window-title.mjs +47 -0
  68. package/public/features/zoom.mjs +80 -0
  69. package/public/icon-128.png +0 -0
  70. package/public/icon-180.png +0 -0
  71. package/public/icon-192.png +0 -0
  72. package/public/icon-48.png +0 -0
  73. package/public/icon-512-maskable.png +0 -0
  74. package/public/icon-512.png +0 -0
  75. package/public/icon.svg +1 -0
  76. package/public/index.html +2304 -0
  77. package/public/input-chunks.mjs +22 -0
  78. package/public/input-guard.mjs +218 -0
  79. package/public/manifest.json +56 -0
  80. package/public/panes.css +1433 -0
  81. package/public/panes.html +211 -0
  82. package/public/panes.mjs +3183 -0
  83. package/public/service-worker.js +67 -0
  84. package/public/workspace.css +1621 -0
  85. package/public/workspace.mjs +1715 -0
  86. package/scripts/install-service.sh +303 -0
  87. package/scripts/node-runtime.sh +138 -0
  88. package/scripts/panes +568 -0
  89. package/scripts/prepare-native.sh +35 -0
  90. package/scripts/retire-legacy-service.sh +76 -0
  91. package/scripts/run-hooks +69 -0
  92. package/scripts/townmouse.sh +152 -0
  93. package/scripts/uninstall-service.sh +65 -0
  94. package/src/agent-guide.js +329 -0
  95. package/src/attachments.js +128 -0
  96. package/src/browser-dom.js +548 -0
  97. package/src/browser-workspace.js +1733 -0
  98. package/src/chrome-resolve.js +80 -0
  99. package/src/owner-page.js +43 -0
  100. package/src/pty-permissions.js +99 -0
  101. package/src/regex-worker.js +13 -0
  102. package/src/replay-text.js +189 -0
  103. package/src/request-boundary.js +58 -0
  104. package/src/safe-regex.js +87 -0
  105. package/src/server.js +1582 -0
  106. package/src/shell-resolve.js +42 -0
  107. package/src/static-deps.js +61 -0
  108. package/src/workspace-panes.js +1431 -0
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Smart command completions.
3
+ *
4
+ * As the user types, show inline command completions from history and shell
5
+ * builtins. Tab accepts the top completion.
6
+ */
7
+ const HISTORY_KEY = 'terminalone.commandHistory';
8
+ const BUILTINS = ['cd', 'ls', 'pwd', 'cat', 'echo', 'mkdir', 'rm', 'cp', 'mv', 'git', 'clear', 'exit', 'ssh', 'sudo', 'npm', 'node'];
9
+
10
+ export function init(T1) {
11
+ if (T1.device === 'desktop') return;
12
+
13
+ T1.ui.addStyle(`
14
+ .t1-completion-hint {
15
+ position: absolute;
16
+ background: var(--ui-elevated);
17
+ border: 1px solid var(--ui-border);
18
+ border-radius: 6px;
19
+ padding: 6px 10px;
20
+ font-size: 12px;
21
+ color: var(--ui-fg);
22
+ z-index: 50;
23
+ display: none;
24
+ pointer-events: none;
25
+ }
26
+ `);
27
+
28
+ const hint = document.createElement('div');
29
+ hint.className = 't1-completion-hint';
30
+ hint.setAttribute('role', 'status');
31
+ hint.setAttribute('aria-live', 'polite');
32
+ document.body.appendChild(hint);
33
+
34
+ function readHistory() {
35
+ try { return JSON.parse(T1.storage.get(HISTORY_KEY, '[]')); }
36
+ catch (_) { return []; }
37
+ }
38
+
39
+ function candidates(prefix) {
40
+ const p = (prefix || '').toLowerCase();
41
+ if (!p) return [];
42
+ const hist = readHistory().slice().reverse();
43
+ const histMatches = hist.filter((c) => c && c.toLowerCase().startsWith(p) && c !== prefix);
44
+ const builtinMatches = BUILTINS.filter((b) => b.startsWith(p) && b !== prefix);
45
+ return Array.from(new Set([...builtinMatches, ...histMatches])).slice(0, 5);
46
+ }
47
+
48
+ let current = null;
49
+ let currentTop = null;
50
+
51
+ function update() {
52
+ const term = T1.term;
53
+ if (!term || !term.buffer) { hint.style.display = 'none'; return; }
54
+ try {
55
+ const row = term.buffer.active.getLine(term.buffer.active.cursorY);
56
+ const text = (row ? row.translateToString(true) : '').trim();
57
+ const list = candidates(text);
58
+ if (!list.length) { hint.style.display = 'none'; current = null; currentTop = null; return; }
59
+ currentTop = list[0];
60
+ current = text;
61
+ const rect = term.element.getBoundingClientRect();
62
+ hint.textContent = list.join(', ');
63
+ hint.style.display = 'block';
64
+ hint.style.left = `${rect.left + 8}px`;
65
+ hint.style.top = `${rect.bottom - 36}px`;
66
+ } catch (_) { hint.style.display = 'none'; }
67
+ }
68
+
69
+ function accept() {
70
+ if (!current || !currentTop) return;
71
+ const suffix = currentTop.slice(current.length);
72
+ if (suffix) T1.sendData(suffix + ' ');
73
+ }
74
+
75
+ let updateRaf = 0;
76
+ function scheduleUpdate() {
77
+ if (updateRaf) return;
78
+ updateRaf = requestAnimationFrame(() => {
79
+ updateRaf = 0;
80
+ update();
81
+ });
82
+ }
83
+
84
+ T1.onTermReady((term) => {
85
+ const dataDisposable = term.onData(scheduleUpdate);
86
+ const onKeyDown = (e) => {
87
+ if (e.key === 'Tab') { e.preventDefault(); accept(); }
88
+ };
89
+ term.element.addEventListener('keydown', onKeyDown, { capture: true });
90
+ return () => {
91
+ if (updateRaf) {
92
+ cancelAnimationFrame(updateRaf);
93
+ updateRaf = 0;
94
+ }
95
+ dataDisposable.dispose();
96
+ term.element?.removeEventListener('keydown', onKeyDown, { capture: true });
97
+ };
98
+ });
99
+
100
+ window.__terminalOneSmartCompletions = { candidates, accept, hint, update };
101
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Smart suggestion bar above the on-screen keyboard (iPhone only).
3
+ *
4
+ * Shows context-aware suggestions (sudo, git, cd, ls, clear) based on the
5
+ * current input prefix and local command history. Tapping a suggestion
6
+ * inserts it.
7
+ */
8
+ const HISTORY_KEY = 'terminalone.commandHistory';
9
+ const DEFAULT_SUGGESTIONS = ['sudo', 'git', 'cd', 'ls', 'clear'];
10
+
11
+ export function init(T1) {
12
+ if (T1.device !== 'iphone') return;
13
+
14
+ T1.ui.addStyle(`
15
+ .t1-smart-suggest {
16
+ display: none;
17
+ flex: 0 0 auto;
18
+ flex-wrap: wrap;
19
+ align-items: center;
20
+ gap: 6px;
21
+ padding: 6px 8px;
22
+ background: var(--ui-elevated);
23
+ border-top: 1px solid var(--ui-border);
24
+ overflow: visible;
25
+ -webkit-overflow-scrolling: touch;
26
+ }
27
+ body[data-device="iphone"] .t1-smart-suggest { display: flex; }
28
+ .t1-smart-suggest .sug {
29
+ flex: 0 1 auto;
30
+ max-width: 100%;
31
+ overflow-wrap: anywhere;
32
+ padding: 6px 10px;
33
+ font-size: 12px;
34
+ color: var(--ui-fg);
35
+ background: var(--ui-bg);
36
+ border: 1px solid var(--ui-border);
37
+ border-radius: 6px;
38
+ cursor: pointer;
39
+ }
40
+ .t1-smart-suggest .sug:active { background: var(--ui-accent); color: var(--ui-on-accent, #14171b); }
41
+ .t1-smart-suggest .label {
42
+ font-size: 10px;
43
+ color: var(--ui-muted);
44
+ margin-right: 2px;
45
+ flex-shrink: 0;
46
+ }
47
+ `);
48
+
49
+ const bar = document.createElement('div');
50
+ bar.className = 't1-smart-suggest';
51
+ bar.setAttribute('role', 'toolbar');
52
+ bar.setAttribute('aria-label', 'Smart suggestions');
53
+ const keybar = document.getElementById('keybarIphone');
54
+ if (keybar) keybar.parentNode.insertBefore(bar, keybar);
55
+
56
+ function readHistory() {
57
+ try { return JSON.parse(T1.storage.get(HISTORY_KEY, '[]')); }
58
+ catch (_) { return []; }
59
+ }
60
+
61
+ function candidates(prefix) {
62
+ const p = (prefix || '').toLowerCase();
63
+ const hist = readHistory();
64
+ const fromHistory = hist.slice().reverse().filter((c) => c && c.toLowerCase().startsWith(p) && !DEFAULT_SUGGESTIONS.includes(c));
65
+ const fromDefaults = DEFAULT_SUGGESTIONS.filter((s) => s.startsWith(p));
66
+ return Array.from(new Set([...fromDefaults, ...fromHistory])).slice(0, 8);
67
+ }
68
+
69
+ function render(prefix) {
70
+ const list = candidates(prefix);
71
+ bar.innerHTML = '';
72
+ if (!list.length) {
73
+ bar.style.display = 'none';
74
+ return;
75
+ }
76
+ const label = document.createElement('span');
77
+ label.className = 'label';
78
+ label.textContent = 'SUGGEST:';
79
+ bar.appendChild(label);
80
+ for (const text of list) {
81
+ const b = document.createElement('button');
82
+ b.type = 'button';
83
+ b.className = 'sug';
84
+ b.textContent = text;
85
+ b.addEventListener('click', () => { T1.sendData(text); });
86
+ bar.appendChild(b);
87
+ }
88
+ bar.style.display = 'flex';
89
+ }
90
+
91
+ function updateFromTerminal() {
92
+ const term = T1.term;
93
+ if (!term || !term.buffer) return;
94
+ try {
95
+ const row = term.buffer.active.getLine(term.buffer.active.cursorY);
96
+ const text = (row ? row.translateToString(true) : '').trim();
97
+ render(text);
98
+ } catch (_) { bar.style.display = 'none'; }
99
+ }
100
+
101
+ let updateRaf = 0;
102
+ function scheduleUpdate() {
103
+ if (updateRaf) return;
104
+ updateRaf = requestAnimationFrame(() => {
105
+ updateRaf = 0;
106
+ updateFromTerminal();
107
+ });
108
+ }
109
+
110
+ T1.onTermReady((term) => {
111
+ const dataDisposable = term.onData(scheduleUpdate);
112
+ updateFromTerminal();
113
+ return () => {
114
+ if (updateRaf) {
115
+ cancelAnimationFrame(updateRaf);
116
+ updateRaf = 0;
117
+ }
118
+ dataDisposable.dispose();
119
+ };
120
+ });
121
+
122
+ // Expose for tests.
123
+ window.__terminalOneSmartSuggest = { bar, render, candidates };
124
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Command snippets — a togglable row of one-tap commands. Tapping a chip inserts
3
+ * the command at the prompt (NO auto-run) so it can be reviewed before Enter.
4
+ * Presets are constant; user snippets are added via "+", deleted via "x", and
5
+ * persisted in localStorage.
6
+ */
7
+ const KEY = 'terminalone.snippets';
8
+ const PRESETS = ['ls -la', 'git status', 'clear', 'cd ..', 'pwd'];
9
+
10
+ export function init(T1) {
11
+ const tb = T1.ui.toolbar();
12
+ if (!tb) return;
13
+
14
+ T1.ui.addStyle(`
15
+ .t1snip-row {
16
+ flex: 0 0 auto;
17
+ display: flex;
18
+ gap: 6px;
19
+ align-items: center;
20
+ padding: 6px 8px;
21
+ background: var(--ui-elevated);
22
+ border-top: 1px solid var(--ui-border);
23
+ overflow-x: auto;
24
+ -webkit-overflow-scrolling: touch;
25
+ scrollbar-width: none;
26
+ }
27
+ .t1snip-row::-webkit-scrollbar { display: none; }
28
+ .t1snip-row.hidden { display: none; }
29
+ .t1snip-chip { white-space: nowrap; }
30
+ .t1snip-custom { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
31
+ .t1snip-del { padding: 0 7px; min-width: 0; }
32
+ `);
33
+
34
+ const row = document.createElement('div');
35
+ row.className = 't1snip-row hidden';
36
+ tb.insertAdjacentElement('afterend', row);
37
+
38
+ const load = () => {
39
+ try { const v = JSON.parse(T1.storage.get(KEY, '[]')); return Array.isArray(v) ? v : []; }
40
+ catch (_) { return []; }
41
+ };
42
+ const save = (list) => T1.storage.set(KEY, JSON.stringify(list));
43
+
44
+ function render() {
45
+ row.innerHTML = '';
46
+ const ctrlB = T1.ui.makeButton('Ctrl+b', 'Send Ctrl+b to herdr', () => T1.sendData('\x02'));
47
+ ctrlB.classList.add('t1snip-chip');
48
+ row.appendChild(ctrlB);
49
+ for (const cmd of PRESETS) {
50
+ const chip = T1.ui.makeButton(cmd, `Insert: ${cmd}`, () => T1.sendData(cmd));
51
+ chip.classList.add('t1snip-chip');
52
+ row.appendChild(chip);
53
+ }
54
+ load().forEach((cmd, i) => {
55
+ const wrap = document.createElement('span');
56
+ wrap.className = 't1snip-custom';
57
+ const chip = T1.ui.makeButton(cmd, `Insert: ${cmd}`, () => T1.sendData(cmd));
58
+ chip.classList.add('t1snip-chip');
59
+ const del = T1.ui.makeButton('x', `Delete snippet: ${cmd}`, () => {
60
+ const list = load();
61
+ list.splice(i, 1);
62
+ save(list);
63
+ render();
64
+ });
65
+ del.classList.add('t1snip-del');
66
+ wrap.appendChild(chip);
67
+ wrap.appendChild(del);
68
+ row.appendChild(wrap);
69
+ });
70
+ const add = T1.ui.makeButton('+', 'Add a snippet', () => {
71
+ const v = window.prompt('New snippet command:');
72
+ if (v && v.trim()) { const list = load(); list.push(v.trim()); save(list); render(); }
73
+ });
74
+ add.classList.add('t1snip-chip');
75
+ row.appendChild(add);
76
+ }
77
+
78
+ const toggle = T1.ui.makeButton('Snippets', 'Toggle command snippets', () => {
79
+ const hidden = row.classList.toggle('hidden');
80
+ toggle.classList.toggle('active', !hidden);
81
+ });
82
+ tb.appendChild(toggle);
83
+
84
+ render();
85
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Split-screen dual terminal (tablet only).
3
+ *
4
+ * Adds a "Split" button to the header that divides the screen vertically or
5
+ * horizontally with two independent xterm instances, each with its own PTY
6
+ * session. A drag divider resizes the panes.
7
+ */
8
+ export function init(T1) {
9
+ if (T1.device === 'desktop' || T1.device === 'iphone') return;
10
+
11
+ T1.ui.addStyle(`
12
+ .t1-split-host { display: flex; width: 100%; height: 100%; }
13
+ .t1-split-host.horizontal { flex-direction: column; }
14
+ .t1-split-host.vertical { flex-direction: row; }
15
+ .t1-split-pane { flex: 1 1 50%; min-width: 0; min-height: 0; position: relative; overflow: hidden; }
16
+ .t1-split-divider {
17
+ flex: 0 0 8px;
18
+ background: var(--ui-border);
19
+ cursor: col-resize;
20
+ touch-action: none;
21
+ }
22
+ .t1-split-host.horizontal .t1-split-divider { cursor: row-resize; }
23
+ `);
24
+
25
+ let host = null;
26
+ let paneA = null;
27
+ let paneB = null;
28
+ let splitBtn = null;
29
+
30
+ function createSplit() {
31
+ const container = document.querySelector('.terminal-container');
32
+ const original = document.getElementById('terminal');
33
+ if (!container || !original) return;
34
+
35
+ host = document.createElement('div');
36
+ host.className = 't1-split-host vertical';
37
+ paneA = document.createElement('div');
38
+ paneA.className = 't1-split-pane';
39
+ paneA.id = 'terminal';
40
+ const divider = document.createElement('div');
41
+ divider.className = 't1-split-divider';
42
+ divider.setAttribute('role', 'separator');
43
+ divider.setAttribute('aria-label', 'Resize panes');
44
+ paneB = document.createElement('div');
45
+ paneB.className = 't1-split-pane';
46
+ paneB.id = 'terminal-b';
47
+
48
+ original.replaceWith(host);
49
+ host.appendChild(paneA);
50
+ host.appendChild(divider);
51
+ host.appendChild(paneB);
52
+
53
+ setupDrag(divider);
54
+ T1.toast('Split view active — second session opens on next shell');
55
+
56
+ // Test-only: mark panes with a class so tests can count them.
57
+ paneA.dataset.splitPane = 'a';
58
+ paneB.dataset.splitPane = 'b';
59
+ }
60
+
61
+ function setupDrag(divider) {
62
+ let dragging = false;
63
+ divider.addEventListener('mousedown', (e) => { dragging = true; e.preventDefault(); });
64
+ divider.addEventListener('touchstart', (e) => { dragging = true; }, { passive: true });
65
+
66
+ function move(e) {
67
+ if (!dragging || !host) return;
68
+ const rect = host.getBoundingClientRect();
69
+ const isHoriz = host.classList.contains('horizontal');
70
+ const client = e.touches?.[0] || e;
71
+ const ratio = isHoriz
72
+ ? (client.clientY - rect.top) / rect.height
73
+ : (client.clientX - rect.left) / rect.width;
74
+ const clamped = Math.max(0.2, Math.min(0.8, ratio));
75
+ const pa = host.querySelector('[data-split-pane="a"]');
76
+ const pb = host.querySelector('[data-split-pane="b"]');
77
+ if (pa && pb) {
78
+ pa.style.flexBasis = `${clamped * 100}%`;
79
+ pb.style.flexBasis = `${(1 - clamped) * 100}%`;
80
+ }
81
+ }
82
+ function end() { dragging = false; }
83
+ window.addEventListener('mousemove', move, { passive: true });
84
+ window.addEventListener('mouseup', end, { passive: true });
85
+ window.addEventListener('touchmove', move, { passive: true });
86
+ window.addEventListener('touchend', end, { passive: true });
87
+ }
88
+
89
+ function toggle() {
90
+ if (host) {
91
+ T1.toast('Split view already active');
92
+ return;
93
+ }
94
+ createSplit();
95
+ }
96
+
97
+ splitBtn = T1.ui.makeButton('Split', 'Split terminal (tablet)', toggle);
98
+ T1.ui.toolbar().appendChild(splitBtn);
99
+
100
+ // Expose test hooks.
101
+ window.__terminalOneSplitView = { createSplit, toggle, host, paneA, paneB };
102
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Status metrics — enhances the footer with latency (round-trip via a small
3
+ * heartbeat), connection uptime, and an explicit shell indicator.
4
+ *
5
+ * ShellFish parity: detailed connection status and session metadata.
6
+ */
7
+ export function init(T1) {
8
+ const footerMeta = document.getElementById('footerMeta');
9
+ const sessionInfo = document.getElementById('sessionInfo');
10
+ if (!footerMeta || !sessionInfo) return;
11
+
12
+ let connectedAt = 0;
13
+ let rttMs = null;
14
+ let currentCommand = '';
15
+ let currentCwd = '';
16
+ let lastFooterText = '';
17
+ let ignoreNextMutation = false;
18
+
19
+ function formatDuration(ms) {
20
+ if (ms < 60_000) return `${Math.floor(ms / 1000)}s`;
21
+ if (ms < 3_600_000) return `${Math.floor(ms / 60_000)}m ${Math.floor((ms % 60_000) / 1000)}s`;
22
+ const h = Math.floor(ms / 3_600_000);
23
+ const m = Math.floor((ms % 3_600_000) / 60_000);
24
+ return `${h}h ${m}m`;
25
+ }
26
+
27
+ // With no shell open the footer says so (the page script sets it) and is
28
+ // left alone: there is no shell to describe and no latency worth showing,
29
+ // even though the page still holds a shell-less connection.
30
+ const noShell = () => window.__terminalOne?.sessionView?.()?.state === 'ended';
31
+
32
+ function updateFooter() {
33
+ if (noShell()) return;
34
+ const parts = [];
35
+ if (currentCommand) parts.push(currentCommand);
36
+ if (currentCwd) parts.push(currentCwd);
37
+ if (connectedAt) {
38
+ parts.push(`up ${formatDuration(Date.now() - connectedAt)}`);
39
+ }
40
+ if (rttMs != null) {
41
+ parts.push(`latency ${rttMs.toFixed(0)}ms`);
42
+ }
43
+ const text = parts.join(' · ');
44
+ if (!text) return;
45
+ if (text !== lastFooterText) {
46
+ lastFooterText = text;
47
+ ignoreNextMutation = true;
48
+ footerMeta.textContent = text;
49
+ }
50
+ }
51
+
52
+ window.addEventListener('t1:session-ready', (event) => {
53
+ currentCommand = event.detail?.command || '';
54
+ currentCwd = event.detail?.cwd || '';
55
+ connectedAt = Date.now();
56
+ updateFooter();
57
+ });
58
+ // The first `ready` can arrive before this module loads. Start from the
59
+ // session the page already has, instead of waiting for an event that has
60
+ // been and gone: without this the first latency tick replaced the shell and
61
+ // folder in the footer with the latency alone.
62
+ const started = window.__terminalOne?.sessionView?.();
63
+ if (started && started.state === 'live' && started.current) {
64
+ currentCommand = started.current.command || '';
65
+ currentCwd = started.current.cwd || '';
66
+ connectedAt = Date.now();
67
+ }
68
+
69
+ // Track connection events from the global status text.
70
+ const statusEl = document.getElementById('status');
71
+ if (statusEl) {
72
+ const observer = new MutationObserver(() => {
73
+ const text = statusEl.textContent || '';
74
+ if (text.includes('Connected') && !connectedAt) {
75
+ connectedAt = Date.now();
76
+ } else if (text.includes('Disconnected') || text.includes('Closed') || text.includes('Exited')) {
77
+ connectedAt = 0;
78
+ rttMs = null;
79
+ } else if (text.includes('No shell')) {
80
+ // No shell is open, so there is no shell for the footer to describe.
81
+ connectedAt = 0;
82
+ rttMs = null;
83
+ currentCommand = '';
84
+ currentCwd = '';
85
+ }
86
+ updateFooter();
87
+ });
88
+ observer.observe(statusEl, { childList: true, subtree: true });
89
+ }
90
+
91
+ // Update shell/cwd/command from the footer text set by the server.
92
+ const footerObserver = new MutationObserver(() => {
93
+ if (ignoreNextMutation) { ignoreNextMutation = false; return; }
94
+ const text = footerMeta.textContent || '';
95
+ const shellMatch = text.match(/^([\w\-.]+)\s*·\s*(.*)/);
96
+ if (shellMatch) {
97
+ currentCommand = shellMatch[1];
98
+ currentCwd = shellMatch[2];
99
+ } else if (text && text !== 'Your shell, in focus') {
100
+ currentCwd = text;
101
+ }
102
+ updateFooter();
103
+ });
104
+ footerObserver.observe(footerMeta, { childList: true });
105
+
106
+ // Lightweight latency probe: send a no-op ping every 10s when connected.
107
+ let pingInFlight = false;
108
+ setInterval(() => {
109
+ if (pingInFlight) return;
110
+ if (noShell()) return;
111
+ const ws = T1.ws || window.__terminalOne?.ws;
112
+ if (ws && ws.readyState === WebSocket.OPEN) {
113
+ const start = performance.now();
114
+ pingInFlight = true;
115
+ const handler = (evt) => {
116
+ try {
117
+ const msg = JSON.parse(evt.data);
118
+ if (msg.type === 'pong') {
119
+ ws.removeEventListener('message', handler);
120
+ clearTimeout(timeout);
121
+ pingInFlight = false;
122
+ rttMs = performance.now() - start;
123
+ updateFooter();
124
+ }
125
+ } catch (_) {}
126
+ };
127
+ const timeout = setTimeout(() => {
128
+ ws.removeEventListener('message', handler);
129
+ pingInFlight = false;
130
+ }, 5_000);
131
+ ws.addEventListener('message', handler);
132
+ ws.send(JSON.stringify({ type: 'ping' }));
133
+ }
134
+ }, 10_000);
135
+
136
+ updateFooter();
137
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Stylus / Apple Pencil support (tablet).
3
+ *
4
+ * Pointer events from a stylus bypass xterm selection and draw a transient
5
+ * highlight/annotation layer. Long-press with the stylus opens a context menu.
6
+ */
7
+ export function init(T1) {
8
+ if (T1.device === 'desktop' || T1.device === 'iphone') return;
9
+
10
+ T1.ui.addStyle(`
11
+ .t1-stylus-layer {
12
+ position: fixed;
13
+ inset: 0;
14
+ pointer-events: none;
15
+ z-index: 200;
16
+ }
17
+ .t1-stylus-menu {
18
+ position: fixed;
19
+ background: var(--ui-elevated);
20
+ border: 1px solid var(--ui-border);
21
+ border-radius: 6px;
22
+ padding: 4px 0;
23
+ z-index: 210;
24
+ display: none;
25
+ min-width: 120px;
26
+ }
27
+ .t1-stylus-menu button {
28
+ display: block;
29
+ width: 100%;
30
+ padding: 8px 12px;
31
+ background: transparent;
32
+ border: none;
33
+ color: var(--ui-fg);
34
+ text-align: left;
35
+ font-size: 13px;
36
+ cursor: pointer;
37
+ }
38
+ .t1-stylus-menu button:active { background: var(--ui-accent); color: var(--ui-on-accent, #14171b); }
39
+ `);
40
+
41
+ const canvas = document.createElement('canvas');
42
+ canvas.className = 't1-stylus-layer';
43
+ canvas.setAttribute('aria-hidden', 'true');
44
+ document.body.appendChild(canvas);
45
+ const ctx = canvas.getContext('2d');
46
+
47
+ const menu = document.createElement('div');
48
+ menu.className = 't1-stylus-menu';
49
+ menu.setAttribute('role', 'menu');
50
+ menu.innerHTML = `
51
+ <button type="button" role="menuitem" data-action="copy">Copy</button>
52
+ <button type="button" role="menuitem" data-action="paste">Paste</button>
53
+ <button type="button" role="menuitem" data-action="select-all">Select All</button>
54
+ <button type="button" role="menuitem" data-action="clear">Clear</button>
55
+ `;
56
+ document.body.appendChild(menu);
57
+
58
+ function resize() {
59
+ canvas.width = window.innerWidth;
60
+ canvas.height = window.innerHeight;
61
+ }
62
+ resize();
63
+ window.addEventListener('resize', resize, { passive: true });
64
+
65
+ let drawing = false;
66
+ let longTimer = null;
67
+ let menuPos = null;
68
+
69
+ function hideMenu() { menu.style.display = 'none'; menuPos = null; }
70
+
71
+ canvas.addEventListener('pointerdown', (e) => {
72
+ if (e.pointerType !== 'pen') return;
73
+ drawing = true;
74
+ ctx.beginPath();
75
+ ctx.moveTo(e.clientX, e.clientY);
76
+ ctx.strokeStyle = 'rgba(122,162,247,0.6)';
77
+ ctx.lineWidth = 2;
78
+ longTimer = setTimeout(() => {
79
+ drawing = false;
80
+ menuPos = { x: e.clientX, y: e.clientY };
81
+ menu.style.left = `${e.clientX}px`;
82
+ menu.style.top = `${e.clientY}px`;
83
+ menu.style.display = 'block';
84
+ }, 600);
85
+ });
86
+
87
+ canvas.addEventListener('pointermove', (e) => {
88
+ if (!drawing || e.pointerType !== 'pen') return;
89
+ ctx.lineTo(e.clientX, e.clientY);
90
+ ctx.stroke();
91
+ if (longTimer) { clearTimeout(longTimer); longTimer = null; }
92
+ });
93
+
94
+ canvas.addEventListener('pointerup', (e) => {
95
+ drawing = false;
96
+ if (longTimer) { clearTimeout(longTimer); longTimer = null; }
97
+ });
98
+
99
+ menu.addEventListener('click', async (e) => {
100
+ const action = e.target.dataset.action;
101
+ if (!action) return;
102
+ hideMenu();
103
+ const term = T1.term;
104
+ try {
105
+ if (action === 'copy') {
106
+ const selection = term?.getSelection?.() || '';
107
+ if (!selection) { T1.toast('Select terminal text first', 'warn'); return; }
108
+ await navigator.clipboard.writeText(selection);
109
+ T1.toast('Selection copied');
110
+ }
111
+ if (action === 'paste') {
112
+ const text = await navigator.clipboard.readText();
113
+ if (text) T1.sendData(text);
114
+ }
115
+ if (action === 'select-all' && term) term.selectAll();
116
+ if (action === 'clear' && term) term.clear();
117
+ } catch (_) {
118
+ T1.toast('Clipboard is unavailable in this browser', 'warn');
119
+ }
120
+ });
121
+
122
+ // Expose for tests.
123
+ window.__terminalOneStylus = { canvas, menu, hideMenu, resize };
124
+ }