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.
- package/CHANGELOG.md +126 -0
- package/DESIGN.md +169 -0
- package/LICENSE +661 -0
- package/README.md +368 -2
- package/SECURITY.md +57 -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 +275 -0
- package/docs/browser-workspace.md +184 -0
- package/docs/panes.md +252 -0
- package/native/TownmouseApp.swift +108 -0
- package/package.json +89 -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/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/autosave.mjs +76 -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 +74 -0
- package/public/features/osc-bridge.mjs +59 -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 +149 -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 +114 -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 +62 -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 +40 -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 +1765 -0
- package/public/input-chunks.mjs +22 -0
- package/public/input-guard.mjs +210 -0
- package/public/manifest.json +56 -0
- package/public/panes.css +1257 -0
- package/public/panes.html +208 -0
- package/public/panes.mjs +2625 -0
- package/public/service-worker.js +67 -0
- package/public/workspace.css +1447 -0
- package/public/workspace.mjs +1475 -0
- package/scripts/install-service.sh +269 -0
- package/scripts/node-runtime.sh +138 -0
- package/scripts/panes +439 -0
- package/scripts/prepare-native.sh +35 -0
- package/scripts/run-hooks +69 -0
- package/scripts/t1.sh +113 -0
- package/scripts/uninstall-service.sh +49 -0
- package/src/agent-guide.js +260 -0
- package/src/attachments.js +128 -0
- package/src/browser-dom.js +545 -0
- package/src/browser-workspace.js +1246 -0
- package/src/chrome-resolve.js +80 -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 +1122 -0
- package/src/shell-resolve.js +42 -0
- package/src/static-deps.js +61 -0
- package/src/workspace-panes.js +1099 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key bar configuration — show/hide button groups in Settings.
|
|
3
|
+
*
|
|
4
|
+
* ShellFish parity: customize the on-screen key bar.
|
|
5
|
+
*/
|
|
6
|
+
const LS_KEYBAR = 'terminalone.keybarConfig';
|
|
7
|
+
|
|
8
|
+
export function init(T1) {
|
|
9
|
+
const panel = T1.ui.settingsPanel();
|
|
10
|
+
if (!panel) return;
|
|
11
|
+
|
|
12
|
+
const defaults = { mod: true, ctrl: true, nav: true, arrows: true, symbols: true };
|
|
13
|
+
let cfg = { ...defaults };
|
|
14
|
+
try {
|
|
15
|
+
cfg = { ...defaults, ...JSON.parse(T1.storage.get(LS_KEYBAR, '{}')) };
|
|
16
|
+
} catch (_) {}
|
|
17
|
+
|
|
18
|
+
T1.ui.addStyle(`
|
|
19
|
+
.t1keybar-cfg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
|
|
20
|
+
.t1keybar-cfg label { display: flex; align-items: center; gap: 6px; min-height: 44px; margin: 0; font-size: 12px; text-transform: none; letter-spacing: 0; cursor: pointer; }
|
|
21
|
+
`);
|
|
22
|
+
|
|
23
|
+
const row = document.createElement('div');
|
|
24
|
+
row.className = 'settings-row settings-keybar-row';
|
|
25
|
+
row.innerHTML = `
|
|
26
|
+
<label>Key bar groups</label>
|
|
27
|
+
<div class="t1keybar-cfg">
|
|
28
|
+
<label><input type="checkbox" data-key="mod" ${cfg.mod ? 'checked' : ''}> Modifiers</label>
|
|
29
|
+
<label><input type="checkbox" data-key="ctrl" ${cfg.ctrl ? 'checked' : ''}> Ctrl chords</label>
|
|
30
|
+
<label><input type="checkbox" data-key="nav" ${cfg.nav ? 'checked' : ''}> Navigation</label>
|
|
31
|
+
<label><input type="checkbox" data-key="arrows" ${cfg.arrows ? 'checked' : ''}> Arrows</label>
|
|
32
|
+
<label><input type="checkbox" data-key="symbols" ${cfg.symbols ? 'checked' : ''}> Symbols</label>
|
|
33
|
+
</div>
|
|
34
|
+
`;
|
|
35
|
+
// The first .settings-actions in the panel belongs to the voice section and
|
|
36
|
+
// is not a direct child. Target the panel's own Done row instead.
|
|
37
|
+
const actions = panel.querySelector(':scope > .settings-actions');
|
|
38
|
+
if (actions) panel.insertBefore(row, actions);
|
|
39
|
+
else panel.append(row);
|
|
40
|
+
|
|
41
|
+
function save() {
|
|
42
|
+
T1.storage.set(LS_KEYBAR, JSON.stringify(cfg));
|
|
43
|
+
apply();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function apply() {
|
|
47
|
+
const iphone = document.getElementById('keybarIphone');
|
|
48
|
+
const ipad = document.getElementById('keybarIpad');
|
|
49
|
+
[iphone, ipad].forEach((bar) => {
|
|
50
|
+
if (!bar) return;
|
|
51
|
+
const groups = bar.querySelectorAll('[data-kb]');
|
|
52
|
+
groups.forEach((g) => {
|
|
53
|
+
const key = g.dataset.kb;
|
|
54
|
+
if (!key || !(key in cfg)) return;
|
|
55
|
+
g.style.display = cfg[key] ? '' : 'none';
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
row.querySelectorAll('input[type="checkbox"]').forEach((cb) => {
|
|
61
|
+
cb.addEventListener('change', () => {
|
|
62
|
+
cfg[cb.dataset.key] = cb.checked;
|
|
63
|
+
save();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Apply on load and whenever key bars are rebuilt (orientation change).
|
|
68
|
+
apply();
|
|
69
|
+
window.addEventListener('orientationchange', () => setTimeout(apply, 250));
|
|
70
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global keyboard shortcuts — terminal-friendly chords that don't steal from
|
|
3
|
+
* the shell. Each shortcut is gated so it only fires when xterm doesn't need
|
|
4
|
+
* the key (i.e. target is document body, not the terminal textarea).
|
|
5
|
+
*/
|
|
6
|
+
const KEY = 'terminalone.shortcuts';
|
|
7
|
+
|
|
8
|
+
export function init(T1) {
|
|
9
|
+
const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform || '');
|
|
10
|
+
const meta = (e) => (isMac ? e.metaKey : e.ctrlKey);
|
|
11
|
+
// Bare Ctrl+K/Ctrl+B belong to readline on Windows/Linux. Use shifted chords
|
|
12
|
+
// there so kill-line and backward-char still reach the shell.
|
|
13
|
+
const appChord = (e) => (isMac ? e.metaKey && !e.ctrlKey : e.ctrlKey && e.shiftKey);
|
|
14
|
+
|
|
15
|
+
function dispatch(name) {
|
|
16
|
+
window.dispatchEvent(new CustomEvent('t1:action', { detail: { action: name }, bubbles: true }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
document.addEventListener('keydown', (e) => {
|
|
20
|
+
// Only intercept when focus is outside the terminal helper textarea,
|
|
21
|
+
// unless the chord explicitly includes a modifier.
|
|
22
|
+
const targetIsTerm = e.target && (e.target.classList?.contains('xterm-helper-textarea') ||
|
|
23
|
+
e.target.closest?.('#terminal'));
|
|
24
|
+
const mod = e.ctrlKey || e.metaKey || e.altKey || e.shiftKey;
|
|
25
|
+
|
|
26
|
+
// Escape closes open modals/panels.
|
|
27
|
+
if (e.key === 'Escape') {
|
|
28
|
+
const openModal = document.querySelector('[role="dialog"].open, .t1help.open, .t1palette.open');
|
|
29
|
+
if (openModal) { openModal.classList.remove('open'); e.preventDefault(); return; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// F1 help.
|
|
33
|
+
if (e.key === 'F1') { e.preventDefault(); dispatch('help'); return; }
|
|
34
|
+
|
|
35
|
+
if (!mod) return; // plain typing belongs to the shell
|
|
36
|
+
|
|
37
|
+
// Ctrl/Cmd + '+' / '-' font size.
|
|
38
|
+
if ((e.key === '+' || e.key === '=' || e.key === 'Plus') && meta(e)) {
|
|
39
|
+
e.preventDefault(); dispatch('font-increase'); return;
|
|
40
|
+
}
|
|
41
|
+
if ((e.key === '-' || e.key === '_' || e.key === 'Minus') && meta(e)) {
|
|
42
|
+
e.preventDefault(); dispatch('font-decrease'); return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Cmd+K on macOS; Ctrl+Shift+K elsewhere (bare Ctrl+K is readline).
|
|
46
|
+
if ((e.key === 'k' || e.key === 'K') && appChord(e)) {
|
|
47
|
+
e.preventDefault(); dispatch('clear'); return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Ctrl/Cmd + Shift + P command palette.
|
|
51
|
+
if ((e.key === 'p' || e.key === 'P') && meta(e) && e.shiftKey) {
|
|
52
|
+
e.preventDefault(); dispatch('command-palette'); return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Cmd+B on macOS; Ctrl+Shift+B elsewhere (bare Ctrl+B is backward-char).
|
|
56
|
+
if ((e.key === 'b' || e.key === 'B') && appChord(e)) {
|
|
57
|
+
e.preventDefault(); dispatch('toggle-snippets'); return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Ctrl/Cmd + Shift + F toggle search.
|
|
61
|
+
if ((e.key === 'f' || e.key === 'F') && meta(e) && e.shiftKey) {
|
|
62
|
+
e.preventDefault(); dispatch('toggle-search'); return;
|
|
63
|
+
}
|
|
64
|
+
}, true);
|
|
65
|
+
|
|
66
|
+
// Listen to our own action events so this module is self-contained.
|
|
67
|
+
window.addEventListener('t1:action', (e) => {
|
|
68
|
+
const { action } = e.detail || {};
|
|
69
|
+
if (action === 'clear' && T1.term) {
|
|
70
|
+
T1.sendData('\x0c');
|
|
71
|
+
T1.toast('Screen cleared');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link and filename actions — extends xterm's link handling with a context
|
|
3
|
+
* menu, and makes obvious filenames in terminal output tappable.
|
|
4
|
+
*
|
|
5
|
+
* ShellFish parity: tap URLs/filenames to preview or copy them.
|
|
6
|
+
*/
|
|
7
|
+
export function init(T1) {
|
|
8
|
+
const shell = T1.ui.appShell() || document.body;
|
|
9
|
+
|
|
10
|
+
T1.ui.addStyle(`
|
|
11
|
+
.t1link-menu {
|
|
12
|
+
position: absolute;
|
|
13
|
+
z-index: 500;
|
|
14
|
+
background: var(--ui-elevated);
|
|
15
|
+
border: 1px solid var(--ui-border);
|
|
16
|
+
border-radius: 6px;
|
|
17
|
+
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
|
|
18
|
+
padding: 4px 0;
|
|
19
|
+
min-width: 160px;
|
|
20
|
+
display: none;
|
|
21
|
+
}
|
|
22
|
+
.t1link-menu.open { display: block; }
|
|
23
|
+
.t1link-menu button {
|
|
24
|
+
display: block;
|
|
25
|
+
width: 100%;
|
|
26
|
+
text-align: left;
|
|
27
|
+
background: transparent;
|
|
28
|
+
border: none;
|
|
29
|
+
padding: 6px 12px;
|
|
30
|
+
font-size: 12px;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
}
|
|
33
|
+
.t1link-menu button:hover { background: var(--ui-bg); }
|
|
34
|
+
`);
|
|
35
|
+
|
|
36
|
+
const menu = document.createElement('div');
|
|
37
|
+
menu.className = 't1link-menu';
|
|
38
|
+
shell.appendChild(menu);
|
|
39
|
+
|
|
40
|
+
function showMenu(x, y, targetUrl, filename) {
|
|
41
|
+
menu.innerHTML = '';
|
|
42
|
+
if (targetUrl) {
|
|
43
|
+
const openBtn = document.createElement('button');
|
|
44
|
+
openBtn.textContent = 'Open link';
|
|
45
|
+
openBtn.addEventListener('click', () => { window.open(targetUrl, '_blank', 'noopener,noreferrer'); closeMenu(); });
|
|
46
|
+
menu.appendChild(openBtn);
|
|
47
|
+
const copyBtn = document.createElement('button');
|
|
48
|
+
copyBtn.textContent = 'Copy link';
|
|
49
|
+
copyBtn.addEventListener('click', () => {
|
|
50
|
+
navigator.clipboard?.writeText(targetUrl).catch(() => {});
|
|
51
|
+
T1.toast('Link copied');
|
|
52
|
+
closeMenu();
|
|
53
|
+
});
|
|
54
|
+
menu.appendChild(copyBtn);
|
|
55
|
+
}
|
|
56
|
+
if (filename) {
|
|
57
|
+
const fileBtn = document.createElement('button');
|
|
58
|
+
fileBtn.textContent = `Copy "${filename}"`;
|
|
59
|
+
fileBtn.addEventListener('click', () => {
|
|
60
|
+
navigator.clipboard?.writeText(filename).catch(() => {});
|
|
61
|
+
T1.toast(`Filename copied: ${filename}`);
|
|
62
|
+
closeMenu();
|
|
63
|
+
});
|
|
64
|
+
menu.appendChild(fileBtn);
|
|
65
|
+
}
|
|
66
|
+
menu.style.left = `${Math.min(x, window.innerWidth - 170)}px`;
|
|
67
|
+
menu.style.top = `${Math.min(y, window.innerHeight - 80)}px`;
|
|
68
|
+
menu.classList.add('open');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function closeMenu() { menu.classList.remove('open'); }
|
|
72
|
+
|
|
73
|
+
document.addEventListener('click', (e) => { if (!menu.contains(e.target)) closeMenu(); });
|
|
74
|
+
|
|
75
|
+
T1.onTermReady((term) => {
|
|
76
|
+
const screenEl = term.element;
|
|
77
|
+
if (!screenEl) return;
|
|
78
|
+
|
|
79
|
+
// Right-click/long-press on links. xterm wraps link text in spans with
|
|
80
|
+
// the xterm-decoration-inline-anchor class when WebLinksAddon is active.
|
|
81
|
+
function onContextMenu(e) {
|
|
82
|
+
const anchor = e.target.closest?.('a');
|
|
83
|
+
if (anchor) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
showMenu(e.clientX, e.clientY, anchor.href, null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Filename heuristic: anything that looks like a path/file.
|
|
89
|
+
const filename = extractFilename(e.target.textContent);
|
|
90
|
+
if (filename) {
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
showMenu(e.clientX, e.clientY, null, filename);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Also add filename highlighting by scanning rows. We do not modify xterm
|
|
97
|
+
// internals; instead we listen for mousemove and show a tooltip for paths.
|
|
98
|
+
let tooltip = null;
|
|
99
|
+
function onMouseMove(e) {
|
|
100
|
+
const text = e.target.textContent || '';
|
|
101
|
+
const filename = extractFilename(text);
|
|
102
|
+
if (!filename) {
|
|
103
|
+
if (tooltip) { tooltip.remove(); tooltip = null; }
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (!tooltip) {
|
|
107
|
+
tooltip = document.createElement('div');
|
|
108
|
+
tooltip.className = 't1link-menu';
|
|
109
|
+
tooltip.style.position = 'absolute';
|
|
110
|
+
tooltip.style.padding = '4px 8px';
|
|
111
|
+
tooltip.style.pointerEvents = 'none';
|
|
112
|
+
tooltip.textContent = filename;
|
|
113
|
+
shell.appendChild(tooltip);
|
|
114
|
+
}
|
|
115
|
+
tooltip.style.left = `${e.clientX + 12}px`;
|
|
116
|
+
tooltip.style.top = `${e.clientY + 12}px`;
|
|
117
|
+
tooltip.classList.add('open');
|
|
118
|
+
}
|
|
119
|
+
function onMouseLeave() { if (tooltip) { tooltip.remove(); tooltip = null; } }
|
|
120
|
+
|
|
121
|
+
screenEl.addEventListener('contextmenu', onContextMenu);
|
|
122
|
+
screenEl.addEventListener('mousemove', onMouseMove);
|
|
123
|
+
screenEl.addEventListener('mouseleave', onMouseLeave);
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
screenEl.removeEventListener('contextmenu', onContextMenu);
|
|
127
|
+
screenEl.removeEventListener('mousemove', onMouseMove);
|
|
128
|
+
screenEl.removeEventListener('mouseleave', onMouseLeave);
|
|
129
|
+
if (tooltip) { tooltip.remove(); tooltip = null; }
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function extractFilename(text) {
|
|
135
|
+
if (!text || text.length > 80) return null;
|
|
136
|
+
// Match common file/path patterns: ./foo, /tmp/bar, foo.txt, dir/file.
|
|
137
|
+
const m = text.match(/(?:[\w.~+-]+\/)+[\w.~+-]+|\/[\w.~+-\/]+|[\w.~+-]+\.[\w]{1,6}/);
|
|
138
|
+
return m ? m[0] : null;
|
|
139
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-window session sync via BroadcastChannel.
|
|
3
|
+
*
|
|
4
|
+
* When TerminalOne is open in multiple tabs/windows, session creation/deletion
|
|
5
|
+
* and active-session changes are broadcast so tabs stay in sync.
|
|
6
|
+
* Falls back to WebLocks + localStorage when BroadcastChannel is unavailable.
|
|
7
|
+
*/
|
|
8
|
+
const BC_NAME = 'terminalone-sync';
|
|
9
|
+
const LS_BCAST = 'terminalone.lsBroadcast';
|
|
10
|
+
|
|
11
|
+
export function init(T1) {
|
|
12
|
+
function send(type, payload) {
|
|
13
|
+
const msg = JSON.stringify({ type, payload, ts: Date.now() });
|
|
14
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
15
|
+
try {
|
|
16
|
+
const bc = new BroadcastChannel(BC_NAME);
|
|
17
|
+
bc.postMessage(msg);
|
|
18
|
+
bc.close();
|
|
19
|
+
} catch (_) {}
|
|
20
|
+
}
|
|
21
|
+
// localStorage fallback for browsers without BC (private mode iOS WebKit).
|
|
22
|
+
try {
|
|
23
|
+
localStorage.setItem(LS_BCAST, JSON.stringify({ msg, nonce: Math.random(), ts: Date.now() }));
|
|
24
|
+
} catch (_) {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function handleRaw(raw) {
|
|
28
|
+
let data;
|
|
29
|
+
try { data = JSON.parse(raw); } catch (_) { return; }
|
|
30
|
+
if (!data || !data.type) return;
|
|
31
|
+
if (data.type === 'session-active' || data.type === 'session-created' || data.type === 'session-deleted') {
|
|
32
|
+
const detail = data.payload || {};
|
|
33
|
+
if (detail.sessionId) T1.toast(`Synced: ${data.type.replace('session-', '')} ${detail.sessionId.slice(0, 8)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
38
|
+
try {
|
|
39
|
+
const bc = new BroadcastChannel(BC_NAME);
|
|
40
|
+
bc.onmessage = (e) => handleRaw(e.data);
|
|
41
|
+
} catch (_) {}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
window.addEventListener('storage', (e) => {
|
|
45
|
+
if (e.key !== LS_BCAST) return;
|
|
46
|
+
try {
|
|
47
|
+
const wrapped = JSON.parse(e.newValue || '{}');
|
|
48
|
+
if (wrapped && wrapped.msg) handleRaw(wrapped.msg);
|
|
49
|
+
} catch (_) {}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Hook session lifecycle by watching the saved session id and session info text.
|
|
53
|
+
let lastSession = T1.storage.get('terminalone.sessionId', null);
|
|
54
|
+
window.__terminalOneGetSavedSession = () => T1.storage.get('terminalone.sessionId', null);
|
|
55
|
+
|
|
56
|
+
const infoEl = document.getElementById('sessionInfo');
|
|
57
|
+
if (infoEl) {
|
|
58
|
+
const mo = new MutationObserver(() => {
|
|
59
|
+
const text = infoEl.textContent || '';
|
|
60
|
+
const m = text.match(/session\s+([a-f0-9\-]+)/);
|
|
61
|
+
if (m) {
|
|
62
|
+
const sid = m[1];
|
|
63
|
+
if (sid !== lastSession) {
|
|
64
|
+
send('session-active', { sessionId: sid });
|
|
65
|
+
lastSession = sid;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
mo.observe(infoEl, { childList: true });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Expose manual broadcast for tests.
|
|
73
|
+
window.__terminalOneMultiWindow = { send, handleRaw, lastSession: () => lastSession };
|
|
74
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { decodeClipboardText } from '../clipboard-text.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OSC bridge — intercepts xterm OSC sequences that remote applications use to
|
|
5
|
+
* control the local client. Supports:
|
|
6
|
+
* - OSC 52: write to the local clipboard from the remote shell.
|
|
7
|
+
* - OSC 777: trigger a local browser notification from the remote shell.
|
|
8
|
+
*
|
|
9
|
+
* ShellFish parity: remote-to-local clipboard and notifications.
|
|
10
|
+
*/
|
|
11
|
+
export function init(T1) {
|
|
12
|
+
T1.onTermReady((term) => {
|
|
13
|
+
// xterm.js does not expose a clean OSC hook, but it parses and ignores
|
|
14
|
+
// unknown OSC sequences. We intercept raw output before it is written,
|
|
15
|
+
// look for the sequences, strip them, and perform the local action.
|
|
16
|
+
const original = term.write.bind(term);
|
|
17
|
+
const osc52Re = /\x1b\]52;[cCsS];([A-Za-z0-9+\/=]*)\x07/g;
|
|
18
|
+
const osc777Re = /\x1b\]777;([^\x07]*)\x07/g;
|
|
19
|
+
|
|
20
|
+
term.write = function (data) {
|
|
21
|
+
if (typeof data !== 'string') return original(data);
|
|
22
|
+
|
|
23
|
+
// OSC 52 — set clipboard. Data is base64.
|
|
24
|
+
let m;
|
|
25
|
+
while ((m = osc52Re.exec(data)) !== null) {
|
|
26
|
+
try {
|
|
27
|
+
const text = decodeClipboardText(m[1]);
|
|
28
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
29
|
+
navigator.clipboard.writeText(text).catch(() => {});
|
|
30
|
+
}
|
|
31
|
+
T1.toast('Clipboard updated by remote');
|
|
32
|
+
} catch (_) {}
|
|
33
|
+
}
|
|
34
|
+
osc52Re.lastIndex = 0;
|
|
35
|
+
|
|
36
|
+
// OSC 777 — notification. Payload is free-form text.
|
|
37
|
+
while ((m = osc777Re.exec(data)) !== null) {
|
|
38
|
+
try {
|
|
39
|
+
const payload = m[1];
|
|
40
|
+
const title = 'Townmouse';
|
|
41
|
+
const body = payload.startsWith('notify;') ? payload.slice(7) : payload;
|
|
42
|
+
if ('Notification' in window && Notification.permission === 'granted') {
|
|
43
|
+
new Notification(title, { body, tag: 'terminalone' });
|
|
44
|
+
} else if ('Notification' in window && Notification.permission !== 'denied') {
|
|
45
|
+
Notification.requestPermission().then((p) => {
|
|
46
|
+
if (p === 'granted') new Notification(title, { body, tag: 'terminalone' });
|
|
47
|
+
}).catch(() => {});
|
|
48
|
+
}
|
|
49
|
+
T1.toast(`Notification: ${body}`, 'info');
|
|
50
|
+
} catch (_) {}
|
|
51
|
+
}
|
|
52
|
+
osc777Re.lastIndex = 0;
|
|
53
|
+
|
|
54
|
+
// Strip the sequences from the visible stream.
|
|
55
|
+
const cleaned = data.replace(osc52Re, '').replace(osc777Re, '');
|
|
56
|
+
return original(cleaned);
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome toggle + landscape focus (iPhone + iPad).
|
|
3
|
+
*
|
|
4
|
+
* Provides a persistent, always-on-screen floating toggle that collapses the
|
|
5
|
+
* top header and bottom footer chrome to maximize terminal space. The on-screen
|
|
6
|
+
* control bar (keybar) is NEVER hidden — it stays visible at the bottom on every
|
|
7
|
+
* viewport size and orientation.
|
|
8
|
+
*
|
|
9
|
+
* The toggle is centered at the top and clamped inside the safe-area insets, so
|
|
10
|
+
* a notch / Dynamic Island can never push it off-screen (the prior version used
|
|
11
|
+
* `right: 12px`, which clipped off the right edge on notched devices in
|
|
12
|
+
* landscape). It is a >=44pt touch target per Apple HIG.
|
|
13
|
+
*/
|
|
14
|
+
export function init(T1) {
|
|
15
|
+
if (T1.device !== 'iphone' && T1.device !== 'ipad') return;
|
|
16
|
+
|
|
17
|
+
T1.ui.addStyle(`
|
|
18
|
+
/* Collapsed chrome hides header + footer + feature toolbar — but NEVER the
|
|
19
|
+
keybar (control bar), which must stay visible at the bottom always. */
|
|
20
|
+
body.t1-chrome-collapsed .terminal-header,
|
|
21
|
+
body.t1-chrome-collapsed .terminal-footer,
|
|
22
|
+
body.t1-chrome-collapsed .t1toolbar {
|
|
23
|
+
display: none !important;
|
|
24
|
+
}
|
|
25
|
+
/* Always-on-screen chrome toggle. Centered + safe-area clamped so it can
|
|
26
|
+
never sit off-screen or under a notch on any iPhone/iPad viewport. */
|
|
27
|
+
.t1-chrome-fab {
|
|
28
|
+
display: none;
|
|
29
|
+
position: relative;
|
|
30
|
+
top: auto;
|
|
31
|
+
left: auto;
|
|
32
|
+
transform: none;
|
|
33
|
+
z-index: 350;
|
|
34
|
+
min-width: 44px;
|
|
35
|
+
min-height: 44px;
|
|
36
|
+
padding: 8px 18px;
|
|
37
|
+
font-size: 12px;
|
|
38
|
+
line-height: 1;
|
|
39
|
+
border-radius: 999px;
|
|
40
|
+
background: var(--ui-elevated);
|
|
41
|
+
border: 1px solid var(--ui-border);
|
|
42
|
+
color: var(--ui-fg);
|
|
43
|
+
box-shadow: none;
|
|
44
|
+
opacity: 1; margin: 6px 8px; align-self: flex-start; flex-shrink: 0;
|
|
45
|
+
-webkit-tap-highlight-color: transparent;
|
|
46
|
+
touch-action: manipulation;
|
|
47
|
+
}
|
|
48
|
+
.t1-chrome-fab:active { opacity: 1; }
|
|
49
|
+
body[data-device="iphone"] .t1-chrome-fab,
|
|
50
|
+
body[data-device="ipad"] .t1-chrome-fab {
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
}
|
|
55
|
+
`);
|
|
56
|
+
|
|
57
|
+
const fab = document.createElement('button');
|
|
58
|
+
fab.type = 'button';
|
|
59
|
+
fab.className = 't1-chrome-fab';
|
|
60
|
+
document.querySelector('.app-shell').prepend(fab);
|
|
61
|
+
|
|
62
|
+
// On short touch screens, secondary tools open in a dedicated sheet instead
|
|
63
|
+
// of taking the terminal's remaining height. The original toolbar stays intact.
|
|
64
|
+
const tools = document.createElement('button');
|
|
65
|
+
tools.type = 'button';
|
|
66
|
+
tools.className = 't1-tools-toggle';
|
|
67
|
+
tools.textContent = 'Tools';
|
|
68
|
+
tools.setAttribute('aria-controls', 't1toolbar');
|
|
69
|
+
tools.setAttribute('aria-expanded', 'false');
|
|
70
|
+
document.querySelector('.terminal-header').appendChild(tools);
|
|
71
|
+
const toolbar = document.getElementById('t1toolbar');
|
|
72
|
+
const done = document.createElement('button');
|
|
73
|
+
done.type = 'button';
|
|
74
|
+
done.className = 't1-tools-done';
|
|
75
|
+
done.textContent = 'Done';
|
|
76
|
+
toolbar.prepend(done);
|
|
77
|
+
const backdrop = document.createElement('div');
|
|
78
|
+
backdrop.className = 't1-tools-backdrop';
|
|
79
|
+
document.querySelector('.app-shell').appendChild(backdrop);
|
|
80
|
+
let toolsOpen = false;
|
|
81
|
+
function setToolsOpen(open) {
|
|
82
|
+
toolsOpen = open;
|
|
83
|
+
document.body.classList.toggle('t1-tools-open', open);
|
|
84
|
+
tools.setAttribute('aria-expanded', String(open));
|
|
85
|
+
toolbar.setAttribute('role', open ? 'dialog' : 'toolbar');
|
|
86
|
+
if (open) toolbar.setAttribute('aria-modal', 'true');
|
|
87
|
+
else toolbar.removeAttribute('aria-modal');
|
|
88
|
+
for (const child of document.querySelector('.app-shell').children) {
|
|
89
|
+
if (child !== toolbar && child !== backdrop) child.inert = open;
|
|
90
|
+
}
|
|
91
|
+
if (open) done.focus(); else tools.focus();
|
|
92
|
+
T1.fit();
|
|
93
|
+
}
|
|
94
|
+
tools.addEventListener('click', () => setToolsOpen(!toolsOpen));
|
|
95
|
+
done.addEventListener('click', () => setToolsOpen(false));
|
|
96
|
+
toolbar.addEventListener('click', e => {
|
|
97
|
+
if (toolsOpen && e.target.closest('button') && e.target.closest('button') !== done) setToolsOpen(false);
|
|
98
|
+
}, true);
|
|
99
|
+
backdrop.addEventListener('click', () => setToolsOpen(false));
|
|
100
|
+
document.addEventListener('keydown', e => {
|
|
101
|
+
if (!toolsOpen) return;
|
|
102
|
+
if (e.key === 'Escape') { e.preventDefault(); setToolsOpen(false); }
|
|
103
|
+
if (e.key === 'Tab') {
|
|
104
|
+
const buttons = [...toolbar.querySelectorAll('button:not(:disabled)')];
|
|
105
|
+
const first = buttons[0], last = buttons[buttons.length - 1];
|
|
106
|
+
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
107
|
+
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const shortScreen = matchMedia('(max-height: 500px)');
|
|
111
|
+
shortScreen.addEventListener('change', () => { if (toolsOpen) setToolsOpen(false); });
|
|
112
|
+
T1.ui.addStyle(`
|
|
113
|
+
.t1-tools-toggle, .t1-tools-done, .t1-tools-backdrop { display: none; }
|
|
114
|
+
@media (max-height: 500px) {
|
|
115
|
+
.t1-tools-toggle { display: inline-flex; align-items: center; }
|
|
116
|
+
body:not(.t1-tools-open) .t1toolbar { display: none; }
|
|
117
|
+
body.t1-tools-open .t1toolbar {
|
|
118
|
+
display: flex !important; position: fixed; inset: 12px; z-index: 450;
|
|
119
|
+
padding: 16px; border: 1px solid var(--ui-border); border-radius: 12px;
|
|
120
|
+
align-content: flex-start; align-items: flex-start; overflow-y: auto;
|
|
121
|
+
}
|
|
122
|
+
body.t1-tools-open .t1-tools-done { display: inline-flex; align-items: center; }
|
|
123
|
+
body.t1-tools-open .t1-tools-backdrop {
|
|
124
|
+
display: block; position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 440;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
`);
|
|
128
|
+
|
|
129
|
+
let collapsed = false;
|
|
130
|
+
function render() {
|
|
131
|
+
document.body.classList.toggle('t1-chrome-collapsed', collapsed);
|
|
132
|
+
if (collapsed) document.querySelector('.app-shell').prepend(fab);
|
|
133
|
+
else document.querySelector('.terminal-header').appendChild(fab);
|
|
134
|
+
fab.textContent = collapsed ? 'Show bars' : 'Hide bars';
|
|
135
|
+
fab.setAttribute(
|
|
136
|
+
'aria-label',
|
|
137
|
+
collapsed ? 'Show header and footer' : 'Hide header and footer for more terminal space'
|
|
138
|
+
);
|
|
139
|
+
fab.setAttribute('aria-pressed', String(collapsed));
|
|
140
|
+
}
|
|
141
|
+
function setCollapsed(v) {
|
|
142
|
+
collapsed = !!v;
|
|
143
|
+
render();
|
|
144
|
+
T1.fit();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fab.addEventListener('click', () => setCollapsed(!collapsed));
|
|
148
|
+
render();
|
|
149
|
+
|
|
150
|
+
// Surface for automated tests + other features.
|
|
151
|
+
window.__terminalOneChrome = {
|
|
152
|
+
fab,
|
|
153
|
+
isCollapsed: () => collapsed,
|
|
154
|
+
setCollapsed,
|
|
155
|
+
toggle: () => setCollapsed(!collapsed)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recent items — quick palette of the last commands typed in this terminal.
|
|
3
|
+
* Persists in localStorage and integrates with the command history collected by
|
|
4
|
+
* the undo/redo feature. Adds a "Recent" toolbar button that opens a dropdown.
|
|
5
|
+
*/
|
|
6
|
+
const HISTORY_KEY = 'terminalone.commandHistory';
|
|
7
|
+
const MAX = 15;
|
|
8
|
+
|
|
9
|
+
export function init(T1) {
|
|
10
|
+
const tb = T1.ui.toolbar();
|
|
11
|
+
if (!tb) return;
|
|
12
|
+
|
|
13
|
+
T1.ui.addStyle(`
|
|
14
|
+
.t1recent-pop {
|
|
15
|
+
position: absolute;
|
|
16
|
+
bottom: 100%;
|
|
17
|
+
right: 8px;
|
|
18
|
+
z-index: 350;
|
|
19
|
+
min-width: 220px;
|
|
20
|
+
max-width: 80vw;
|
|
21
|
+
max-height: 60vh;
|
|
22
|
+
overflow-y: auto;
|
|
23
|
+
background: var(--ui-elevated);
|
|
24
|
+
border: 1px solid var(--ui-border);
|
|
25
|
+
border-radius: 8px;
|
|
26
|
+
box-shadow: 0 -8px 32px rgba(0,0,0,0.35);
|
|
27
|
+
display: none;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
padding: 6px;
|
|
30
|
+
}
|
|
31
|
+
.t1recent-pop.open { display: flex; }
|
|
32
|
+
.t1recent-item {
|
|
33
|
+
text-align: left;
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
text-overflow: ellipsis;
|
|
37
|
+
margin-bottom: 3px;
|
|
38
|
+
}
|
|
39
|
+
.t1recent-empty { padding: 8px; color: var(--ui-muted); font-size: 12px; }
|
|
40
|
+
`);
|
|
41
|
+
|
|
42
|
+
const pop = document.createElement('div');
|
|
43
|
+
pop.className = 't1recent-pop';
|
|
44
|
+
(T1.ui.appShell() || document.body).appendChild(pop);
|
|
45
|
+
|
|
46
|
+
function readHistory() {
|
|
47
|
+
try {
|
|
48
|
+
const v = JSON.parse(T1.storage.get(HISTORY_KEY, '[]'));
|
|
49
|
+
return Array.isArray(v) ? v.slice(-MAX).reverse() : [];
|
|
50
|
+
} catch (_) { return []; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function render() {
|
|
54
|
+
const list = readHistory();
|
|
55
|
+
pop.innerHTML = '';
|
|
56
|
+
if (!list.length) {
|
|
57
|
+
const empty = document.createElement('div');
|
|
58
|
+
empty.className = 't1recent-empty';
|
|
59
|
+
empty.textContent = 'No recent commands yet';
|
|
60
|
+
pop.appendChild(empty);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const cmd of list) {
|
|
64
|
+
const b = T1.ui.makeButton(cmd, `Insert: ${cmd}`, () => {
|
|
65
|
+
T1.sendData(cmd);
|
|
66
|
+
pop.classList.remove('open');
|
|
67
|
+
});
|
|
68
|
+
b.classList.add('t1recent-item');
|
|
69
|
+
pop.appendChild(b);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const toggle = T1.ui.makeButton('Recent', 'Recent commands', () => {
|
|
74
|
+
render();
|
|
75
|
+
pop.classList.toggle('open');
|
|
76
|
+
});
|
|
77
|
+
tb.appendChild(toggle);
|
|
78
|
+
|
|
79
|
+
// Close when clicking outside.
|
|
80
|
+
document.addEventListener('click', (e) => {
|
|
81
|
+
if (!pop.contains(e.target) && e.target !== toggle) pop.classList.remove('open');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Keyboard shortcut Ctrl/Cmd+Shift+R opens recent palette.
|
|
85
|
+
document.addEventListener('keydown', (e) => {
|
|
86
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
87
|
+
if (mod && e.shiftKey && (e.key === 'r' || e.key === 'R')) {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
render();
|
|
90
|
+
pop.classList.toggle('open');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// React to new history being written by autosaving history elsewhere.
|
|
95
|
+
let lastKnown = JSON.stringify(readHistory());
|
|
96
|
+
setInterval(() => {
|
|
97
|
+
const cur = JSON.stringify(readHistory());
|
|
98
|
+
if (cur !== lastKnown && pop.classList.contains('open')) { lastKnown = cur; render(); }
|
|
99
|
+
}, 2000);
|
|
100
|
+
}
|