townmouse 0.0.0-stage → 0.2.1

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 (103) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/DESIGN.md +169 -0
  3. package/LICENSE +661 -0
  4. package/README.md +368 -2
  5. package/SECURITY.md +57 -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 +275 -0
  13. package/docs/browser-workspace.md +184 -0
  14. package/docs/panes.md +252 -0
  15. package/native/TownmouseApp.swift +108 -0
  16. package/package.json +89 -4
  17. package/public/apple-touch-icon.png +0 -0
  18. package/public/brand/floydslabs-credit.png +0 -0
  19. package/public/brand/floydslabs-credit.webp +0 -0
  20. package/public/brand/townmouse-aristocrat.webp +0 -0
  21. package/public/brand/townmouse-monocled.webp +0 -0
  22. package/public/clipboard-text.mjs +5 -0
  23. package/public/favicon-16x16.png +0 -0
  24. package/public/favicon-32x32.png +0 -0
  25. package/public/favicon.ico +0 -0
  26. package/public/favicon.svg +1 -0
  27. package/public/features/autosave.mjs +76 -0
  28. package/public/features/clipboard.mjs +69 -0
  29. package/public/features/command-palette.mjs +181 -0
  30. package/public/features/desktop-palette.mjs +19 -0
  31. package/public/features/export.mjs +37 -0
  32. package/public/features/file-drop.mjs +77 -0
  33. package/public/features/floating-palette.mjs +113 -0
  34. package/public/features/fontsize.mjs +72 -0
  35. package/public/features/haptic-keys.mjs +42 -0
  36. package/public/features/history-undo.mjs +102 -0
  37. package/public/features/keepalive.mjs +36 -0
  38. package/public/features/keybar-config.mjs +70 -0
  39. package/public/features/keyboard-shortcuts.mjs +74 -0
  40. package/public/features/links.mjs +139 -0
  41. package/public/features/multi-window-sync.mjs +74 -0
  42. package/public/features/osc-bridge.mjs +59 -0
  43. package/public/features/phone-landscape-focus.mjs +157 -0
  44. package/public/features/recent-commands.mjs +100 -0
  45. package/public/features/search.mjs +134 -0
  46. package/public/features/session-lock.mjs +96 -0
  47. package/public/features/session-manager.mjs +149 -0
  48. package/public/features/settings-sync.mjs +77 -0
  49. package/public/features/shortcut-help.mjs +85 -0
  50. package/public/features/smart-completions.mjs +101 -0
  51. package/public/features/smart-suggest.mjs +124 -0
  52. package/public/features/snippets.mjs +85 -0
  53. package/public/features/split-view.mjs +102 -0
  54. package/public/features/status-metrics.mjs +114 -0
  55. package/public/features/stylus-support.mjs +124 -0
  56. package/public/features/swipe-history.mjs +141 -0
  57. package/public/features/swipe-sessions.mjs +85 -0
  58. package/public/features/tab-reorder.mjs +62 -0
  59. package/public/features/theme-system.mjs +51 -0
  60. package/public/features/toast-status.mjs +118 -0
  61. package/public/features/two-finger-menu.mjs +87 -0
  62. package/public/features/voice-input.mjs +244 -0
  63. package/public/features/wake-fullscreen.mjs +67 -0
  64. package/public/features/window-title.mjs +40 -0
  65. package/public/features/zoom.mjs +80 -0
  66. package/public/icon-128.png +0 -0
  67. package/public/icon-180.png +0 -0
  68. package/public/icon-192.png +0 -0
  69. package/public/icon-48.png +0 -0
  70. package/public/icon-512-maskable.png +0 -0
  71. package/public/icon-512.png +0 -0
  72. package/public/icon.svg +1 -0
  73. package/public/index.html +1765 -0
  74. package/public/input-chunks.mjs +22 -0
  75. package/public/input-guard.mjs +210 -0
  76. package/public/manifest.json +56 -0
  77. package/public/panes.css +1257 -0
  78. package/public/panes.html +208 -0
  79. package/public/panes.mjs +2625 -0
  80. package/public/service-worker.js +67 -0
  81. package/public/workspace.css +1447 -0
  82. package/public/workspace.mjs +1475 -0
  83. package/scripts/install-service.sh +269 -0
  84. package/scripts/node-runtime.sh +138 -0
  85. package/scripts/panes +439 -0
  86. package/scripts/prepare-native.sh +35 -0
  87. package/scripts/run-hooks +69 -0
  88. package/scripts/t1.sh +113 -0
  89. package/scripts/uninstall-service.sh +49 -0
  90. package/src/agent-guide.js +260 -0
  91. package/src/attachments.js +128 -0
  92. package/src/browser-dom.js +545 -0
  93. package/src/browser-workspace.js +1246 -0
  94. package/src/chrome-resolve.js +80 -0
  95. package/src/pty-permissions.js +99 -0
  96. package/src/regex-worker.js +13 -0
  97. package/src/replay-text.js +189 -0
  98. package/src/request-boundary.js +58 -0
  99. package/src/safe-regex.js +87 -0
  100. package/src/server.js +1122 -0
  101. package/src/shell-resolve.js +42 -0
  102. package/src/static-deps.js +61 -0
  103. package/src/workspace-panes.js +1099 -0
