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,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrollback search — find text in the terminal buffer via the xterm
|
|
3
|
+
* SearchAddon. A fresh addon is attached on every (re)connect because the
|
|
4
|
+
* terminal is recreated. The search box is a small overlay toggled from the
|
|
5
|
+
* feature bar; Enter finds next, Shift+Enter finds previous, Esc closes.
|
|
6
|
+
*
|
|
7
|
+
* v2 adds case-sensitive and regex toggles so the global search behaves like
|
|
8
|
+
* a modern editor find panel.
|
|
9
|
+
*/
|
|
10
|
+
import { SearchAddon } from '/node_modules/@xterm/addon-search/lib/addon-search.mjs';
|
|
11
|
+
|
|
12
|
+
export function init(T1) {
|
|
13
|
+
const tb = T1.ui.toolbar();
|
|
14
|
+
if (!tb) return;
|
|
15
|
+
|
|
16
|
+
let addon = null;
|
|
17
|
+
T1.onTermReady((term) => {
|
|
18
|
+
try { addon = new SearchAddon(); term.loadAddon(addon); }
|
|
19
|
+
catch (_) { addon = null; }
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
T1.ui.addStyle(`
|
|
23
|
+
.t1search-box {
|
|
24
|
+
position: absolute;
|
|
25
|
+
top: 8px; right: 8px;
|
|
26
|
+
z-index: 250;
|
|
27
|
+
display: none;
|
|
28
|
+
gap: 4px;
|
|
29
|
+
align-items: center;
|
|
30
|
+
padding: 6px;
|
|
31
|
+
background: var(--ui-elevated);
|
|
32
|
+
border: 1px solid var(--ui-border);
|
|
33
|
+
border-radius: 8px;
|
|
34
|
+
box-shadow: 0 4px 16px rgba(0,0,0,0.35);
|
|
35
|
+
}
|
|
36
|
+
.t1search-box.open { display: flex; }
|
|
37
|
+
.t1search-input {
|
|
38
|
+
background: var(--ui-bg);
|
|
39
|
+
border: 1px solid var(--ui-border);
|
|
40
|
+
border-radius: 6px;
|
|
41
|
+
color: var(--ui-fg);
|
|
42
|
+
font-family: inherit;
|
|
43
|
+
font-size: 13px;
|
|
44
|
+
padding: 4px 8px;
|
|
45
|
+
width: 180px;
|
|
46
|
+
outline: none;
|
|
47
|
+
}
|
|
48
|
+
.t1search-input:focus { border-color: var(--ui-accent); }
|
|
49
|
+
.t1search-toggle {
|
|
50
|
+
min-width: 28px;
|
|
51
|
+
padding: 0 6px;
|
|
52
|
+
}
|
|
53
|
+
.t1search-toggle.active { background: var(--ui-accent); color: var(--ui-on-accent, #14171b); }
|
|
54
|
+
`);
|
|
55
|
+
|
|
56
|
+
const state = { caseSensitive: false, regex: false };
|
|
57
|
+
|
|
58
|
+
const box = document.createElement('div');
|
|
59
|
+
box.className = 't1search-box';
|
|
60
|
+
|
|
61
|
+
const input = document.createElement('input');
|
|
62
|
+
input.type = 'text';
|
|
63
|
+
input.className = 't1search-input';
|
|
64
|
+
input.placeholder = 'Search scrollback';
|
|
65
|
+
input.setAttribute('aria-label', 'Search scrollback');
|
|
66
|
+
box.appendChild(input);
|
|
67
|
+
|
|
68
|
+
const searchOptions = () => ({
|
|
69
|
+
caseSensitive: state.caseSensitive,
|
|
70
|
+
regex: state.regex,
|
|
71
|
+
incremental: false,
|
|
72
|
+
decorate: true
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const next = () => {
|
|
76
|
+
if (addon && input.value) {
|
|
77
|
+
try { addon.findNext(input.value, searchOptions()); }
|
|
78
|
+
catch (_) {
|
|
79
|
+
try { addon.findNext(input.value); } catch (_) {}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const prev = () => {
|
|
84
|
+
if (addon && input.value) {
|
|
85
|
+
try { addon.findPrevious(input.value, searchOptions()); }
|
|
86
|
+
catch (_) {
|
|
87
|
+
try { addon.findPrevious(input.value); } catch (_) {}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const makeToggle = (label, title, key) => {
|
|
93
|
+
const b = T1.ui.makeButton(label, title, () => {
|
|
94
|
+
state[key] = !state[key];
|
|
95
|
+
b.classList.toggle('active', state[key]);
|
|
96
|
+
if (input.value) next();
|
|
97
|
+
});
|
|
98
|
+
b.classList.add('t1search-toggle');
|
|
99
|
+
return b;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const caseToggle = makeToggle('Aa', 'Case sensitive', 'caseSensitive');
|
|
103
|
+
const regexToggle = makeToggle('.*', 'Regular expression', 'regex');
|
|
104
|
+
|
|
105
|
+
box.appendChild(caseToggle);
|
|
106
|
+
box.appendChild(regexToggle);
|
|
107
|
+
box.appendChild(T1.ui.makeButton('\u25c0', 'Previous match', prev));
|
|
108
|
+
box.appendChild(T1.ui.makeButton('\u25b6', 'Next match', next));
|
|
109
|
+
box.appendChild(T1.ui.makeButton('x', 'Close search', () => box.classList.remove('open')));
|
|
110
|
+
|
|
111
|
+
input.addEventListener('keydown', (e) => {
|
|
112
|
+
if (e.key === 'Enter') { e.preventDefault(); if (e.shiftKey) prev(); else next(); }
|
|
113
|
+
else if (e.key === 'Escape') { box.classList.remove('open'); }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const shell = T1.ui.appShell() || document.body;
|
|
117
|
+
// The overlay is absolutely positioned; ensure the shell is a containing block.
|
|
118
|
+
if (getComputedStyle(shell).position === 'static') shell.style.position = 'relative';
|
|
119
|
+
shell.appendChild(box);
|
|
120
|
+
|
|
121
|
+
const toggle = T1.ui.makeButton('Search', 'Search scrollback (Ctrl+Shift+F)', () => {
|
|
122
|
+
const open = box.classList.toggle('open');
|
|
123
|
+
if (open) setTimeout(() => input.focus(), 0);
|
|
124
|
+
});
|
|
125
|
+
tb.appendChild(toggle);
|
|
126
|
+
|
|
127
|
+
// Global keyboard shortcut is handled by keyboard-shortcuts.mjs via t1:action.
|
|
128
|
+
window.addEventListener('t1:action', (e) => {
|
|
129
|
+
if ((e.detail || {}).action === 'toggle-search') {
|
|
130
|
+
const open = box.classList.toggle('open');
|
|
131
|
+
if (open) setTimeout(() => input.focus(), 0);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Biometric / PIN session lock.
|
|
3
|
+
*
|
|
4
|
+
* Optional per-session lock. Uses WebAuthn / Credential Management on desktop
|
|
5
|
+
* where available; falls back to a simple PIN modal on phone/tablet.
|
|
6
|
+
* Locks the terminal with a blur overlay until authenticated.
|
|
7
|
+
*/
|
|
8
|
+
const LS_PIN = 'terminalone.sessionPin';
|
|
9
|
+
const LS_LOCKED = 'terminalone.sessionLocked';
|
|
10
|
+
|
|
11
|
+
export function init(T1) {
|
|
12
|
+
T1.ui.addStyle(`
|
|
13
|
+
.t1-lock-overlay {
|
|
14
|
+
position: fixed; inset: 0;
|
|
15
|
+
backdrop-filter: blur(12px);
|
|
16
|
+
background: rgba(0,0,0,0.55);
|
|
17
|
+
z-index: 600;
|
|
18
|
+
display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
|
|
19
|
+
}
|
|
20
|
+
.t1-lock-overlay.active { display: flex; }
|
|
21
|
+
.t1-lock-overlay h3 { color: #fff; margin: 0; font-size: 16px; }
|
|
22
|
+
.t1-lock-overlay input {
|
|
23
|
+
width: 180px; padding: 10px; font-size: 16px; text-align: center;
|
|
24
|
+
border-radius: 6px; border: 1px solid var(--ui-border); background: var(--ui-bg); color: var(--ui-fg);
|
|
25
|
+
}
|
|
26
|
+
.t1-lock-overlay button {
|
|
27
|
+
padding: 8px 18px; border-radius: 6px; border: none;
|
|
28
|
+
background: var(--ui-accent); color: var(--ui-on-accent, #14171b); cursor: pointer; font-weight: 600;
|
|
29
|
+
}
|
|
30
|
+
.t1-lock-overlay .hint { color: #aaa; font-size: 12px; }
|
|
31
|
+
`);
|
|
32
|
+
|
|
33
|
+
const overlay = document.createElement('div');
|
|
34
|
+
overlay.className = 't1-lock-overlay';
|
|
35
|
+
overlay.setAttribute('role', 'dialog');
|
|
36
|
+
overlay.setAttribute('aria-modal', 'true');
|
|
37
|
+
overlay.setAttribute('aria-label', 'Unlock session');
|
|
38
|
+
overlay.innerHTML = `
|
|
39
|
+
<h3>Session locked</h3>
|
|
40
|
+
<input type="password" maxlength="8" inputmode="numeric" placeholder="PIN" aria-label="PIN" />
|
|
41
|
+
<button type="button">Unlock</button>
|
|
42
|
+
<span class="hint">Set a PIN in settings to protect this session.</span>
|
|
43
|
+
`;
|
|
44
|
+
document.body.appendChild(overlay);
|
|
45
|
+
|
|
46
|
+
const input = overlay.querySelector('input');
|
|
47
|
+
const btn = overlay.querySelector('button');
|
|
48
|
+
|
|
49
|
+
function setPin(pin) { T1.storage.set(LS_PIN, pin); }
|
|
50
|
+
function getPin() { return T1.storage.get(LS_PIN, ''); }
|
|
51
|
+
function lock() { T1.storage.set(LS_LOCKED, '1'); overlay.classList.add('active'); }
|
|
52
|
+
function unlock() {
|
|
53
|
+
const stored = getPin();
|
|
54
|
+
if (stored && input.value !== stored) {
|
|
55
|
+
T1.toast('Wrong PIN', 'error');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
T1.storage.del(LS_LOCKED);
|
|
59
|
+
overlay.classList.remove('active');
|
|
60
|
+
input.value = '';
|
|
61
|
+
T1.toast('Unlocked');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
btn.addEventListener('click', unlock);
|
|
65
|
+
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') unlock(); });
|
|
66
|
+
|
|
67
|
+
// NOTE: WebAuthn credential creation/verification is intentionally not
|
|
68
|
+
// wired here — it requires a secure context (HTTPS or localhost) plus a
|
|
69
|
+
// registered credential, neither of which a generic browser terminal can
|
|
70
|
+
// assume. This feature degrades to a local PIN. The PIN is stored in
|
|
71
|
+
// same-origin localStorage (cleartext) — acceptable threat model for a
|
|
72
|
+
// single-user local terminal; do NOT reuse this pattern for multi-user or
|
|
73
|
+
// remote-deployed apps.
|
|
74
|
+
function tryWebAuthn() { return Promise.resolve(false); }
|
|
75
|
+
|
|
76
|
+
// Auto-lock if previously locked.
|
|
77
|
+
if (T1.storage.get(LS_LOCKED, '0') === '1') lock();
|
|
78
|
+
|
|
79
|
+
// Toolbar button.
|
|
80
|
+
const lockBtn = T1.ui.makeButton('Lock', 'Lock this session', () => {
|
|
81
|
+
if (!getPin()) {
|
|
82
|
+
let pin = prompt('Create a 4-8 digit PIN');
|
|
83
|
+
if (!pin) return;
|
|
84
|
+
pin = pin.trim();
|
|
85
|
+
if (!/^\d{4,8}$/.test(pin)) {
|
|
86
|
+
T1.toast('PIN must be 4-8 digits', 'warn');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
setPin(pin);
|
|
90
|
+
}
|
|
91
|
+
lock();
|
|
92
|
+
});
|
|
93
|
+
T1.ui.toolbar().appendChild(lockBtn);
|
|
94
|
+
|
|
95
|
+
window.__terminalOneSessionLock = { lock, unlock, setPin, getPin, overlay, tryWebAuthn };
|
|
96
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session manager — multi-session tabs and session rename for TerminalOne.
|
|
3
|
+
*
|
|
4
|
+
* ShellFish parity: switch between named sessions, rename a session.
|
|
5
|
+
*
|
|
6
|
+
* Note: TerminalOne currently has one live WebSocket per page. This module
|
|
7
|
+
* keeps a small client-side registry of sessions and lets the user switch by
|
|
8
|
+
* opening the named session id. The server supports resume, so switching to
|
|
9
|
+
* an existing session re-attaches the PTY.
|
|
10
|
+
*/
|
|
11
|
+
const LS_NAMES = 'terminalone.sessionNames';
|
|
12
|
+
const MAX_SESSIONS = 5;
|
|
13
|
+
|
|
14
|
+
export function init(T1) {
|
|
15
|
+
const header = document.querySelector('.terminal-header');
|
|
16
|
+
if (!header) return;
|
|
17
|
+
|
|
18
|
+
const names = readNames();
|
|
19
|
+
let activeId = null;
|
|
20
|
+
let switchCallback = null;
|
|
21
|
+
|
|
22
|
+
T1.ui.addStyle(`
|
|
23
|
+
.t1session-tabs {
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
gap: 4px;
|
|
27
|
+
margin-left: 12px;
|
|
28
|
+
flex: 0 1 auto;
|
|
29
|
+
min-width: 0;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
}
|
|
32
|
+
.t1session-tab {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 4px;
|
|
36
|
+
padding: 3px 8px;
|
|
37
|
+
font-size: 11px;
|
|
38
|
+
background: var(--ui-bg);
|
|
39
|
+
border: 1px solid var(--ui-border);
|
|
40
|
+
border-radius: 4px;
|
|
41
|
+
color: var(--ui-muted);
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
user-select: none;
|
|
45
|
+
}
|
|
46
|
+
.t1session-tab.active {
|
|
47
|
+
color: var(--ui-fg);
|
|
48
|
+
border-color: var(--ui-accent);
|
|
49
|
+
}
|
|
50
|
+
.t1session-tab input {
|
|
51
|
+
width: 80px;
|
|
52
|
+
background: transparent;
|
|
53
|
+
border: none;
|
|
54
|
+
color: inherit;
|
|
55
|
+
font: inherit;
|
|
56
|
+
padding: 0;
|
|
57
|
+
outline: none;
|
|
58
|
+
}
|
|
59
|
+
.t1session-new {
|
|
60
|
+
font-size: 14px;
|
|
61
|
+
line-height: 1;
|
|
62
|
+
padding: 3px 6px;
|
|
63
|
+
}
|
|
64
|
+
`);
|
|
65
|
+
|
|
66
|
+
const tabsEl = document.createElement('div');
|
|
67
|
+
tabsEl.className = 't1session-tabs';
|
|
68
|
+
// Insert after the title.
|
|
69
|
+
const title = header.querySelector('.terminal-title');
|
|
70
|
+
title?.parentNode?.insertBefore(tabsEl, title.nextSibling);
|
|
71
|
+
|
|
72
|
+
function readNames() {
|
|
73
|
+
try { return JSON.parse(T1.storage.get(LS_NAMES, '{}')); } catch (_) { return {}; }
|
|
74
|
+
}
|
|
75
|
+
function writeNames(n) {
|
|
76
|
+
try { T1.storage.set(LS_NAMES, JSON.stringify(n)); } catch (_) {}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function setName(id, newName) {
|
|
80
|
+
if (!id) return;
|
|
81
|
+
names[id] = newName || id.slice(0, 8);
|
|
82
|
+
writeNames(names);
|
|
83
|
+
render();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function render() {
|
|
87
|
+
tabsEl.innerHTML = '';
|
|
88
|
+
// Always show a tab for the active session.
|
|
89
|
+
const ids = Object.keys(names);
|
|
90
|
+
if (activeId && !names[activeId]) {
|
|
91
|
+
names[activeId] = activeId.slice(0, 8);
|
|
92
|
+
writeNames(names);
|
|
93
|
+
}
|
|
94
|
+
for (const id of ids.slice(-MAX_SESSIONS)) {
|
|
95
|
+
const tab = document.createElement('div');
|
|
96
|
+
tab.className = `t1session-tab ${id === activeId ? 'active' : ''}`;
|
|
97
|
+
const span = document.createElement('span');
|
|
98
|
+
span.textContent = names[id] || id.slice(0, 8);
|
|
99
|
+
tab.appendChild(span);
|
|
100
|
+
tab.addEventListener('click', (e) => {
|
|
101
|
+
if (e.target === span) {
|
|
102
|
+
if (id !== activeId && typeof switchCallback === 'function') switchCallback(id);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
tab.addEventListener('dblclick', () => {
|
|
106
|
+
const input = document.createElement('input');
|
|
107
|
+
input.value = span.textContent;
|
|
108
|
+
tab.replaceChild(input, span);
|
|
109
|
+
input.focus();
|
|
110
|
+
input.select();
|
|
111
|
+
const finish = () => { setName(id, input.value); };
|
|
112
|
+
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') finish(); if (e.key === 'Escape') render(); });
|
|
113
|
+
input.addEventListener('blur', finish);
|
|
114
|
+
});
|
|
115
|
+
tabsEl.appendChild(tab);
|
|
116
|
+
}
|
|
117
|
+
const plus = document.createElement('button');
|
|
118
|
+
plus.className = 't1session-tab t1session-new';
|
|
119
|
+
plus.title = 'New session';
|
|
120
|
+
plus.textContent = '+';
|
|
121
|
+
plus.addEventListener('click', () => {
|
|
122
|
+
if (typeof switchCallback === 'function') switchCallback('__new__');
|
|
123
|
+
});
|
|
124
|
+
tabsEl.appendChild(plus);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Listen for active session changes.
|
|
128
|
+
const infoEl = document.getElementById('sessionInfo');
|
|
129
|
+
if (infoEl) {
|
|
130
|
+
const observer = new MutationObserver(() => {
|
|
131
|
+
const text = infoEl.textContent || '';
|
|
132
|
+
const m = text.match(/session\s+([a-f0-9\-]+)/);
|
|
133
|
+
if (m) {
|
|
134
|
+
activeId = m[1];
|
|
135
|
+
if (!names[activeId]) setName(activeId, activeId.slice(0, 8));
|
|
136
|
+
else render();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
observer.observe(infoEl, { childList: true });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Allow other modules to register the switch handler.
|
|
143
|
+
window.__terminalOne = window.__terminalOne || {};
|
|
144
|
+
window.__terminalOne.setSessionSwitchCallback = (cb) => { switchCallback = cb; };
|
|
145
|
+
window.__terminalOne.renameSession = (id, name) => setName(id, name);
|
|
146
|
+
window.__terminalOne.sessionNames = () => ({ ...names });
|
|
147
|
+
|
|
148
|
+
render();
|
|
149
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-device settings export/import cloud hook (local-first).
|
|
3
|
+
*
|
|
4
|
+
* Extends the settings import/export with a sync token / QR code for easy
|
|
5
|
+
* transfer. Settings are exported as JSON; import validates schema version.
|
|
6
|
+
*/
|
|
7
|
+
const SCHEMA_VERSION = 2;
|
|
8
|
+
const LS_SYNC_TOKEN = 'terminalone.syncToken';
|
|
9
|
+
|
|
10
|
+
export function init(T1) {
|
|
11
|
+
T1.ui.addStyle(`
|
|
12
|
+
.t1-sync-token { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 13px; word-break: break-all; }
|
|
13
|
+
.t1-qr-host { display: inline-block; padding: 6px; background: #fff; border-radius: 4px; }
|
|
14
|
+
`);
|
|
15
|
+
|
|
16
|
+
function collectSettings() {
|
|
17
|
+
return {
|
|
18
|
+
schemaVersion: SCHEMA_VERSION,
|
|
19
|
+
exportedAt: new Date().toISOString(),
|
|
20
|
+
theme: T1.storage.get('terminalone.theme', 'tokyo-night'),
|
|
21
|
+
style: T1.storage.get('terminalone.style', 'default'),
|
|
22
|
+
cursorStyle: T1.storage.get('terminalone.cursorStyle', 'block'),
|
|
23
|
+
cursorBlink: T1.storage.get('terminalone.cursorBlink', 'true') === 'true',
|
|
24
|
+
bell: T1.storage.get('terminalone.bell', 'false') === 'true',
|
|
25
|
+
scrollback: parseInt(T1.storage.get('terminalone.scrollback', '10000'), 10),
|
|
26
|
+
fontSize: parseInt(T1.storage.get('terminalone.fontSize', '14'), 10)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function validate(data) {
|
|
31
|
+
if (!data || typeof data !== 'object') return { ok: false, reason: 'not an object' };
|
|
32
|
+
if (typeof data.schemaVersion !== 'number') return { ok: false, reason: 'missing schemaVersion' };
|
|
33
|
+
if (data.schemaVersion > SCHEMA_VERSION) return { ok: false, reason: `schemaVersion ${data.schemaVersion} > supported ${SCHEMA_VERSION}` };
|
|
34
|
+
if (data.theme && typeof data.theme !== 'string') return { ok: false, reason: 'invalid theme' };
|
|
35
|
+
return { ok: true };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function importSettings(data) {
|
|
39
|
+
const v = validate(data);
|
|
40
|
+
if (!v.ok) throw new Error(v.reason);
|
|
41
|
+
if (data.theme) T1.storage.set('terminalone.theme', data.theme);
|
|
42
|
+
if (data.style) T1.storage.set('terminalone.style', data.style);
|
|
43
|
+
if (data.cursorStyle) T1.storage.set('terminalone.cursorStyle', data.cursorStyle);
|
|
44
|
+
if (typeof data.cursorBlink === 'boolean') T1.storage.set('terminalone.cursorBlink', String(data.cursorBlink));
|
|
45
|
+
if (typeof data.bell === 'boolean') T1.storage.set('terminalone.bell', String(data.bell));
|
|
46
|
+
if (data.scrollback) T1.storage.set('terminalone.scrollback', String(data.scrollback));
|
|
47
|
+
if (data.fontSize) T1.storage.set('terminalone.fontSize', String(data.fontSize));
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function generateToken() {
|
|
52
|
+
const chars = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
|
|
53
|
+
let token = '';
|
|
54
|
+
for (let i = 0; i < 12; i++) token += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
55
|
+
T1.storage.set(LS_SYNC_TOKEN, token);
|
|
56
|
+
return token;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getToken() { return T1.storage.get(LS_SYNC_TOKEN, '') || generateToken(); }
|
|
60
|
+
|
|
61
|
+
// Toolbar button: export with token.
|
|
62
|
+
const exportBtn = T1.ui.makeButton('Sync', 'Export settings with sync token', () => {
|
|
63
|
+
const payload = collectSettings();
|
|
64
|
+
payload.syncToken = getToken();
|
|
65
|
+
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
|
|
66
|
+
const a = document.createElement('a');
|
|
67
|
+
a.href = URL.createObjectURL(blob);
|
|
68
|
+
a.download = `terminalone-sync-${payload.syncToken}.json`;
|
|
69
|
+
a.click();
|
|
70
|
+
URL.revokeObjectURL(a.href);
|
|
71
|
+
T1.toast(`Settings exported (token ${payload.syncToken})`);
|
|
72
|
+
});
|
|
73
|
+
T1.ui.toolbar().appendChild(exportBtn);
|
|
74
|
+
|
|
75
|
+
// Expose for tests.
|
|
76
|
+
window.__terminalOneSettingsSync = { collectSettings, importSettings, validate, generateToken, getToken, SCHEMA_VERSION };
|
|
77
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard shortcut helper overlay (tablet/desktop).
|
|
3
|
+
*
|
|
4
|
+
* Pressing ? or Cmd/Ctrl+? opens an overlay listing available shortcuts for
|
|
5
|
+
* the current device.
|
|
6
|
+
*/
|
|
7
|
+
export function init(T1) {
|
|
8
|
+
T1.ui.addStyle(`
|
|
9
|
+
.t1-shortcut-overlay {
|
|
10
|
+
position: fixed; inset: 0;
|
|
11
|
+
background: rgba(0,0,0,0.5);
|
|
12
|
+
z-index: 400;
|
|
13
|
+
display: none; align-items: center; justify-content: center;
|
|
14
|
+
}
|
|
15
|
+
.t1-shortcut-overlay.open { display: flex; }
|
|
16
|
+
.t1-shortcut-panel {
|
|
17
|
+
background: var(--ui-elevated);
|
|
18
|
+
border: 1px solid var(--ui-border);
|
|
19
|
+
border-radius: 10px;
|
|
20
|
+
width: min(520px, 90vw);
|
|
21
|
+
max-height: 70vh;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
display: flex; flex-direction: column;
|
|
24
|
+
}
|
|
25
|
+
.t1-shortcut-panel header { padding: 14px 18px; border-bottom: 1px solid var(--ui-border); display: flex; justify-content: space-between; align-items: center; }
|
|
26
|
+
.t1-shortcut-panel h3 { margin: 0; font-size: 15px; color: var(--ui-fg); }
|
|
27
|
+
.t1-shortcut-panel .close { background: transparent; border: none; color: var(--ui-muted); font-size: 18px; }
|
|
28
|
+
.t1-shortcut-list { overflow-y: auto; padding: 10px 18px; }
|
|
29
|
+
.t1-shortcut-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--ui-border); color: var(--ui-fg); font-size: 13px; }
|
|
30
|
+
.t1-shortcut-row kbd { background: var(--ui-bg); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--ui-border); font-family: inherit; }
|
|
31
|
+
`);
|
|
32
|
+
|
|
33
|
+
const overlay = document.createElement('div');
|
|
34
|
+
overlay.className = 't1-shortcut-overlay';
|
|
35
|
+
overlay.setAttribute('role', 'dialog');
|
|
36
|
+
overlay.setAttribute('aria-label', 'Keyboard shortcuts');
|
|
37
|
+
overlay.innerHTML = `
|
|
38
|
+
<div class="t1-shortcut-panel">
|
|
39
|
+
<header><h3>Keyboard Shortcuts</h3><button type="button" class="close" aria-label="Close shortcuts">×</button></header>
|
|
40
|
+
<div class="t1-shortcut-list"></div>
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
document.body.appendChild(overlay);
|
|
44
|
+
|
|
45
|
+
const list = overlay.querySelector('.t1-shortcut-list');
|
|
46
|
+
overlay.querySelector('.close').addEventListener('click', close);
|
|
47
|
+
overlay.addEventListener('click', (e) => { if (e.target === overlay) close(); });
|
|
48
|
+
|
|
49
|
+
const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform || '');
|
|
50
|
+
const COMMON = [
|
|
51
|
+
{ keys: isMac ? 'Cmd + Shift + P' : 'Ctrl + Shift + P', desc: 'Open command palette' },
|
|
52
|
+
{ keys: isMac ? 'Cmd + Shift + F' : 'Ctrl + Shift + F', desc: 'Search scrollback' },
|
|
53
|
+
{ keys: isMac ? 'Cmd + K' : 'Ctrl + Shift + K', desc: 'Clear screen' },
|
|
54
|
+
{ keys: isMac ? 'Cmd + B' : 'Ctrl + Shift + B', desc: 'Toggle snippets' },
|
|
55
|
+
{ keys: 'Cmd/Ctrl + = / -', desc: 'Increase / decrease font size' },
|
|
56
|
+
{ keys: 'Ctrl + L', desc: 'Clear screen from the shell' },
|
|
57
|
+
{ keys: 'Ctrl + Z / Ctrl + Y', desc: 'Recall previous / next command' }
|
|
58
|
+
];
|
|
59
|
+
const TOUCH = [
|
|
60
|
+
{ keys: 'Two-finger swipe', desc: 'Switch session tabs' },
|
|
61
|
+
{ keys: 'Two-finger tap', desc: 'Open terminal context menu' }
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
function open() {
|
|
65
|
+
const device = T1.device;
|
|
66
|
+
list.innerHTML = '';
|
|
67
|
+
const rows = [...COMMON, ...(device === 'desktop' ? [] : TOUCH)];
|
|
68
|
+
for (const { keys, desc } of rows) {
|
|
69
|
+
const row = document.createElement('div');
|
|
70
|
+
row.className = 't1-shortcut-row';
|
|
71
|
+
row.innerHTML = `<span>${desc}</span><kbd>${keys}</kbd>`;
|
|
72
|
+
list.appendChild(row);
|
|
73
|
+
}
|
|
74
|
+
overlay.classList.add('open');
|
|
75
|
+
}
|
|
76
|
+
function close() { overlay.classList.remove('open'); }
|
|
77
|
+
|
|
78
|
+
document.addEventListener('keydown', (e) => {
|
|
79
|
+
if (e.key === '?' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); open(); }
|
|
80
|
+
else if (e.key === '?' && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey) { e.preventDefault(); open(); }
|
|
81
|
+
else if (e.key === 'Escape') { close(); }
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
window.__terminalOneShortcutHelp = { open, close, overlay };
|
|
85
|
+
}
|
|
@@ -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
|
+
}
|