@andy.ian/dsh-homing 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/bin/auth.mjs +159 -0
- package/bin/backup.mjs +118 -0
- package/bin/bootstrap-server.mjs +436 -0
- package/bin/entry-link.mjs +69 -0
- package/bin/nginx-dsh.template.conf +91 -0
- package/bin/nginx-gate.conf +9 -0
- package/bin/nginx-ws-map.conf +5 -0
- package/bin/renew-cert.mjs +127 -0
- package/bin/watchdog.mjs +158 -0
- package/cordis.patch.yml +30 -0
- package/icon.svg +9 -0
- package/index.js +3339 -0
- package/lib/csrf.mjs +60 -0
- package/lib/devices.mjs +221 -0
- package/lib/files-page.mjs +391 -0
- package/lib/files.mjs +464 -0
- package/lib/git.mjs +154 -0
- package/lib/limits.mjs +135 -0
- package/lib/pty.mjs +354 -0
- package/lib/session.mjs +216 -0
- package/lib/shell-page.mjs +430 -0
- package/lib/shell.mjs +274 -0
- package/lib/term-app.js +318 -0
- package/lib/term-page.mjs +117 -0
- package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
- package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
- package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
- package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
- package/lib/vendor/node_modules/asn1/LICENSE +19 -0
- package/lib/vendor/node_modules/asn1/README.md +50 -0
- package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
- package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
- package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
- package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
- package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
- package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
- package/lib/vendor/node_modules/asn1/package.json +31 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
- package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
- package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
- package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
- package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
- package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
- package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
- package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
- package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
- package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
- package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
- package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
- package/lib/vendor/node_modules/ssh2/README.md +1529 -0
- package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
- package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
- package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
- package/lib/vendor/node_modules/ssh2/install.js +27 -0
- package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
- package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
- package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
- package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
- package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
- package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
- package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
- package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
- package/lib/vendor/node_modules/ssh2/package.json +49 -0
- package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
- package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
- package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
- package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
- package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
- package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
- package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
- package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
- package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
- package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
- package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
- package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
- package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
- package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
- package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
- package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
- package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
- package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
- package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
- package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
- package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
- package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
- package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
- package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
- package/lib/vendor/xterm.css +218 -0
- package/lib/vendor/xterm.js +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/ops/watchdog/dsh-watchdog.ps1 +105 -0
- package/ops/watchdog/restart-now.ps1 +247 -0
- package/package.json +69 -4
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /shell 终端页:模仿 Git Bash(mintty)的样子。
|
|
3
|
+
*
|
|
4
|
+
* 提示符是两行(和 mintty 一致):
|
|
5
|
+
* andyi@DESKTOP-JH8H48I MINGW64 /c/Users/.../workspace (main)
|
|
6
|
+
* $ ▮
|
|
7
|
+
* 第一行是信息行(用户名@主机 / MINGW64 / MSYS 风格路径 / 当前分支),
|
|
8
|
+
* 第二行只有一个 $ 和正在输入的命令(textarea,长命令自动换行增高)。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const escapeHtml = (value) => String(value ?? '')
|
|
12
|
+
.replaceAll('&', '&')
|
|
13
|
+
.replaceAll('<', '<')
|
|
14
|
+
.replaceAll('>', '>')
|
|
15
|
+
.replaceAll('"', '"')
|
|
16
|
+
.replaceAll("'", ''')
|
|
17
|
+
|
|
18
|
+
/** C:\Users\x → /c/Users/x(mintty 里显示的样子) */
|
|
19
|
+
export const toMsys = (value) => {
|
|
20
|
+
const text = String(value ?? '')
|
|
21
|
+
const match = /^([A-Za-z]):[\\/]?(.*)$/u.exec(text)
|
|
22
|
+
if (match === null) return text
|
|
23
|
+
const rest = match[2].replaceAll('\\', '/').replace(/\/+$/u, '')
|
|
24
|
+
return '/' + match[1].toLowerCase() + (rest === '' ? '' : '/' + rest)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const STYLE = `
|
|
28
|
+
:root { color-scheme: dark; }
|
|
29
|
+
* { box-sizing: border-box; }
|
|
30
|
+
html, body { height: 100%; }
|
|
31
|
+
body {
|
|
32
|
+
margin: 0; background: #0c0c0c; color: #cccccc;
|
|
33
|
+
font-family: "Cascadia Mono", Consolas, "DejaVu Sans Mono", "Noto Sans Mono CJK SC", monospace;
|
|
34
|
+
font-size: 13px; display: flex; flex-direction: column;
|
|
35
|
+
}
|
|
36
|
+
.top {
|
|
37
|
+
display: flex; gap: 8px; align-items: center; padding: 6px 10px;
|
|
38
|
+
background: #1c1c1c; border-bottom: 1px solid #2a2a2a; font-size: 12px; color: #9a9a9a;
|
|
39
|
+
flex: 0 0 auto;
|
|
40
|
+
}
|
|
41
|
+
.top a { color: #6cb6ff; text-decoration: none; }
|
|
42
|
+
.top .spacer { flex: 1; }
|
|
43
|
+
#term {
|
|
44
|
+
flex: 1 1 auto; overflow-y: auto; padding: 8px 10px 12px;
|
|
45
|
+
white-space: normal; word-break: break-word; line-height: 1.45;
|
|
46
|
+
}
|
|
47
|
+
.ps1line { color: #cccccc; margin: 6px 0 0; white-space: normal; }
|
|
48
|
+
.ps1line .user { color: #6ad46a; }
|
|
49
|
+
.ps1line .mingw { color: #e6c07b; }
|
|
50
|
+
.ps1line .path { color: #e6c07b; word-break: break-all; }
|
|
51
|
+
.ps1line .branch { color: #56c8d8; }
|
|
52
|
+
.cmdline { color: #ffffff; white-space: pre-wrap; }
|
|
53
|
+
.cmdline .dollar { color: #ffffff; }
|
|
54
|
+
.out { margin: 0 0 2px; color: #cccccc; }
|
|
55
|
+
.err { color: #ff8f8f; }
|
|
56
|
+
.meta { color: #7a7a7a; font-size: 11px; margin-bottom: 2px; }
|
|
57
|
+
form.input { display: flex; gap: 6px; align-items: flex-start; margin: 0; padding: 0; }
|
|
58
|
+
form.input .dollar { flex: 0 0 auto; color: #ffffff; }
|
|
59
|
+
#cmd {
|
|
60
|
+
flex: 1 1 0; min-width: 80px; background: transparent; border: 0; outline: 0;
|
|
61
|
+
color: #ffffff; font: inherit; font-size: 13px; line-height: 1.45;
|
|
62
|
+
caret-color: #ffffff; resize: none; overflow: hidden; padding: 0;
|
|
63
|
+
white-space: pre-wrap; word-break: break-word; min-height: 1.5em;
|
|
64
|
+
}
|
|
65
|
+
form.input .tools { display: flex; gap: 6px; flex: 0 0 auto; }
|
|
66
|
+
button {
|
|
67
|
+
flex: 0 0 auto; padding: 6px 10px; border-radius: 6px; border: 1px solid #333;
|
|
68
|
+
background: #232323; color: #cfcfcf; font: inherit; font-size: 12px;
|
|
69
|
+
}
|
|
70
|
+
button.primary { background: #2d5bd7; border-color: #2d5bd7; color: #fff; }
|
|
71
|
+
.toolbar { display: flex; gap: 6px; padding-top: 6px; }
|
|
72
|
+
.toolbar button { min-width: 44px; text-align: center; }
|
|
73
|
+
.toolbar button.toggle { min-width: 56px; }
|
|
74
|
+
/* Ctrl 按下态:和高亮一致,松开即恢复 */
|
|
75
|
+
button.pressed {
|
|
76
|
+
background: #2d5bd7; border-color: #2d5bd7; color: #fff;
|
|
77
|
+
box-shadow: 0 0 0 1px #2d5bd7 inset;
|
|
78
|
+
}
|
|
79
|
+
.hint { color: #7a7a7a; font-size: 11px; padding-top: 4px; }
|
|
80
|
+
#cands { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; }
|
|
81
|
+
#cands button { background: #1b2030; border: 1px solid #2a3550; color: #9fc0ff; font-size: 12px; padding: 5px 9px; border-radius: 999px; }
|
|
82
|
+
`
|
|
83
|
+
|
|
84
|
+
/** 信息行:user@host MINGW64 /c/path (branch) */
|
|
85
|
+
export const promptInfo = ({ cwd = '', user = '', host = '', branch = '' } = {}) => {
|
|
86
|
+
const head = user === '' ? '' : `<span class="user">${escapeHtml(user)}${host === '' ? '' : '@' + escapeHtml(host)}</span> `
|
|
87
|
+
const mingw = '<span class="mingw">MINGW64</span> '
|
|
88
|
+
const path = `<span class="path">${escapeHtml(toMsys(cwd))}</span>`
|
|
89
|
+
const br = branch === '' ? '' : ` <span class="branch">(${escapeHtml(branch)})</span>`
|
|
90
|
+
return `<div class="ps1line">${head}${mingw}${path}${br}</div>`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function renderShellPage({
|
|
94
|
+
cwd = '',
|
|
95
|
+
transcript = [],
|
|
96
|
+
running = true,
|
|
97
|
+
user = '',
|
|
98
|
+
host = '',
|
|
99
|
+
branch = '',
|
|
100
|
+
}) {
|
|
101
|
+
const infoHtml = (dir, br) => promptInfo({ cwd: dir || cwd, user, host, branch: br ?? branch })
|
|
102
|
+
const entries = transcript.map((entry) => [
|
|
103
|
+
infoHtml(entry.cwd || cwd, entry.branch),
|
|
104
|
+
`<div class="cmdline"><span class="dollar">$</span> ${escapeHtml(entry.command)}</div>`,
|
|
105
|
+
entry.output === undefined
|
|
106
|
+
? ''
|
|
107
|
+
: `<div class="${entry.ok === false && entry.code !== 0 ? 'out err' : 'out'}">${escapeHtml(entry.output)}</div>`,
|
|
108
|
+
].join('')).join('')
|
|
109
|
+
|
|
110
|
+
const body = `
|
|
111
|
+
<div class="top">
|
|
112
|
+
<a href="/files?path=${encodeURIComponent(cwd)}">文件</a>
|
|
113
|
+
<a href="/git?path=${encodeURIComponent(cwd)}">Git</a>
|
|
114
|
+
<span class="spacer"></span>
|
|
115
|
+
<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:52%">${escapeHtml(toMsys(cwd))}</span>
|
|
116
|
+
<button id="reset" type="button">重置</button>
|
|
117
|
+
</div>
|
|
118
|
+
<div id="term">${entries || '<div class="meta">这是你电脑上的 Git Bash,输入命令后回车执行</div>'}
|
|
119
|
+
<div id="ps1meta">${infoHtml(cwd)}</div>
|
|
120
|
+
<form class="input" id="term-form">
|
|
121
|
+
<span class="dollar">$</span>
|
|
122
|
+
<textarea id="cmd" name="command" rows="1" autocomplete="off" autocapitalize="off" autocorrect="off"
|
|
123
|
+
spellcheck="false" autofocus></textarea>
|
|
124
|
+
<span class="tools">
|
|
125
|
+
<button type="submit" class="primary">执行</button>
|
|
126
|
+
</span>
|
|
127
|
+
</form>
|
|
128
|
+
<div class="toolbar">
|
|
129
|
+
<button type="button" id="histUp" title="上一条历史命令">↑</button>
|
|
130
|
+
<button type="button" id="histDown" title="下一条历史命令">↓</button>
|
|
131
|
+
<button type="button" id="ctrlkey" class="toggle" aria-pressed="false"
|
|
132
|
+
title="Ctrl:按下后按字母触发 Ctrl 组合键">Ctrl</button>
|
|
133
|
+
<button type="button" id="tabkey" title="补全">Tab</button>
|
|
134
|
+
</div>
|
|
135
|
+
<div id="cands"></div>
|
|
136
|
+
<div class="hint" id="ctrlhint"></div>
|
|
137
|
+
</div>
|
|
138
|
+
<script>
|
|
139
|
+
(function () {
|
|
140
|
+
var term = document.getElementById('term');
|
|
141
|
+
var form = document.getElementById('term-form');
|
|
142
|
+
var input = document.getElementById('cmd');
|
|
143
|
+
var cands = document.getElementById('cands');
|
|
144
|
+
var meta = document.getElementById('ps1meta');
|
|
145
|
+
var currentCwd = ${JSON.stringify(cwd)};
|
|
146
|
+
var currentBranch = ${JSON.stringify(branch)};
|
|
147
|
+
var userName = ${JSON.stringify(user)};
|
|
148
|
+
var hostName = ${JSON.stringify(host)};
|
|
149
|
+
|
|
150
|
+
function esc(text) {
|
|
151
|
+
return String(text == null ? '' : text)
|
|
152
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
153
|
+
}
|
|
154
|
+
function toMsys(value) {
|
|
155
|
+
var m = String(value || '').match(/^([A-Za-z]):[\\\\/]?(.*)$/);
|
|
156
|
+
if (!m) return String(value || '');
|
|
157
|
+
var rest = m[2].replace(/\\\\/g, '/').replace(/\\/+$/, '');
|
|
158
|
+
return '/' + m[1].toLowerCase() + (rest === '' ? '' : '/' + rest);
|
|
159
|
+
}
|
|
160
|
+
function infoHtml() {
|
|
161
|
+
var head = userName === '' ? '' : '<span class="user">' + esc(userName) + (hostName === '' ? '' : '@' + esc(hostName)) + '</span> ';
|
|
162
|
+
var br = currentBranch === '' ? '' : ' <span class="branch">(' + esc(currentBranch) + ')</span>';
|
|
163
|
+
return '<div class="ps1line">' + head + '<span class="mingw">MINGW64</span> <span class="path">' + esc(toMsys(currentCwd)) + '</span>' + br + '</div>';
|
|
164
|
+
}
|
|
165
|
+
function scrollBottom() { term.scrollTop = term.scrollHeight; }
|
|
166
|
+
function autosize() {
|
|
167
|
+
input.style.height = 'auto';
|
|
168
|
+
input.style.height = Math.min(input.scrollHeight, Math.round(window.innerHeight * 0.4)) + 'px';
|
|
169
|
+
scrollBottom();
|
|
170
|
+
}
|
|
171
|
+
function renderCands(items) {
|
|
172
|
+
cands.innerHTML = '';
|
|
173
|
+
(items || []).slice(0, 12).forEach(function (item) {
|
|
174
|
+
var b = document.createElement('button');
|
|
175
|
+
b.type = 'button';
|
|
176
|
+
b.textContent = item.label;
|
|
177
|
+
b.addEventListener('click', function () { insert(item.value); });
|
|
178
|
+
cands.appendChild(b);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function insert(value) {
|
|
182
|
+
var text = input.value;
|
|
183
|
+
var m = text.match(/(\\S+)$/);
|
|
184
|
+
input.value = (m ? text.slice(0, m.index) : text) + value;
|
|
185
|
+
input.focus();
|
|
186
|
+
autosize();
|
|
187
|
+
fetchComplete();
|
|
188
|
+
}
|
|
189
|
+
function fetchComplete() {
|
|
190
|
+
var lineText = input.value;
|
|
191
|
+
if (lineText.trim() === '') { cands.innerHTML = ''; return; }
|
|
192
|
+
fetch('/shell/complete?cwd=' + encodeURIComponent(currentCwd) + '&line=' + encodeURIComponent(lineText))
|
|
193
|
+
.then(function (r) { return r.ok ? r.json() : []; })
|
|
194
|
+
.then(renderCands)
|
|
195
|
+
.catch(function () {});
|
|
196
|
+
}
|
|
197
|
+
function completeNow() {
|
|
198
|
+
var lineText = input.value;
|
|
199
|
+
if (lineText.trim() === '') return;
|
|
200
|
+
fetch('/shell/complete?cwd=' + encodeURIComponent(currentCwd) + '&line=' + encodeURIComponent(lineText))
|
|
201
|
+
.then(function (r) { return r.ok ? r.json() : []; })
|
|
202
|
+
.then(function (items) {
|
|
203
|
+
if (!items || items.length === 0) { renderCands([]); return; }
|
|
204
|
+
renderCands(items);
|
|
205
|
+
if (items.length === 1) { insert(items[0].value); return; }
|
|
206
|
+
var prefix = items[0].value;
|
|
207
|
+
for (var i = 1; i < items.length; i += 1) {
|
|
208
|
+
while (prefix.length > 0 && items[i].value.indexOf(prefix) !== 0) prefix = prefix.slice(0, -1);
|
|
209
|
+
}
|
|
210
|
+
if (prefix.length > 0) insert(prefix);
|
|
211
|
+
})
|
|
212
|
+
.catch(function () {});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
form.addEventListener('submit', function (event) {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
var command = input.value;
|
|
218
|
+
if (command.trim() === '') return;
|
|
219
|
+
rememberHistory(command);
|
|
220
|
+
input.value = '';
|
|
221
|
+
autosize();
|
|
222
|
+
cands.innerHTML = '';
|
|
223
|
+
|
|
224
|
+
var block = document.createElement('div');
|
|
225
|
+
block.innerHTML = infoHtml() + '<div class="cmdline"><span class="dollar">$</span> ' + esc(command) + '</div>';
|
|
226
|
+
term.insertBefore(block, meta);
|
|
227
|
+
scrollBottom();
|
|
228
|
+
|
|
229
|
+
fetch('/shell/run', {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
headers: { 'content-type': 'application/json' },
|
|
232
|
+
body: JSON.stringify({ command: command, cwd: currentCwd })
|
|
233
|
+
})
|
|
234
|
+
.then(function (r) { return r.json(); })
|
|
235
|
+
.then(function (data) {
|
|
236
|
+
var out = document.createElement('div');
|
|
237
|
+
out.className = (data.ok === false && data.code !== 0) ? 'out err' : 'out';
|
|
238
|
+
out.textContent = data.output;
|
|
239
|
+
term.insertBefore(out, meta);
|
|
240
|
+
if (data.cwd && data.cwd !== currentCwd) {
|
|
241
|
+
currentCwd = data.cwd;
|
|
242
|
+
meta.innerHTML = infoHtml();
|
|
243
|
+
}
|
|
244
|
+
scrollBottom();
|
|
245
|
+
})
|
|
246
|
+
.catch(function (error) {
|
|
247
|
+
var out = document.createElement('div');
|
|
248
|
+
out.className = 'out err';
|
|
249
|
+
out.textContent = '请求失败:' + error.message;
|
|
250
|
+
term.insertBefore(out, meta);
|
|
251
|
+
scrollBottom();
|
|
252
|
+
})
|
|
253
|
+
.then(function () { input.focus(); });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
input.addEventListener('input', function () {
|
|
257
|
+
autosize();
|
|
258
|
+
clearTimeout(input.__t);
|
|
259
|
+
input.__t = setTimeout(fetchComplete, 250);
|
|
260
|
+
});
|
|
261
|
+
input.addEventListener('keydown', function (event) {
|
|
262
|
+
// 回车提交统一在下面"Ctrl 两态"那段处理(那里还要判断 Ctrl 是否按下),这里不再重复绑定
|
|
263
|
+
if (event.key === 'Enter' && !event.shiftKey) event.preventDefault();
|
|
264
|
+
});
|
|
265
|
+
document.getElementById('tabkey').addEventListener('click', function (event) {
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
completeNow();
|
|
268
|
+
input.focus();
|
|
269
|
+
});
|
|
270
|
+
document.getElementById('reset').addEventListener('click', function () {
|
|
271
|
+
fetch('/shell/run', {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
headers: { 'content-type': 'application/json' },
|
|
274
|
+
body: JSON.stringify({ reset: true, cwd: currentCwd })
|
|
275
|
+
}).then(function () { location.reload(); });
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
/* ---------- 历史命令:↑ ↓ ---------- */
|
|
279
|
+
var history = [];
|
|
280
|
+
var histIndex = -1; // -1 表示不在浏览历史中
|
|
281
|
+
function rememberHistory(command) {
|
|
282
|
+
if (command.trim() === '') return;
|
|
283
|
+
if (history[history.length - 1] !== command) history.push(command);
|
|
284
|
+
if (history.length > 200) history.shift();
|
|
285
|
+
histIndex = -1;
|
|
286
|
+
}
|
|
287
|
+
document.getElementById('histUp').addEventListener('click', function (event) {
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
if (history.length === 0) return;
|
|
290
|
+
histIndex = histIndex < 0 ? history.length - 1 : Math.max(0, histIndex - 1);
|
|
291
|
+
input.value = history[histIndex];
|
|
292
|
+
placeCaretEnd();
|
|
293
|
+
autosize();
|
|
294
|
+
input.focus();
|
|
295
|
+
});
|
|
296
|
+
document.getElementById('histDown').addEventListener('click', function (event) {
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
if (history.length === 0) return;
|
|
299
|
+
if (histIndex < 0) return;
|
|
300
|
+
histIndex += 1;
|
|
301
|
+
if (histIndex >= history.length) {
|
|
302
|
+
histIndex = -1;
|
|
303
|
+
input.value = '';
|
|
304
|
+
} else {
|
|
305
|
+
input.value = history[histIndex];
|
|
306
|
+
}
|
|
307
|
+
placeCaretEnd();
|
|
308
|
+
autosize();
|
|
309
|
+
input.focus();
|
|
310
|
+
});
|
|
311
|
+
function placeCaretEnd() {
|
|
312
|
+
try {
|
|
313
|
+
input.setSelectionRange(input.value.length, input.value.length);
|
|
314
|
+
} catch (error) { /* 忽略 */ }
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/* ---------- Ctrl:两态按钮(默认抬起) ---------- */
|
|
318
|
+
var ctrlButton = document.getElementById('ctrlkey');
|
|
319
|
+
var ctrlHint = document.getElementById('ctrlhint');
|
|
320
|
+
var ctrlLatched = false;
|
|
321
|
+
function setCtrl(latched) {
|
|
322
|
+
ctrlLatched = latched;
|
|
323
|
+
ctrlButton.classList.toggle('pressed', latched);
|
|
324
|
+
ctrlButton.setAttribute('aria-pressed', latched ? 'true' : 'false');
|
|
325
|
+
ctrlButton.textContent = latched ? 'Ctrl ●' : 'Ctrl';
|
|
326
|
+
ctrlHint.textContent = latched ? 'Ctrl 已按下:再按 C 中断 / L 清屏 / D 重置 / U 清空 / A 行首 / E 行尾' : '';
|
|
327
|
+
}
|
|
328
|
+
ctrlButton.addEventListener('click', function (event) {
|
|
329
|
+
event.preventDefault();
|
|
330
|
+
setCtrl(!ctrlLatched);
|
|
331
|
+
input.focus();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
function appendLine(html) {
|
|
335
|
+
var el = document.createElement('div');
|
|
336
|
+
el.innerHTML = html;
|
|
337
|
+
term.insertBefore(el, meta);
|
|
338
|
+
scrollBottom();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Ctrl+C:中断(杀掉当前命令并重启会话)
|
|
342
|
+
function interrupt() {
|
|
343
|
+
appendLine('<div class="out err">^C(正在中断…)</div>');
|
|
344
|
+
fetch('/shell/run', {
|
|
345
|
+
method: 'POST',
|
|
346
|
+
headers: { 'content-type': 'application/json' },
|
|
347
|
+
body: JSON.stringify({ interrupt: true, cwd: currentCwd })
|
|
348
|
+
})
|
|
349
|
+
.then(function (r) { return r.json(); })
|
|
350
|
+
.then(function (data) {
|
|
351
|
+
appendLine('<div class="out">' + esc(data.output || '(已中断)') + '</div>');
|
|
352
|
+
if (data.cwd) { currentCwd = data.cwd; meta.innerHTML = infoHtml(); }
|
|
353
|
+
})
|
|
354
|
+
.catch(function (error) {
|
|
355
|
+
appendLine('<div class="out err">中断失败:' + esc(error.message) + '</div>');
|
|
356
|
+
})
|
|
357
|
+
.then(function () { input.focus(); });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Ctrl+L:清屏(保留输入行)
|
|
361
|
+
function clearScreen() {
|
|
362
|
+
Array.prototype.slice.call(term.children).forEach(function (child) {
|
|
363
|
+
if (child === meta || child === form || child.id === 'cands' || child.id === 'ctrlhint') return;
|
|
364
|
+
if (child.contains(meta) || child.contains(form)) return;
|
|
365
|
+
child.remove();
|
|
366
|
+
});
|
|
367
|
+
scrollBottom();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Ctrl+D:重置会话
|
|
371
|
+
function resetSession() {
|
|
372
|
+
fetch('/shell/run', {
|
|
373
|
+
method: 'POST',
|
|
374
|
+
headers: { 'content-type': 'application/json' },
|
|
375
|
+
body: JSON.stringify({ reset: true, cwd: currentCwd })
|
|
376
|
+
}).then(function () { location.reload(); });
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function handleCtrlKey(letter) {
|
|
380
|
+
var key = String(letter).toLowerCase();
|
|
381
|
+
if (key === 'c') { interrupt(); return true; }
|
|
382
|
+
if (key === 'l') { clearScreen(); return true; }
|
|
383
|
+
if (key === 'd') { resetSession(); return true; }
|
|
384
|
+
if (key === 'u') { input.value = ''; autosize(); return true; }
|
|
385
|
+
if (key === 'a') { try { input.setSelectionRange(0, 0); } catch (e) {} return true; }
|
|
386
|
+
if (key === 'e') { placeCaretEnd(); return true; }
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// 键盘:Ctrl 按下时拦截字母;Ctrl+Enter 也可以直接提交
|
|
391
|
+
input.addEventListener('keydown', function (event) {
|
|
392
|
+
if (ctrlLatched && /^[a-zA-Z]$/u.test(event.key)) {
|
|
393
|
+
event.preventDefault();
|
|
394
|
+
if (handleCtrlKey(event.key)) {
|
|
395
|
+
setCtrl(false);
|
|
396
|
+
if (event.key.toLowerCase() !== 'c' && event.key.toLowerCase() !== 'd') input.focus();
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
401
|
+
event.preventDefault();
|
|
402
|
+
if (form.requestSubmit) form.requestSubmit();
|
|
403
|
+
else form.dispatchEvent(new Event('submit', { cancelable: true }));
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
var vv = window.visualViewport;
|
|
408
|
+
if (vv) {
|
|
409
|
+
var fit = function () {
|
|
410
|
+
document.body.style.height = vv.height + 'px';
|
|
411
|
+
scrollBottom();
|
|
412
|
+
};
|
|
413
|
+
vv.addEventListener('resize', fit);
|
|
414
|
+
vv.addEventListener('scroll', fit);
|
|
415
|
+
fit();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
setCtrl(false);
|
|
419
|
+
autosize();
|
|
420
|
+
input.focus();
|
|
421
|
+
scrollBottom();
|
|
422
|
+
})();
|
|
423
|
+
</script>`
|
|
424
|
+
return `<!doctype html>
|
|
425
|
+
<html lang="zh-CN"><head><meta charset="utf-8">
|
|
426
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
427
|
+
<title>终端 · DSH</title>
|
|
428
|
+
<style>${STYLE}</style></head>
|
|
429
|
+
<body>${body}</body></html>`
|
|
430
|
+
}
|