@@ -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,114 @@
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
+ function updateFooter() {
28
+ const parts = [];
29
+ if (currentCommand) parts.push(currentCommand);
30
+ if (currentCwd) parts.push(currentCwd);
31
+ if (connectedAt) {
32
+ parts.push(`up ${formatDuration(Date.now() - connectedAt)}`);
33
+ }
34
+ if (rttMs != null) {
35
+ parts.push(`latency ${rttMs.toFixed(0)}ms`);
36
+ }
37
+ const text = parts.join(' · ');
38
+ if (!text) return;
39
+ if (text !== lastFooterText) {
40
+ lastFooterText = text;
41
+ ignoreNextMutation = true;
42
+ footerMeta.textContent = text;
43
+ }
44
+ }
45
+
46
+ window.addEventListener('t1:session-ready', (event) => {
47
+ currentCommand = event.detail?.command || '';
48
+ currentCwd = event.detail?.cwd || '';
49
+ connectedAt = Date.now();
50
+ updateFooter();
51
+ });
52
+
53
+ // Track connection events from the global status text.
54
+ const statusEl = document.getElementById('status');
55
+ if (statusEl) {
56
+ const observer = new MutationObserver(() => {
57
+ const text = statusEl.textContent || '';
58
+ if (text.includes('Connected') && !connectedAt) {
59
+ connectedAt = Date.now();
60
+ } else if (text.includes('Disconnected') || text.includes('Closed') || text.includes('Exited')) {
61
+ connectedAt = 0;
62
+ rttMs = null;
63
+ }
64
+ updateFooter();
65
+ });
66
+ observer.observe(statusEl, { childList: true, subtree: true });
67
+ }
68
+
69
+ // Update shell/cwd/command from the footer text set by the server.
70
+ const footerObserver = new MutationObserver(() => {
71
+ if (ignoreNextMutation) { ignoreNextMutation = false; return; }
72
+ const text = footerMeta.textContent || '';
73
+ const shellMatch = text.match(/^([\w\-.]+)\s*·\s*(.*)/);
74
+ if (shellMatch) {
75
+ currentCommand = shellMatch[1];
76
+ currentCwd = shellMatch[2];
77
+ } else if (text && text !== 'Your shell, in focus') {
78
+ currentCwd = text;
79
+ }
80
+ updateFooter();
81
+ });
82
+ footerObserver.observe(footerMeta, { childList: true });
83
+
84
+ // Lightweight latency probe: send a no-op ping every 10s when connected.
85
+ let pingInFlight = false;
86
+ setInterval(() => {
87
+ if (pingInFlight) return;
88
+ const ws = T1.ws || window.__terminalOne?.ws;
89
+ if (ws && ws.readyState === WebSocket.OPEN) {
90
+ const start = performance.now();
91
+ pingInFlight = true;
92
+ const handler = (evt) => {
93
+ try {
94
+ const msg = JSON.parse(evt.data);
95
+ if (msg.type === 'pong') {
96
+ ws.removeEventListener('message', handler);
97
+ clearTimeout(timeout);
98
+ pingInFlight = false;
99
+ rttMs = performance.now() - start;
100
+ updateFooter();
101
+ }
102
+ } catch (_) {}
103
+ };
104
+ const timeout = setTimeout(() => {
105
+ ws.removeEventListener('message', handler);
106
+ pingInFlight = false;
107
+ }, 5_000);
108
+ ws.addEventListener('message', handler);
109
+ ws.send(JSON.stringify({ type: 'ping' }));
110
+ }
111
+ }, 10_000);
112
+
113
+ updateFooter();
114
+ }
@@ -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
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Swipe-up command history tray (phone vertical).
3
+ *
4
+ * On iPhone, swiping up from the bottom key bar opens a drawer showing the
5
+ * most recent commands from the local history ring. Tapping a command pastes
6
+ * it into the terminal input.
7
+ */
8
+ const HISTORY_KEY = 'terminalone.commandHistory';
9
+
10
+ export function init(T1) {
11
+ if (T1.device !== 'iphone') return;
12
+
13
+ T1.ui.addStyle(`
14
+ .t1-swipe-history-tray {
15
+ position: fixed;
16
+ left: 0; right: 0; bottom: 0;
17
+ max-height: 45vh;
18
+ background: var(--ui-elevated);
19
+ border-top: 1px solid var(--ui-border);
20
+ border-radius: 12px 12px 0 0;
21
+ transform: translateY(110%);
22
+ visibility: hidden;
23
+ transition: transform 0.25s ease;
24
+ z-index: 250;
25
+ display: flex;
26
+ flex-direction: column;
27
+ padding-bottom: env(safe-area-inset-bottom);
28
+ }
29
+ .t1-swipe-history-tray.open { transform: translateY(0); visibility: visible; }
30
+ .t1-swipe-history-tray header {
31
+ display: flex;
32
+ align-items: center;
33
+ justify-content: space-between;
34
+ padding: 10px 14px;
35
+ border-bottom: 1px solid var(--ui-border);
36
+ }
37
+ .t1-swipe-history-tray h3 { margin: 0; font-size: 13px; color: var(--ui-fg); }
38
+ .t1-swipe-history-tray .close-btn {
39
+ background: transparent; border: none; color: var(--ui-muted); font-size: 16px;
40
+ }
41
+ .t1-swipe-history-list {
42
+ overflow-y: auto;
43
+ -webkit-overflow-scrolling: touch;
44
+ }
45
+ .t1-swipe-history-list .cmd {
46
+ padding: 12px 14px;
47
+ border-bottom: 1px solid var(--ui-border);
48
+ font-size: 13px;
49
+ color: var(--ui-fg);
50
+ cursor: pointer;
51
+ white-space: nowrap;
52
+ overflow: hidden;
53
+ text-overflow: ellipsis;
54
+ }
55
+ .t1-swipe-history-list .cmd:active { background: var(--ui-accent); color: var(--ui-on-accent, #14171b); }
56
+ .t1-swipe-history-list .empty {
57
+ padding: 20px 14px; color: var(--ui-muted); font-size: 12px; text-align: center;
58
+ }
59
+ .t1-swipe-history-hint {
60
+ position: fixed;
61
+ left: 50%; bottom: 4px;
62
+ transform: translateX(-50%);
63
+ width: 36px; height: 4px;
64
+ border-radius: 2px;
65
+ background: var(--ui-border);
66
+ z-index: 251;
67
+ pointer-events: none;
68
+ }
69
+ `);
70
+
71
+ const tray = document.createElement('div');
72
+ tray.className = 't1-swipe-history-tray';
73
+ tray.setAttribute('role', 'dialog');
74
+ tray.setAttribute('aria-label', 'Command history');
75
+ tray.innerHTML = `
76
+ <header><h3>Recent commands</h3><button type="button" class="close-btn" aria-label="Close history">×</button></header>
77
+ <div class="t1-swipe-history-list"></div>
78
+ `;
79
+ document.body.appendChild(tray);
80
+
81
+ const hint = document.createElement('div');
82
+ hint.className = 't1-swipe-history-hint';
83
+ document.body.appendChild(hint);
84
+
85
+ const list = tray.querySelector('.t1-swipe-history-list');
86
+ tray.querySelector('.close-btn').addEventListener('click', close);
87
+
88
+ function readHistory() {
89
+ try { return JSON.parse(T1.storage.get(HISTORY_KEY, '[]')); }
90
+ catch (_) { return []; }
91
+ }
92
+
93
+ function render() {
94
+ const hist = readHistory().slice().reverse();
95
+ list.innerHTML = '';
96
+ if (!hist.length) {
97
+ list.innerHTML = '<div class="empty">No commands yet. Type something and press Enter.</div>';
98
+ return;
99
+ }
100
+ for (const cmd of hist) {
101
+ const row = document.createElement('div');
102
+ row.className = 'cmd';
103
+ row.textContent = cmd;
104
+ row.setAttribute('role', 'button');
105
+ row.setAttribute('tabindex', '0');
106
+ row.addEventListener('click', () => { T1.sendData(cmd); close(); T1.toast('Pasted from history'); });
107
+ row.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); row.click(); } });
108
+ list.appendChild(row);
109
+ }
110
+ }
111
+
112
+ function open() { render(); tray.classList.add('open'); }
113
+ function close() { tray.classList.remove('open'); }
114
+
115
+ // Swipe up from the bottom key bar opens the tray.
116
+ const keybar = document.getElementById('keybarIphone');
117
+ if (keybar) {
118
+ let startY = 0;
119
+ let startX = 0;
120
+ keybar.addEventListener('touchstart', (e) => {
121
+ const t = e.touches[0];
122
+ startY = t.clientY;
123
+ startX = t.clientX;
124
+ }, { passive: true });
125
+ keybar.addEventListener('touchend', (e) => {
126
+ const t = e.changedTouches[0];
127
+ const dy = startY - t.clientY;
128
+ const dx = Math.abs(startX - t.clientX);
129
+ if (dy > 40 && dx < 60) {
130
+ e.preventDefault();
131
+ open();
132
+ }
133
+ }, { passive: false });
134
+ }
135
+
136
+ // Clicking the hint also opens it for discoverability.
137
+ hint.addEventListener('click', open);
138
+
139
+ // Test hook.
140
+ window.__terminalOneSwipeHistory = { open, close, tray, render, readHistory };
141
+ }