@electerm/electerm-react 1.34.30
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 +31 -0
- package/client/common/auto-complete-data-mapper.js +6 -0
- package/client/common/byte-format.js +14 -0
- package/client/common/class.js +52 -0
- package/client/common/clipboard.js +49 -0
- package/client/common/constants.js +308 -0
- package/client/common/create-lang-edit-link.js +7 -0
- package/client/common/create-title.js +29 -0
- package/client/common/db-fix.js +24 -0
- package/client/common/db.js +155 -0
- package/client/common/download-mirrors.js +10 -0
- package/client/common/download.js +16 -0
- package/client/common/error-handler.jsx +27 -0
- package/client/common/fetch-from-server.js +47 -0
- package/client/common/fetch.jsx +71 -0
- package/client/common/find-bookmark-group-id.js +15 -0
- package/client/common/find-parent.js +30 -0
- package/client/common/form-layout.js +27 -0
- package/client/common/fs.js +21 -0
- package/client/common/get-proxy.js +8 -0
- package/client/common/id-with-stamp.js +10 -0
- package/client/common/index-sorter.js +4 -0
- package/client/common/init-setting-item.js +32 -0
- package/client/common/is-absolute-path.js +3 -0
- package/client/common/is-ip.js +16 -0
- package/client/common/is-valid-path.js +7 -0
- package/client/common/key-control-pressed.js +13 -0
- package/client/common/key-pressed.js +13 -0
- package/client/common/key-shift-pressed.js +7 -0
- package/client/common/mode2permission.js +81 -0
- package/client/common/new-terminal.js +31 -0
- package/client/common/parse-int10.js +3 -0
- package/client/common/parse-json-safe.js +11 -0
- package/client/common/pass-enc.js +25 -0
- package/client/common/post-msg.js +3 -0
- package/client/common/pre.js +156 -0
- package/client/common/promise-timeout.js +27 -0
- package/client/common/resolve.js +31 -0
- package/client/common/run-idle.js +1 -0
- package/client/common/safe-local-storage.js +35 -0
- package/client/common/safe-name.js +19 -0
- package/client/common/sftp.js +74 -0
- package/client/common/terminal-theme.js +158 -0
- package/client/common/test-connection.js +12 -0
- package/client/common/time.js +30 -0
- package/client/common/to-simple-obj.js +5 -0
- package/client/common/track.js +7 -0
- package/client/common/transfer.js +76 -0
- package/client/common/trzsz.js +62 -0
- package/client/common/ui-theme.js +44 -0
- package/client/common/uid.js +5 -0
- package/client/common/update-check.js +79 -0
- package/client/common/upgrade.js +68 -0
- package/client/common/wait.js +8 -0
- package/client/common/ws.js +161 -0
- package/client/components/batch-op/batch-op.jsx +650 -0
- package/client/components/bookmark-form/bookmark-form.styl +8 -0
- package/client/components/bookmark-form/bookmark-group-tree-format.js +39 -0
- package/client/components/bookmark-form/encodes.js +44 -0
- package/client/components/bookmark-form/form-ssh-common.jsx +208 -0
- package/client/components/bookmark-form/form-tabs.jsx +69 -0
- package/client/components/bookmark-form/index.jsx +159 -0
- package/client/components/bookmark-form/local-form-ui.jsx +152 -0
- package/client/components/bookmark-form/local-form.jsx +16 -0
- package/client/components/bookmark-form/proxy.jsx +49 -0
- package/client/components/bookmark-form/quick-command-list.jsx +31 -0
- package/client/components/bookmark-form/quick-command.jsx +228 -0
- package/client/components/bookmark-form/render-auth-ssh.jsx +104 -0
- package/client/components/bookmark-form/render-connection-hopping.jsx +229 -0
- package/client/components/bookmark-form/render-delayed-scripts.jsx +88 -0
- package/client/components/bookmark-form/render-ssh-tunnel.jsx +116 -0
- package/client/components/bookmark-form/serial-form-ui.jsx +311 -0
- package/client/components/bookmark-form/serial-form.jsx +20 -0
- package/client/components/bookmark-form/sftp-enable.jsx +33 -0
- package/client/components/bookmark-form/ssh-form-ui.jsx +100 -0
- package/client/components/bookmark-form/ssh-form.jsx +348 -0
- package/client/components/bookmark-form/telnet-form-ui.jsx +154 -0
- package/client/components/bookmark-form/telnet-form.jsx +16 -0
- package/client/components/bookmark-form/tree-delete.jsx +87 -0
- package/client/components/bookmark-form/use-form-funcs.jsx +50 -0
- package/client/components/bookmark-form/use-quick-commands.jsx +83 -0
- package/client/components/bookmark-form/use-submit.jsx +77 -0
- package/client/components/bookmark-form/use-ui.jsx +82 -0
- package/client/components/bookmark-form/x11.jsx +23 -0
- package/client/components/common/animate-text.jsx +37 -0
- package/client/components/common/animate-text.styl +54 -0
- package/client/components/common/external-link.jsx +28 -0
- package/client/components/common/help-icon.jsx +25 -0
- package/client/components/common/highlight.jsx +23 -0
- package/client/components/common/highlight.styl +3 -0
- package/client/components/common/input-auto-focus.jsx +68 -0
- package/client/components/common/input-confirm.jsx +66 -0
- package/client/components/common/logo-elem.jsx +22 -0
- package/client/components/common/markdown.jsx +27 -0
- package/client/components/common/react-subx.jsx +1 -0
- package/client/components/common/resize-wrap.jsx +222 -0
- package/client/components/common/resize-wrap.styl +9 -0
- package/client/components/common/search.jsx +9 -0
- package/client/components/common/show-item.jsx +27 -0
- package/client/components/context-menu/boomarks.jsx +15 -0
- package/client/components/context-menu/context-menu.jsx +340 -0
- package/client/components/context-menu/context-menu.styl +90 -0
- package/client/components/context-menu/history.jsx +27 -0
- package/client/components/context-menu/icon-holder.jsx +5 -0
- package/client/components/context-menu/menu-btn.jsx +224 -0
- package/client/components/context-menu/sub-tab-menu.jsx +23 -0
- package/client/components/context-menu/tabs.jsx +22 -0
- package/client/components/context-menu/zoom.jsx +40 -0
- package/client/components/footer/batch-input.jsx +177 -0
- package/client/components/footer/footer-entry.jsx +141 -0
- package/client/components/footer/footer.styl +47 -0
- package/client/components/icons/match-case.jsx +10 -0
- package/client/components/icons/match-whole-word.jsx +13 -0
- package/client/components/icons/regular-exp.jsx +10 -0
- package/client/components/main/css-overwrite.jsx +92 -0
- package/client/components/main/error-wrapper.jsx +59 -0
- package/client/components/main/index.jsx +11 -0
- package/client/components/main/loading.jsx +25 -0
- package/client/components/main/main.jsx +149 -0
- package/client/components/main/term-fullscreen-control.jsx +21 -0
- package/client/components/main/term-fullscreen.styl +27 -0
- package/client/components/main/ui-theme.jsx +31 -0
- package/client/components/main/upgrade.jsx +351 -0
- package/client/components/main/upgrade.styl +27 -0
- package/client/components/main/wrapper.styl +41 -0
- package/client/components/quick-commands/qm.styl +29 -0
- package/client/components/quick-commands/quick-command-item.jsx +36 -0
- package/client/components/quick-commands/quick-command-transport-mod.jsx +54 -0
- package/client/components/quick-commands/quick-command-transport.jsx +12 -0
- package/client/components/quick-commands/quick-commands-box.jsx +233 -0
- package/client/components/quick-commands/quick-commands-form-elem.jsx +119 -0
- package/client/components/quick-commands/quick-commands-form.jsx +33 -0
- package/client/components/quick-commands/quick-commands-list.jsx +128 -0
- package/client/components/quick-commands/quick-commands-select.jsx +38 -0
- package/client/components/session/session.jsx +533 -0
- package/client/components/session/session.styl +53 -0
- package/client/components/session/sessions.jsx +445 -0
- package/client/components/setting-panel/bookmark-transport.jsx +148 -0
- package/client/components/setting-panel/bookmark-tree-list.jsx +14 -0
- package/client/components/setting-panel/col.jsx +18 -0
- package/client/components/setting-panel/list.jsx +186 -0
- package/client/components/setting-panel/list.styl +33 -0
- package/client/components/setting-panel/on-tree-drop.js +222 -0
- package/client/components/setting-panel/setting-modal.jsx +163 -0
- package/client/components/setting-panel/setting-wrap.jsx +37 -0
- package/client/components/setting-panel/setting-wrap.styl +52 -0
- package/client/components/setting-panel/setting.jsx +858 -0
- package/client/components/setting-panel/setting.styl +4 -0
- package/client/components/setting-panel/start-session-select.jsx +91 -0
- package/client/components/setting-panel/tab-bookmarks.jsx +37 -0
- package/client/components/setting-panel/tab-history.jsx +44 -0
- package/client/components/setting-panel/tab-quick-commands.jsx +38 -0
- package/client/components/setting-panel/tab-settings.jsx +42 -0
- package/client/components/setting-panel/tab-themes.jsx +34 -0
- package/client/components/setting-panel/tree-list.jsx +978 -0
- package/client/components/setting-panel/tree-list.styl +57 -0
- package/client/components/setting-sync/data-import.jsx +65 -0
- package/client/components/setting-sync/setting-sync-form.jsx +271 -0
- package/client/components/setting-sync/setting-sync.jsx +81 -0
- package/client/components/setting-sync/sync.styl +7 -0
- package/client/components/sftp/address-bar.jsx +139 -0
- package/client/components/sftp/address-bookmark-item.jsx +47 -0
- package/client/components/sftp/address-bookmark.jsx +81 -0
- package/client/components/sftp/address-bookmark.styl +8 -0
- package/client/components/sftp/confirm-modal.jsx +184 -0
- package/client/components/sftp/file-icon.jsx +22 -0
- package/client/components/sftp/file-item.jsx +1226 -0
- package/client/components/sftp/file-mode-modal.jsx +205 -0
- package/client/components/sftp/file-props-modal.jsx +211 -0
- package/client/components/sftp/file-read.js +81 -0
- package/client/components/sftp/list-table-ui.jsx +547 -0
- package/client/components/sftp/owner-list.js +97 -0
- package/client/components/sftp/paged-list.jsx +60 -0
- package/client/components/sftp/permission-render.jsx +42 -0
- package/client/components/sftp/sftp-entry.jsx +1069 -0
- package/client/components/sftp/sftp.styl +217 -0
- package/client/components/sftp/transfer-common.js +9 -0
- package/client/components/sftp/transfer-conflict.jsx +315 -0
- package/client/components/sftp/transfer-speed-format.js +60 -0
- package/client/components/sftp/transfer-tag.jsx +40 -0
- package/client/components/sftp/transfer-tag.styl +11 -0
- package/client/components/sftp/transfer.styl +55 -0
- package/client/components/sftp/transport-action.jsx +410 -0
- package/client/components/sftp/transport-entry.jsx +108 -0
- package/client/components/sftp/transport-types.js +8 -0
- package/client/components/sftp/transports-action.jsx +111 -0
- package/client/components/sftp/transports-ui.jsx +93 -0
- package/client/components/sftp/zip.js +42 -0
- package/client/components/sidebar/bookmark-select.jsx +48 -0
- package/client/components/sidebar/bookmark.jsx +82 -0
- package/client/components/sidebar/history.jsx +66 -0
- package/client/components/sidebar/index.jsx +230 -0
- package/client/components/sidebar/info-modal.jsx +250 -0
- package/client/components/sidebar/info.styl +27 -0
- package/client/components/sidebar/side-icon.jsx +25 -0
- package/client/components/sidebar/sidebar.styl +128 -0
- package/client/components/sidebar/transfer-history-modal.jsx +110 -0
- package/client/components/sidebar/transfer-history.styl +3 -0
- package/client/components/sidebar/transfer-list-control.jsx +205 -0
- package/client/components/sidebar/transfer-list.jsx +55 -0
- package/client/components/sidebar/transfer-modal.jsx +76 -0
- package/client/components/sidebar/transfer.styl +8 -0
- package/client/components/sidebar/transport-ui.jsx +109 -0
- package/client/components/tabs/index.jsx +320 -0
- package/client/components/tabs/tab.jsx +427 -0
- package/client/components/tabs/tabs.styl +220 -0
- package/client/components/tabs/window-control.jsx +55 -0
- package/client/components/terminal/attach-addon-custom.js +70 -0
- package/client/components/terminal/build-ls-term-id.js +5 -0
- package/client/components/terminal/index.jsx +1358 -0
- package/client/components/terminal/normal-buffer.jsx +33 -0
- package/client/components/terminal/term-search.jsx +224 -0
- package/client/components/terminal/term-search.styl +15 -0
- package/client/components/terminal/terminal-apis.js +31 -0
- package/client/components/terminal/terminal-interactive.jsx +148 -0
- package/client/components/terminal/terminal.styl +96 -0
- package/client/components/terminal/xterm-zmodem.js +48 -0
- package/client/components/terminal/zmodem-transfer.jsx +98 -0
- package/client/components/terminal/zmodem.styl +14 -0
- package/client/components/terminal-info/activity.jsx +54 -0
- package/client/components/terminal-info/base.jsx +25 -0
- package/client/components/terminal-info/content.jsx +101 -0
- package/client/components/terminal-info/data-cols-parser.jsx +50 -0
- package/client/components/terminal-info/disk.jsx +29 -0
- package/client/components/terminal-info/index.jsx +25 -0
- package/client/components/terminal-info/network.jsx +114 -0
- package/client/components/terminal-info/resource.jsx +80 -0
- package/client/components/terminal-info/run-cmd.jsx +273 -0
- package/client/components/terminal-info/terminal-info.styl +29 -0
- package/client/components/terminal-info/up.jsx +15 -0
- package/client/components/terminal-theme/index.jsx +264 -0
- package/client/components/terminal-theme/terminal-theme-list.styl +3 -0
- package/client/components/terminal-theme/theme-list.jsx +146 -0
- package/client/components/text-editor/text-editor-form.jsx +97 -0
- package/client/components/text-editor/text-editor.jsx +182 -0
- package/client/css/antd-overwrite.styl +14 -0
- package/client/css/basic.styl +38 -0
- package/client/css/includes/box.styl +154 -0
- package/client/css/includes/font-size.styl +6 -0
- package/client/css/includes/index.styl +3 -0
- package/client/css/includes/text.styl +31 -0
- package/client/css/includes/theme-default.styl +20 -0
- package/client/entry/basic.js +58 -0
- package/client/entry/index.jsx +15 -0
- package/client/entry/worker.js +137 -0
- package/client/store/address-bookmark.js +25 -0
- package/client/store/app-upgrade.js +23 -0
- package/client/store/batch-input-history.js +26 -0
- package/client/store/bookmark-group.js +128 -0
- package/client/store/bookmark.js +22 -0
- package/client/store/common.js +140 -0
- package/client/store/context-menu.js +23 -0
- package/client/store/db-upgrade.js +43 -0
- package/client/store/event.js +70 -0
- package/client/store/index.js +335 -0
- package/client/store/init-state.js +191 -0
- package/client/store/item.js +120 -0
- package/client/store/load-data.js +198 -0
- package/client/store/quick-command.js +43 -0
- package/client/store/session.js +54 -0
- package/client/store/setting.js +208 -0
- package/client/store/sidebar.js +48 -0
- package/client/store/sync.js +390 -0
- package/client/store/system-menu.js +120 -0
- package/client/store/tab.js +74 -0
- package/client/store/terminal-theme.js +116 -0
- package/client/store/transfer-history.js +27 -0
- package/client/store/transfer-list.js +20 -0
- package/client/store/ui-theme.js +71 -0
- package/client/store/watch.js +116 -0
- package/client/views/index.pug +58 -0
- package/package.json +34 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run command in remote terminal
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { runCmd } from '../terminal/terminal-apis'
|
|
6
|
+
import { useEffect } from 'react'
|
|
7
|
+
import wait from '../../common/wait'
|
|
8
|
+
import parseInt10 from '../../common/parse-int10'
|
|
9
|
+
|
|
10
|
+
function formatActivities (str) {
|
|
11
|
+
if (!str) {
|
|
12
|
+
return {
|
|
13
|
+
activities: []
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const r = str.split('\n')
|
|
17
|
+
.map(a => a.trim())
|
|
18
|
+
.filter(s => s)
|
|
19
|
+
.map(st => {
|
|
20
|
+
const arr = st.split(/ +/)
|
|
21
|
+
return {
|
|
22
|
+
pid: arr[0],
|
|
23
|
+
user: arr[1],
|
|
24
|
+
cpu: parseFloat(arr[2]),
|
|
25
|
+
mem: parseInt10(arr[3]),
|
|
26
|
+
cmd: arr.slice(4).join(' ')
|
|
27
|
+
}
|
|
28
|
+
}).filter(d => d.pid)
|
|
29
|
+
return {
|
|
30
|
+
activities: r
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatDisks (str) {
|
|
35
|
+
if (!str) {
|
|
36
|
+
return {
|
|
37
|
+
disks: []
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const r = str.split('\n')
|
|
41
|
+
.slice(1)
|
|
42
|
+
.map(s => {
|
|
43
|
+
const arr = s.split(/ +/)
|
|
44
|
+
return {
|
|
45
|
+
filesystem: arr[0],
|
|
46
|
+
size: arr[1],
|
|
47
|
+
used: arr[2],
|
|
48
|
+
avail: arr[3],
|
|
49
|
+
usedPercent: arr[4],
|
|
50
|
+
mount: arr[5]
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
.filter(d => d.filesystem)
|
|
54
|
+
return {
|
|
55
|
+
disks: r
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function formatCpu (str) {
|
|
60
|
+
if (!str) {
|
|
61
|
+
return {
|
|
62
|
+
cpu: ''
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
cpu: str.split(' ')[1]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function formatMem (str) {
|
|
71
|
+
if (!str) {
|
|
72
|
+
return {}
|
|
73
|
+
}
|
|
74
|
+
const names = ['mem', 'swap']
|
|
75
|
+
return str
|
|
76
|
+
.split('\n')
|
|
77
|
+
.filter(d => d)
|
|
78
|
+
.slice(1)
|
|
79
|
+
.reduce((p, d, i) => {
|
|
80
|
+
const arr = d.split(/\s+/)
|
|
81
|
+
if (!arr[1]) {
|
|
82
|
+
return p
|
|
83
|
+
}
|
|
84
|
+
p[names[i]] = {
|
|
85
|
+
total: arr[1],
|
|
86
|
+
used: arr[2],
|
|
87
|
+
free: arr[3]
|
|
88
|
+
}
|
|
89
|
+
return p
|
|
90
|
+
}, {})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const ipSplitReg = /\n[\d]{1,5}:\s+/
|
|
94
|
+
const ipNameReg = /inet\s+([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})\/\d/
|
|
95
|
+
|
|
96
|
+
function formatIps (ips) {
|
|
97
|
+
if (!ips) {
|
|
98
|
+
return {}
|
|
99
|
+
}
|
|
100
|
+
const arr = ips.split(ipSplitReg)
|
|
101
|
+
return arr.reduce((p, s) => {
|
|
102
|
+
const name = s.replace(/^[\d]{1,5}:\s+/, '').split(/:\s+/)[0]
|
|
103
|
+
const arr1 = s.match(ipNameReg)
|
|
104
|
+
return {
|
|
105
|
+
...p,
|
|
106
|
+
[name]: {
|
|
107
|
+
ip: arr1 ? arr1[1] : ''
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, {})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function formatTraffic (traffic, ipObj) {
|
|
114
|
+
if (!traffic) {
|
|
115
|
+
return ipObj
|
|
116
|
+
}
|
|
117
|
+
const arr = traffic.split(ipSplitReg)
|
|
118
|
+
return arr.reduce((p, s) => {
|
|
119
|
+
const name = s.replace(/^[\d]{1,5}:\s+/, '').split(/:\s+/)[0]
|
|
120
|
+
const arr1 = s.split('\n')
|
|
121
|
+
let download = 0
|
|
122
|
+
let upload = 0
|
|
123
|
+
const len = arr1.length
|
|
124
|
+
for (let i = 0; i < len; i++) {
|
|
125
|
+
const line = arr1[i]
|
|
126
|
+
if (line.toLowerCase().trim().startsWith('rx')) {
|
|
127
|
+
download = Number(arr1[i + 1].trim().split(/\s+/)[0])
|
|
128
|
+
} else if (line.trim().toLowerCase().startsWith('tx')) {
|
|
129
|
+
upload = Number(arr1[i + 1].trim().split(/\s+/)[0])
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!p[name]) {
|
|
133
|
+
p[name] = {}
|
|
134
|
+
}
|
|
135
|
+
Object.assign(p[name], {
|
|
136
|
+
download, upload
|
|
137
|
+
})
|
|
138
|
+
return p
|
|
139
|
+
}, ipObj)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function formatNetwork (traffic, ips) {
|
|
143
|
+
const ipObj = formatIps(ips)
|
|
144
|
+
return {
|
|
145
|
+
network: formatTraffic(traffic, ipObj)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// function format (arr) {
|
|
150
|
+
// if (!arr) {
|
|
151
|
+
// return {}
|
|
152
|
+
// }
|
|
153
|
+
// // const arr = res.split(sepStr)
|
|
154
|
+
// // console.log(arr)
|
|
155
|
+
// const uptime = arr[0]
|
|
156
|
+
// const activities = formatActivities(arr[1])
|
|
157
|
+
// const disks = formatDisks(arr[2])
|
|
158
|
+
// const cpu = formatCpu(arr[3])
|
|
159
|
+
// const { mem, swap } = formatMem(arr[4])
|
|
160
|
+
// const { network, ip } = formatNetwork(arr[5], arr[6])
|
|
161
|
+
// const final = {
|
|
162
|
+
// ip,
|
|
163
|
+
// uptime,
|
|
164
|
+
// activities,
|
|
165
|
+
// disks,
|
|
166
|
+
// cpu,
|
|
167
|
+
// mem,
|
|
168
|
+
// swap,
|
|
169
|
+
// network
|
|
170
|
+
// }
|
|
171
|
+
// return final
|
|
172
|
+
// }
|
|
173
|
+
|
|
174
|
+
export async function runCmds (props, cmds) {
|
|
175
|
+
const {
|
|
176
|
+
pid,
|
|
177
|
+
sessionId
|
|
178
|
+
} = props
|
|
179
|
+
const ress = []
|
|
180
|
+
for (const cmd of cmds) {
|
|
181
|
+
const res = await runCmd(pid, sessionId, cmd)
|
|
182
|
+
ress.push(res || '')
|
|
183
|
+
}
|
|
184
|
+
return ress
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function InfoGetter (props) {
|
|
188
|
+
const {
|
|
189
|
+
// name,
|
|
190
|
+
cmd,
|
|
191
|
+
cmds,
|
|
192
|
+
interval,
|
|
193
|
+
formatter,
|
|
194
|
+
delay
|
|
195
|
+
} = props.options
|
|
196
|
+
const cms = cmds || [cmd]
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
const run = async () => {
|
|
199
|
+
await wait(delay)
|
|
200
|
+
const ress = await runCmds(props, cms)
|
|
201
|
+
const update = formatter(...ress)
|
|
202
|
+
props.setState(update)
|
|
203
|
+
}
|
|
204
|
+
run()
|
|
205
|
+
const ref = setInterval(run, interval)
|
|
206
|
+
return () => {
|
|
207
|
+
clearInterval(ref)
|
|
208
|
+
}
|
|
209
|
+
}, [])
|
|
210
|
+
return null
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export default (props) => {
|
|
214
|
+
if (!props.isRemote) {
|
|
215
|
+
return null
|
|
216
|
+
}
|
|
217
|
+
const cmds = [
|
|
218
|
+
{
|
|
219
|
+
name: 'uptime',
|
|
220
|
+
cmd: 'uptime -p',
|
|
221
|
+
interval: 5000,
|
|
222
|
+
delay: 0,
|
|
223
|
+
formatter: d => ({ uptime: d })
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: 'activities',
|
|
227
|
+
cmd: 'ps --no-headers -o pid,user,%cpu,size,command ax | sort -b -k3 -r',
|
|
228
|
+
interval: 5000,
|
|
229
|
+
delay: 800,
|
|
230
|
+
formatter: formatActivities
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'disks',
|
|
234
|
+
cmd: 'df -h',
|
|
235
|
+
interval: 10000,
|
|
236
|
+
delay: 1600,
|
|
237
|
+
formatter: formatDisks
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: 'cpu',
|
|
241
|
+
cmd: '(grep \'cpu \' /proc/stat;sleep 0.1;grep \'cpu \' /proc/stat)|awk -v RS="" \'{print "CPU "($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)"%"}\'',
|
|
242
|
+
interval: 5000,
|
|
243
|
+
formatter: formatCpu,
|
|
244
|
+
delay: 2400
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'mem',
|
|
248
|
+
cmd: 'free -h',
|
|
249
|
+
interval: 5000,
|
|
250
|
+
delay: 3200,
|
|
251
|
+
formatter: formatMem
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: 'network',
|
|
255
|
+
cmds: [
|
|
256
|
+
'ip -s link',
|
|
257
|
+
'ip addr'
|
|
258
|
+
],
|
|
259
|
+
delay: 4000,
|
|
260
|
+
formatter: formatNetwork,
|
|
261
|
+
interval: 5000
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
return cmds.map(options => {
|
|
265
|
+
return (
|
|
266
|
+
<InfoGetter
|
|
267
|
+
key={'info-getter-' + options.name}
|
|
268
|
+
{...props}
|
|
269
|
+
options={options}
|
|
270
|
+
/>
|
|
271
|
+
)
|
|
272
|
+
})
|
|
273
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@require '../../css/includes/theme-default'
|
|
2
|
+
.terminal-info-icon
|
|
3
|
+
color text-dark
|
|
4
|
+
&:hover
|
|
5
|
+
color text
|
|
6
|
+
.info-panel-wrap
|
|
7
|
+
position fixed
|
|
8
|
+
right 0
|
|
9
|
+
top 100px
|
|
10
|
+
bottom 0
|
|
11
|
+
width 500px
|
|
12
|
+
background main
|
|
13
|
+
color text
|
|
14
|
+
box-shadow 0px 3px 3px 3px alpha(main, .25)
|
|
15
|
+
z-index 100
|
|
16
|
+
overflow-y scroll
|
|
17
|
+
opacity .9
|
|
18
|
+
.terminal-info-section
|
|
19
|
+
padding 10px 0
|
|
20
|
+
.terminal-info-act
|
|
21
|
+
.terminal-info-disk
|
|
22
|
+
.terminal-info-network
|
|
23
|
+
max-height 260px
|
|
24
|
+
overflow-y scroll
|
|
25
|
+
.activity-item
|
|
26
|
+
.activity-item-copy
|
|
27
|
+
display none
|
|
28
|
+
&:hover .activity-item-copy
|
|
29
|
+
display inline
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* up time info
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export default function TerminalInfoUp (props) {
|
|
6
|
+
const { uptime } = props
|
|
7
|
+
if (!props.isRemote) {
|
|
8
|
+
return null
|
|
9
|
+
}
|
|
10
|
+
return (
|
|
11
|
+
<div className='terminal-info-section terminal-info-up'>
|
|
12
|
+
<b>uptime</b>: {uptime}
|
|
13
|
+
</div>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { useRef } from 'react'
|
|
2
|
+
import { Button, Input, message, Upload, Form } from 'antd'
|
|
3
|
+
import { convertTheme, convertThemeToText, exportTheme, validThemeProps, requiredThemeProps } from '../../common/terminal-theme'
|
|
4
|
+
import { defaultTheme, defaultThemeLight } from '../../common/constants'
|
|
5
|
+
import generate from '../../common/uid'
|
|
6
|
+
import Link from '../common/external-link'
|
|
7
|
+
import InputAutoFocus from '../common/input-auto-focus'
|
|
8
|
+
|
|
9
|
+
const { TextArea } = Input
|
|
10
|
+
const FormItem = Form.Item
|
|
11
|
+
const { prefix } = window
|
|
12
|
+
const e = prefix('form')
|
|
13
|
+
const s = prefix('setting')
|
|
14
|
+
const t = prefix('terminalThemes')
|
|
15
|
+
|
|
16
|
+
export default function ThemeForm (props) {
|
|
17
|
+
const [form] = Form.useForm()
|
|
18
|
+
const action = useRef('submit')
|
|
19
|
+
function exporter () {
|
|
20
|
+
exportTheme(props.formData.id)
|
|
21
|
+
}
|
|
22
|
+
function saveOnly () {
|
|
23
|
+
action.current = 'saveOnly'
|
|
24
|
+
form.submit()
|
|
25
|
+
}
|
|
26
|
+
// A function to validate the input text
|
|
27
|
+
async function validateInput (_, value) {
|
|
28
|
+
const input = value
|
|
29
|
+
.split('\n')
|
|
30
|
+
.reduce((p, line) => {
|
|
31
|
+
const [name, value] = line.split('=')
|
|
32
|
+
if (!name.trim() || !value.trim()) {
|
|
33
|
+
return p
|
|
34
|
+
}
|
|
35
|
+
p[name.trim()] = value.trim()
|
|
36
|
+
return p
|
|
37
|
+
}, {})
|
|
38
|
+
|
|
39
|
+
// A regex to test the hex color format
|
|
40
|
+
const hexColorRegex = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
|
41
|
+
|
|
42
|
+
// A regex to test the rgba color format
|
|
43
|
+
const rgbaColorRegex = /^rgba\(\d{1,3}, +\d{1,3}, +\d{1,3}, +(0|0?\.\d+|1)\)$/
|
|
44
|
+
|
|
45
|
+
// A message to store the error message
|
|
46
|
+
let message = ''
|
|
47
|
+
|
|
48
|
+
// Loop through the required props
|
|
49
|
+
for (const prop of requiredThemeProps) {
|
|
50
|
+
// Check if the input has the prop
|
|
51
|
+
if (!input[prop]) {
|
|
52
|
+
// If not, set the flag to false and append the message
|
|
53
|
+
message += `Missing prop: ${prop}\n`
|
|
54
|
+
// Skip the rest of the loop
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Check if the prop starts with terminal:
|
|
59
|
+
if (prop.startsWith('terminal:')) {
|
|
60
|
+
// If yes, check if the prop value is a valid rgba color format
|
|
61
|
+
if (!rgbaColorRegex.test(input[prop]) && !hexColorRegex.test(input[prop])) {
|
|
62
|
+
// If not, set the flag to false and append the message
|
|
63
|
+
message += `Invalid color format for prop: ${prop}\n`
|
|
64
|
+
// Skip the rest of the loop
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
// If no, check if the prop value is a valid hex color format
|
|
69
|
+
if (!hexColorRegex.test(input[prop])) {
|
|
70
|
+
// If not, set the flag to false and append the message
|
|
71
|
+
message += `Invalid hex color format for prop: ${prop}\n`
|
|
72
|
+
// Skip the rest of the loop
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const keys = Object.keys(input)
|
|
79
|
+
for (const key of keys) {
|
|
80
|
+
if (!validThemeProps.includes(key)) {
|
|
81
|
+
message += `Not supported prop: ${key}\n`
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (message) {
|
|
85
|
+
return Promise.reject(message)
|
|
86
|
+
}
|
|
87
|
+
// Return an object with the flag and the message
|
|
88
|
+
return Promise.resolve()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function handleSubmit (res) {
|
|
92
|
+
const { formData } = props
|
|
93
|
+
const {
|
|
94
|
+
themeName,
|
|
95
|
+
themeText
|
|
96
|
+
} = res
|
|
97
|
+
const update = {
|
|
98
|
+
name: themeName,
|
|
99
|
+
...convertTheme(themeText)
|
|
100
|
+
}
|
|
101
|
+
const update1 = {
|
|
102
|
+
...update,
|
|
103
|
+
id: generate()
|
|
104
|
+
}
|
|
105
|
+
if (formData.id) {
|
|
106
|
+
props.store.editTheme(formData.id, update)
|
|
107
|
+
} else {
|
|
108
|
+
props.store.addTheme(update1)
|
|
109
|
+
props.store.storeAssign({
|
|
110
|
+
item: update1
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
if (action.current !== 'saveOnly') {
|
|
114
|
+
props.store.setTheme(
|
|
115
|
+
formData.id || update1.id
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
message.success(s('saved'))
|
|
119
|
+
action.current = 'submit'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderSrc (type) {
|
|
123
|
+
if (type === 'iterm') {
|
|
124
|
+
const url = `https://github.com/mbadolato/iTerm2-Color-Schemes/blob/master/electerm/${encodeURIComponent(themeName)}.txt`
|
|
125
|
+
return (
|
|
126
|
+
<FormItem>
|
|
127
|
+
<span className='mg1r'>src:</span>
|
|
128
|
+
<Link
|
|
129
|
+
to={url}
|
|
130
|
+
>{url}
|
|
131
|
+
</Link>
|
|
132
|
+
</FormItem>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
return null
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function beforeUpload (file) {
|
|
139
|
+
const txt = await window.fs.readFile(file.path)
|
|
140
|
+
const { name, themeConfig, uiThemeConfig } = convertTheme(txt)
|
|
141
|
+
form.setFieldsValue({
|
|
142
|
+
themeName: name,
|
|
143
|
+
themeText: convertThemeToText({
|
|
144
|
+
themeConfig, uiThemeConfig
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
return false
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function renderFuncs (id) {
|
|
151
|
+
if (!id) {
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
return (
|
|
155
|
+
<FormItem>
|
|
156
|
+
<Button
|
|
157
|
+
type='dashed'
|
|
158
|
+
onClick={exporter}
|
|
159
|
+
>
|
|
160
|
+
{t('export')}
|
|
161
|
+
</Button>
|
|
162
|
+
</FormItem>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const {
|
|
167
|
+
readOnly,
|
|
168
|
+
id,
|
|
169
|
+
type,
|
|
170
|
+
name: themeName
|
|
171
|
+
} = props.formData
|
|
172
|
+
const initialValues = {
|
|
173
|
+
themeName,
|
|
174
|
+
themeText: convertThemeToText(props.formData)
|
|
175
|
+
}
|
|
176
|
+
const { autofocustrigger } = props.store
|
|
177
|
+
const isDefaultTheme = id === defaultTheme.id || id === defaultThemeLight.id
|
|
178
|
+
const disabled = readOnly || isDefaultTheme
|
|
179
|
+
return (
|
|
180
|
+
<Form
|
|
181
|
+
onFinish={handleSubmit}
|
|
182
|
+
form={form}
|
|
183
|
+
initialValues={initialValues}
|
|
184
|
+
className='form-wrap'
|
|
185
|
+
name='terminal-theme-form'
|
|
186
|
+
layout='vertical'
|
|
187
|
+
>
|
|
188
|
+
{renderFuncs(id)}
|
|
189
|
+
<FormItem
|
|
190
|
+
label={t('themeName')}
|
|
191
|
+
hasFeedback
|
|
192
|
+
name='themeName'
|
|
193
|
+
rules={[{
|
|
194
|
+
max: 30, message: '30 chars max'
|
|
195
|
+
}, {
|
|
196
|
+
required: true, message: 'theme name required'
|
|
197
|
+
}]}
|
|
198
|
+
>
|
|
199
|
+
<InputAutoFocus
|
|
200
|
+
selectall='yes'
|
|
201
|
+
disabled={disabled}
|
|
202
|
+
autofocustrigger={autofocustrigger}
|
|
203
|
+
/>
|
|
204
|
+
</FormItem>
|
|
205
|
+
<FormItem
|
|
206
|
+
label={t('themeConfig')}
|
|
207
|
+
>
|
|
208
|
+
<div className='pd1b'>
|
|
209
|
+
<Upload
|
|
210
|
+
beforeUpload={beforeUpload}
|
|
211
|
+
fileList={[]}
|
|
212
|
+
className='mg1b'
|
|
213
|
+
>
|
|
214
|
+
<Button
|
|
215
|
+
type='dashed'
|
|
216
|
+
disabled={disabled}
|
|
217
|
+
>
|
|
218
|
+
{e('importFromFile')}
|
|
219
|
+
</Button>
|
|
220
|
+
</Upload>
|
|
221
|
+
</div>
|
|
222
|
+
<FormItem
|
|
223
|
+
noStyle
|
|
224
|
+
name='themeText'
|
|
225
|
+
hasFeedback
|
|
226
|
+
rules={[{
|
|
227
|
+
max: 1000, message: '1000 chars max'
|
|
228
|
+
}, {
|
|
229
|
+
required: true, message: 'theme Config required'
|
|
230
|
+
}, {
|
|
231
|
+
validator: validateInput
|
|
232
|
+
}]}
|
|
233
|
+
>
|
|
234
|
+
<TextArea rows={33} disabled={disabled} />
|
|
235
|
+
</FormItem>
|
|
236
|
+
</FormItem>
|
|
237
|
+
{
|
|
238
|
+
disabled
|
|
239
|
+
? null
|
|
240
|
+
: (
|
|
241
|
+
<FormItem>
|
|
242
|
+
<p>
|
|
243
|
+
<Button
|
|
244
|
+
type='primary'
|
|
245
|
+
htmlType='submit'
|
|
246
|
+
className='mg1r mg1b'
|
|
247
|
+
>{t('saveAndApply')}
|
|
248
|
+
</Button>
|
|
249
|
+
<Button
|
|
250
|
+
type='dashed'
|
|
251
|
+
className='mg1r mg1b'
|
|
252
|
+
onClick={saveOnly}
|
|
253
|
+
>{e('save')}
|
|
254
|
+
</Button>
|
|
255
|
+
</p>
|
|
256
|
+
</FormItem>
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
{
|
|
260
|
+
renderSrc(type)
|
|
261
|
+
}
|
|
262
|
+
</Form>
|
|
263
|
+
)
|
|
264
|
+
}
|