peer-term 1.3.9 → 1.3.10

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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +1849 -1800
  3. package/src/ui.js +142 -142
package/src/ui.js CHANGED
@@ -1,142 +1,142 @@
1
- /**
2
- * PeerTerm — CLI UI Module
3
- *
4
- * Handles all terminal output formatting:
5
- * - ASCII art banner
6
- * - Session code display box
7
- * - Help text
8
- * - Version display
9
- */
10
-
11
- import fs from 'fs';
12
- import path from 'path';
13
- import { fileURLToPath } from 'url';
14
-
15
- const __filename = fileURLToPath(import.meta.url);
16
- const __dirname = path.dirname(__filename);
17
-
18
- // ─── ASCII Banner ────────────────────────────────────────────────────────────
19
-
20
- const BANNER = `
21
- ██████╗ ███████╗███████╗██████╗ ████████╗███████╗██████╗ ███╗ ███╗
22
- ██╔══██╗██╔════╝██╔════╝██╔══██╗╚══██╔══╝██╔════╝██╔══██╗████╗ ████║
23
- ██████╔╝█████╗ █████╗ ██████╔╝ ██║ █████╗ ██████╔╝██╔████╔██║
24
- ██╔═══╝ ██╔══╝ ██╔══╝ ██╔══██╗ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║
25
- ██║ ███████╗███████╗██║ ██║ ██║ ███████╗██║ ██║██║ ╚═╝ ██║
26
- ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
27
- Terminal sharing. Instant. Encrypted.`;
28
-
29
- /**
30
- * Print the startup ASCII art banner.
31
- */
32
- export function printBanner() {
33
- console.log(BANNER);
34
- console.log('');
35
- }
36
-
37
- // ─── Session Code Box ────────────────────────────────────────────────────────
38
-
39
- /**
40
- * Print the bordered session information box.
41
- *
42
- * @param {Object} opts
43
- * @param {string} opts.code - 6-digit session code
44
- * @param {string} opts.expiry - Formatted expiry string (e.g. "5 minute(s)")
45
- * @param {string} opts.mode - "Read-Write" or "Read-Only"
46
- * @param {string} opts.shell - Shell path (e.g. "/bin/zsh")
47
- * @param {string} [opts.startPath] - Starting directory for the session
48
- * @param {string} [opts.shareUrl] - URL to share (e.g. "https://peerterm.dev")
49
- */
50
- export function printSessionBox({ code, expiry, rejoinWindow, mode, shell, startPath, shareUrl }) {
51
- const spacedCode = code.split('').join(' ');
52
- const url = shareUrl || 'https://peerterm.dev';
53
-
54
- // Truncate long shell paths to keep box readable
55
- const shellDisplay = shell.length > 24 ? '...' + shell.slice(-21) : shell;
56
-
57
- // Truncate long start paths similarly
58
- const homeDir = process.env.HOME || process.env.USERPROFILE || '';
59
- let pathDisplay = startPath || homeDir;
60
- if (homeDir && pathDisplay.startsWith(homeDir)) {
61
- pathDisplay = '~' + pathDisplay.slice(homeDir.length);
62
- }
63
- if (pathDisplay.length > 30) pathDisplay = '...' + pathDisplay.slice(-27);
64
-
65
- // Calculate dynamic box width based on longest content
66
- const infoLines = [
67
- ` Session Code: ${spacedCode}`,
68
- ` Expires in: ${expiry}`,
69
- ` Rejoin Window: ${rejoinWindow}`,
70
- ` Mode: ${mode}`,
71
- ` Shell: ${shellDisplay}`,
72
- ` Path: ${pathDisplay}`,
73
- ];
74
- const shareLine = ` Share at: ${url}`;
75
- const allLines = [...infoLines, shareLine];
76
- const maxLen = Math.max(...allLines.map(l => l.length), 35);
77
- const innerWidth = maxLen + 3; // padding on right
78
-
79
- const hr = '─'.repeat(innerWidth);
80
- const emptyLine = ' '.repeat(innerWidth);
81
-
82
- console.log('');
83
- console.log(` ┌${hr}┐`);
84
- console.log(` │${emptyLine}│`);
85
- for (const line of infoLines) {
86
- console.log(` │${line.padEnd(innerWidth)}│`);
87
- }
88
- console.log(` │${emptyLine}│`);
89
- console.log(` │${shareLine.padEnd(innerWidth)}│`);
90
- console.log(` │${emptyLine}│`);
91
- console.log(` └${hr}┘`);
92
- console.log('');
93
- }
94
-
95
- // ─── Help Text ───────────────────────────────────────────────────────────────
96
-
97
- const HELP_TEXT = `
98
- Usage: peer-term [options]
99
-
100
- Options:
101
- --expiry <time> Session expiry time (e.g. 5m, 30s, 1h) [default: 5m]
102
- --rejoin <time> Reconnection window (e.g. 5m, 1h, 6h) [default: 2m]
103
- --readonly Share in view-only mode
104
- --secure Enable fingerprint verification for MITM protection
105
- --path <dir> Starting directory for the terminal session [default: home]
106
- --relay <url> Custom relay server URL
107
- --verbose Enable debug logging
108
- --help Show this help message
109
- --version Print version number
110
-
111
- Examples:
112
- peer-term Start session with defaults
113
- peer-term --expiry 10m Custom expiry
114
- peer-term --rejoin 30m Custom reconnection window
115
- peer-term --readonly View-only session
116
- peer-term --secure Require fingerprint verification
117
- peer-term --path ~/projects Start in ~/projects
118
- peer-term --verbose Debug logs
119
- peer-term --relay wss://custom Use custom relay server
120
- `;
121
-
122
- /**
123
- * Print CLI help text.
124
- */
125
- export function printHelp() {
126
- console.log(HELP_TEXT);
127
- }
128
-
129
- // ─── Version ─────────────────────────────────────────────────────────────────
130
-
131
- /**
132
- * Print the version number from package.json.
133
- */
134
- export function printVersion() {
135
- try {
136
- const pkgPath = path.join(__dirname, '..', 'package.json');
137
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
138
- console.log(`peer-term v${pkg.version}`);
139
- } catch {
140
- console.log('peer-term (version unknown)');
141
- }
142
- }
1
+ /**
2
+ * PeerTerm — CLI UI Module
3
+ *
4
+ * Handles all terminal output formatting:
5
+ * - ASCII art banner
6
+ * - Session code display box
7
+ * - Help text
8
+ * - Version display
9
+ */
10
+
11
+ import fs from 'fs';
12
+ import path from 'path';
13
+ import { fileURLToPath } from 'url';
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+
18
+ // ─── ASCII Banner ────────────────────────────────────────────────────────────
19
+
20
+ const BANNER = `
21
+ ██████╗ ███████╗███████╗██████╗ ████████╗███████╗██████╗ ███╗ ███╗
22
+ ██╔══██╗██╔════╝██╔════╝██╔══██╗╚══██╔══╝██╔════╝██╔══██╗████╗ ████║
23
+ ██████╔╝█████╗ █████╗ ██████╔╝ ██║ █████╗ ██████╔╝██╔████╔██║
24
+ ██╔═══╝ ██╔══╝ ██╔══╝ ██╔══██╗ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║
25
+ ██║ ███████╗███████╗██║ ██║ ██║ ███████╗██║ ██║██║ ╚═╝ ██║
26
+ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
27
+ Terminal sharing. Instant. Encrypted.`;
28
+
29
+ /**
30
+ * Print the startup ASCII art banner.
31
+ */
32
+ export function printBanner() {
33
+ console.log(BANNER);
34
+ console.log('');
35
+ }
36
+
37
+ // ─── Session Code Box ────────────────────────────────────────────────────────
38
+
39
+ /**
40
+ * Print the bordered session information box.
41
+ *
42
+ * @param {Object} opts
43
+ * @param {string} opts.code - 6-digit session code
44
+ * @param {string} opts.expiry - Formatted expiry string (e.g. "5 minute(s)")
45
+ * @param {string} opts.mode - "Read-Write" or "Read-Only"
46
+ * @param {string} opts.shell - Shell path (e.g. "/bin/zsh")
47
+ * @param {string} [opts.startPath] - Starting directory for the session
48
+ * @param {string} [opts.shareUrl] - URL to share (e.g. "https://peerterm.dev")
49
+ */
50
+ export function printSessionBox({ code, expiry, rejoinWindow, mode, shell, startPath, shareUrl }) {
51
+ const spacedCode = code.split('').join(' ');
52
+ const url = shareUrl || 'https://peerterm.dev';
53
+
54
+ // Truncate long shell paths to keep box readable
55
+ const shellDisplay = shell.length > 24 ? '...' + shell.slice(-21) : shell;
56
+
57
+ // Truncate long start paths similarly
58
+ const homeDir = process.env.HOME || process.env.USERPROFILE || '';
59
+ let pathDisplay = startPath || homeDir;
60
+ if (homeDir && pathDisplay.startsWith(homeDir)) {
61
+ pathDisplay = '~' + pathDisplay.slice(homeDir.length);
62
+ }
63
+ if (pathDisplay.length > 30) pathDisplay = '...' + pathDisplay.slice(-27);
64
+
65
+ // Calculate dynamic box width based on longest content
66
+ const infoLines = [
67
+ ` Session Code: ${spacedCode}`,
68
+ ` Expires in: ${expiry}`,
69
+ ` Rejoin Window: ${rejoinWindow}`,
70
+ ` Mode: ${mode}`,
71
+ ` Shell: ${shellDisplay}`,
72
+ ` Path: ${pathDisplay}`,
73
+ ];
74
+ const shareLine = ` Share at: ${url}`;
75
+ const allLines = [...infoLines, shareLine];
76
+ const maxLen = Math.max(...allLines.map(l => l.length), 35);
77
+ const innerWidth = maxLen + 3; // padding on right
78
+
79
+ const hr = '─'.repeat(innerWidth);
80
+ const emptyLine = ' '.repeat(innerWidth);
81
+
82
+ console.log('');
83
+ console.log(` ┌${hr}┐`);
84
+ console.log(` │${emptyLine}│`);
85
+ for (const line of infoLines) {
86
+ console.log(` │${line.padEnd(innerWidth)}│`);
87
+ }
88
+ console.log(` │${emptyLine}│`);
89
+ console.log(` │${shareLine.padEnd(innerWidth)}│`);
90
+ console.log(` │${emptyLine}│`);
91
+ console.log(` └${hr}┘`);
92
+ console.log('');
93
+ }
94
+
95
+ // ─── Help Text ───────────────────────────────────────────────────────────────
96
+
97
+ const HELP_TEXT = `
98
+ Usage: peer-term [options]
99
+
100
+ Options:
101
+ --expiry <time> Session expiry time (e.g. 5m, 30s, 1h) [default: 5m]
102
+ --rejoin <time> Reconnection window (e.g. 5m, 1h, 6h) [default: 2m]
103
+ --readonly Share in view-only mode
104
+ --secure Enable fingerprint verification for MITM protection
105
+ --path <dir> Starting directory for the terminal session [default: home]
106
+ --relay <url> Custom relay server URL
107
+ --verbose Enable debug logging
108
+ --help Show this help message
109
+ --version Print version number
110
+
111
+ Examples:
112
+ peer-term Start session with defaults
113
+ peer-term --expiry 10m Custom expiry
114
+ peer-term --rejoin 30m Custom reconnection window
115
+ peer-term --readonly View-only session
116
+ peer-term --secure Require fingerprint verification
117
+ peer-term --path ~/projects Start in ~/projects
118
+ peer-term --verbose Debug logs
119
+ peer-term --relay wss://custom Use custom relay server
120
+ `;
121
+
122
+ /**
123
+ * Print CLI help text.
124
+ */
125
+ export function printHelp() {
126
+ console.log(HELP_TEXT);
127
+ }
128
+
129
+ // ─── Version ─────────────────────────────────────────────────────────────────
130
+
131
+ /**
132
+ * Print the version number from package.json.
133
+ */
134
+ export function printVersion() {
135
+ try {
136
+ const pkgPath = path.join(__dirname, '..', 'package.json');
137
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
138
+ console.log(`peer-term v${pkg.version}`);
139
+ } catch {
140
+ console.log('peer-term (version unknown)');
141
+ }
142
+ }