pywebexec 1.1.2__py3-none-any.whl → 1.4.12__py3-none-any.whl
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.
- pywebexec/pywebexec.py +255 -94
- pywebexec/static/css/Consolas NF.ttf +0 -0
- pywebexec/static/css/style.css +187 -18
- pywebexec/static/css/xterm.css +209 -0
- pywebexec/static/images/down-arrow.svg +1 -0
- pywebexec/static/images/favicon.svg +8 -1
- pywebexec/static/images/popup.svg +1 -0
- pywebexec/static/images/running.gif +0 -0
- pywebexec/static/js/commands.js +223 -0
- pywebexec/static/js/popup.js +141 -0
- pywebexec/static/js/script.js +248 -110
- pywebexec/static/js/xterm/LICENSE +21 -0
- pywebexec/static/js/xterm/ansi_up.min.js +7 -0
- pywebexec/static/js/xterm/xterm-addon-fit.js +1 -0
- pywebexec/static/js/xterm/xterm.js +1 -0
- pywebexec/templates/index.html +23 -7
- pywebexec/templates/popup.html +24 -0
- pywebexec/version.py +2 -2
- {pywebexec-1.1.2.dist-info → pywebexec-1.4.12.dist-info}/METADATA +49 -19
- pywebexec-1.4.12.dist-info/RECORD +31 -0
- pywebexec/static/images/running.svg +0 -1
- pywebexec-1.1.2.dist-info/RECORD +0 -20
- {pywebexec-1.1.2.dist-info → pywebexec-1.4.12.dist-info}/LICENSE +0 -0
- {pywebexec-1.1.2.dist-info → pywebexec-1.4.12.dist-info}/WHEEL +0 -0
- {pywebexec-1.1.2.dist-info → pywebexec-1.4.12.dist-info}/entry_points.txt +0 -0
- {pywebexec-1.1.2.dist-info → pywebexec-1.4.12.dist-info}/top_level.txt +0 -0
pywebexec/static/js/script.js
CHANGED
@@ -1,131 +1,256 @@
|
|
1
1
|
let currentCommandId = null;
|
2
2
|
let outputInterval = null;
|
3
|
+
let nextOutputLink = null;
|
4
|
+
let fullOutput = '';
|
5
|
+
let outputLength = 0;
|
6
|
+
const maxScrollback = 99999;
|
7
|
+
const maxSize = 10485760; // 10MB
|
8
|
+
|
9
|
+
function initTerminal()
|
10
|
+
{
|
11
|
+
return new Terminal({
|
12
|
+
cursorBlink: false,
|
13
|
+
cursorInactiveStyle: 'none',
|
14
|
+
disableStdin: true,
|
15
|
+
convertEol: true,
|
16
|
+
fontFamily: 'Consolas NF, monospace, courier-new, courier',
|
17
|
+
scrollback: maxScrollback,
|
18
|
+
theme: {
|
19
|
+
background: '#111412',
|
20
|
+
black: '#111412',
|
21
|
+
green: '#088a5b',
|
22
|
+
blue: "#2760aa",
|
23
|
+
red: '#ba1611',
|
24
|
+
yellow: "#cf8700",
|
25
|
+
magenta: "#4c3d80",
|
26
|
+
cyan: "#00a7aa",
|
27
|
+
brightBlack: "#243C4F",
|
28
|
+
brightBlue: "#5584b1",
|
29
|
+
brightGreen: "#18Ed93",
|
30
|
+
},
|
31
|
+
customGlyphs: false,
|
32
|
+
rescaleOverlappingGlyphs: true,
|
33
|
+
});
|
34
|
+
}
|
35
|
+
let terminal = initTerminal()
|
36
|
+
|
37
|
+
const fitAddon = new FitAddon.FitAddon();
|
38
|
+
terminal.loadAddon(fitAddon);
|
39
|
+
terminal.open(document.getElementById('output'));
|
40
|
+
fitAddon.fit();
|
41
|
+
|
42
|
+
function getTokenParam() {
|
43
|
+
const urlParams = new URLSearchParams(window.location.search);
|
44
|
+
return urlParams.get('token') ? `?token=${urlParams.get('token')}` : '';
|
45
|
+
}
|
46
|
+
const urlToken = getTokenParam();
|
47
|
+
|
48
|
+
terminal.onSelectionChange(() => {
|
49
|
+
const selectionText = terminal.getSelection();
|
50
|
+
if (selectionText) {
|
51
|
+
navigator.clipboard.writeText(selectionText).catch(err => {
|
52
|
+
console.error('Failed to copy text to clipboard:', err);
|
53
|
+
});
|
54
|
+
}
|
55
|
+
});
|
3
56
|
|
4
57
|
document.getElementById('launchForm').addEventListener('submit', async (event) => {
|
5
58
|
event.preventDefault();
|
6
59
|
const commandName = document.getElementById('commandName').value;
|
7
60
|
const params = document.getElementById('params').value.split(' ');
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
61
|
+
try {
|
62
|
+
const response = await fetch(`/run_command${urlToken}`, {
|
63
|
+
method: 'POST',
|
64
|
+
headers: {
|
65
|
+
'Content-Type': 'application/json'
|
66
|
+
},
|
67
|
+
body: JSON.stringify({ command: commandName, params: params })
|
68
|
+
});
|
69
|
+
if (!response.ok) {
|
70
|
+
throw new Error('Failed to launch command');
|
71
|
+
}
|
72
|
+
const data = await response.json();
|
73
|
+
await new Promise(r => setTimeout(r, 300));
|
74
|
+
fetchCommands();
|
75
|
+
viewOutput(data.command_id);
|
76
|
+
commandInput.focus()
|
77
|
+
commandInput.setSelectionRange(0, commandInput.value.length)
|
78
|
+
} catch (error) {
|
79
|
+
console.log('Error running command:', error);
|
80
|
+
}
|
18
81
|
});
|
19
82
|
|
20
83
|
async function fetchCommands() {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
84
|
+
try {
|
85
|
+
const response = await fetch(`/commands${urlToken}`);
|
86
|
+
if (!response.ok) {
|
87
|
+
document.getElementById('dimmer').style.display = 'block';
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
const commands = await response.json();
|
91
|
+
commands.sort((a, b) => new Date(b.start_time) - new Date(a.start_time));
|
92
|
+
const commandsTbody = document.getElementById('commands');
|
93
|
+
commandsTbody.innerHTML = '';
|
94
|
+
if (!currentCommandId && commands.length) {
|
95
|
+
currentCommandId = commands[0].command_id;
|
96
|
+
viewOutput(currentCommandId);
|
97
|
+
}
|
98
|
+
commands.forEach(command => {
|
99
|
+
const commandRow = document.createElement('tr');
|
100
|
+
commandRow.className = `clickable-row ${command.command_id === currentCommandId ? 'currentcommand' : ''}`;
|
101
|
+
commandRow.onclick = () => viewOutput(command.command_id);
|
102
|
+
commandRow.innerHTML = `
|
103
|
+
<td class="monospace">
|
104
|
+
${navigator.clipboard == undefined ? `${command.command_id.slice(0, 8)}` : `<span class="copy_clip" onclick="copyToClipboard('${command.command_id}', this, event)">${command.command_id.slice(0, 8)}</span>`}
|
105
|
+
</td>
|
106
|
+
<td>${formatTime(command.start_time)}</td>
|
107
|
+
<td>${command.status === 'running' ? formatDuration(command.start_time, new Date().toISOString()) : formatDuration(command.start_time, command.end_time)}</td>
|
108
|
+
<td>${command.command.replace(/^\.\//, '')}</td>
|
109
|
+
<td><span class="status-icon status-${command.status}"></span>${command.status}${command.status === 'failed' ? ` (${command.exit_code})` : ''}</td>
|
110
|
+
<td>
|
111
|
+
${command.command.startsWith('term') ? '' : command.status === 'running' ? `<button onclick="stopCommand('${command.command_id}', event)">Stop</button>` : `<button onclick="relaunchCommand('${command.command_id}', event)">Run</button>`}
|
112
|
+
</td>
|
113
|
+
<td class="monospace outcol">
|
114
|
+
<button class="popup-button" onclick="openPopup('${command.command_id}', event)">
|
115
|
+
<img src="/static/images/popup.svg" alt="Popup">
|
116
|
+
</button>
|
117
|
+
${command.last_output_line || ''}
|
118
|
+
</td>
|
119
|
+
`;
|
120
|
+
commandsTbody.appendChild(commandRow);
|
121
|
+
});
|
122
|
+
document.getElementById('dimmer').style.display = 'none';
|
123
|
+
} catch (error) {
|
124
|
+
console.log('Error fetching commands:', error);
|
125
|
+
document.getElementById('dimmer').style.display = 'block';
|
29
126
|
}
|
30
|
-
commands.forEach(command => {
|
31
|
-
const commandRow = document.createElement('tr');
|
32
|
-
commandRow.className = `clickable-row ${command.command_id === currentCommandId ? 'currentcommand' : ''}`;
|
33
|
-
commandRow.onclick = () => viewOutput(command.command_id);
|
34
|
-
commandRow.innerHTML = `
|
35
|
-
<td class="monospace">
|
36
|
-
<span class="copy_clip" onclick="copyToClipboard('${command.command_id}', this)">${command.command_id.slice(0, 8)}</span>
|
37
|
-
</td>
|
38
|
-
<td><span class="status-icon status-${command.status}"></span>${command.status}</td>
|
39
|
-
<td>${formatTime(command.start_time)}</td>
|
40
|
-
<td>${command.status === 'running' ? formatDuration(command.start_time, new Date().toISOString()) : formatDuration(command.start_time, command.end_time)}</td>
|
41
|
-
<td>${command.exit_code}</td>
|
42
|
-
<td>${command.command.replace(/^\.\//, '')}</td>
|
43
|
-
<td>
|
44
|
-
${command.status === 'running' ? `<button onclick="stopCommand('${command.command_id}')">Stop</button>` : ` <button onclick="relaunchCommand('${command.command_id}')">Run</button>
|
45
|
-
`}
|
46
|
-
</td>
|
47
|
-
<td class="monospace outcol">${command.last_output_line || ''}</td>
|
48
|
-
`;
|
49
|
-
commandsTbody.appendChild(commandRow);
|
50
|
-
});
|
51
|
-
}
|
52
|
-
|
53
|
-
async function fetchExecutables() {
|
54
|
-
const response = await fetch('/executables');
|
55
|
-
const executables = await response.json();
|
56
|
-
const commandNameSelect = document.getElementById('commandName');
|
57
|
-
commandNameSelect.innerHTML = '';
|
58
|
-
executables.forEach(executable => {
|
59
|
-
const option = document.createElement('option');
|
60
|
-
option.value = executable;
|
61
|
-
option.textContent = executable;
|
62
|
-
commandNameSelect.appendChild(option);
|
63
|
-
});
|
64
127
|
}
|
65
128
|
|
66
|
-
async function fetchOutput(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
outputDiv.scrollTop = outputDiv.scrollHeight;
|
76
|
-
if (data.status != 'running') {
|
129
|
+
async function fetchOutput(url) {
|
130
|
+
try {
|
131
|
+
const response = await fetch(url);
|
132
|
+
if (!response.ok) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
const data = await response.json();
|
136
|
+
if (data.error) {
|
137
|
+
terminal.write(data.error);
|
77
138
|
clearInterval(outputInterval);
|
139
|
+
} else {
|
140
|
+
slider = document.getElementById('outputSlider')
|
141
|
+
percentage = slider.value;
|
142
|
+
fullOutput += data.output;
|
143
|
+
if (fullOutput.length > maxSize)
|
144
|
+
fullOutput = fullOutput.slice(-maxSize);
|
145
|
+
if (percentage == 100)
|
146
|
+
terminal.write(data.output); //.replace(/ \r/g, "\r\n")); tty size mismatch
|
147
|
+
else {
|
148
|
+
percentage = Math.round((outputLength * 100)/fullOutput.length);
|
149
|
+
slider.value = percentage;
|
150
|
+
document.getElementById('outputPercentage').innerText = `${percentage}%`;
|
151
|
+
}
|
152
|
+
nextOutputLink = data.links.next;
|
153
|
+
if (data.status != 'running') {
|
154
|
+
clearInterval(outputInterval);
|
155
|
+
}
|
78
156
|
}
|
157
|
+
} catch (error) {
|
158
|
+
console.log('Error fetching output:', error);
|
79
159
|
}
|
80
160
|
}
|
81
161
|
|
82
162
|
async function viewOutput(command_id) {
|
163
|
+
document.getElementById('outputSlider').value = 100;
|
83
164
|
adjustOutputHeight();
|
84
165
|
currentCommandId = command_id;
|
166
|
+
nextOutputLink = `/command_output/${command_id}${urlToken}`;
|
85
167
|
clearInterval(outputInterval);
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
168
|
+
terminal.clear();
|
169
|
+
terminal.reset();
|
170
|
+
fullOutput = '';
|
171
|
+
try {
|
172
|
+
const response = await fetch(`/command_status/${command_id}${urlToken}`);
|
173
|
+
if (!response.ok) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
const data = await response.json();
|
177
|
+
if (data.command == 'term')
|
178
|
+
terminal.options.cursorInactiveStyle = 'outline';
|
179
|
+
else
|
180
|
+
terminal.options.cursorInactiveStyle = 'none';
|
181
|
+
if (data.status === 'running') {
|
182
|
+
fetchOutput(nextOutputLink);
|
183
|
+
outputInterval = setInterval(() => fetchOutput(nextOutputLink), 1000);
|
184
|
+
} else {
|
185
|
+
fetchOutput(nextOutputLink);
|
186
|
+
}
|
187
|
+
fetchCommands(); // Refresh the command list to highlight the current command
|
188
|
+
} catch (error) {
|
189
|
+
console.log('Error viewing output:', error);
|
93
190
|
}
|
94
|
-
fetchCommands(); // Refresh the command list to highlight the current command
|
95
191
|
}
|
96
192
|
|
97
|
-
async function
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
return;
|
103
|
-
}
|
104
|
-
const relaunchResponse = await fetch('/run_command', {
|
105
|
-
method: 'POST',
|
106
|
-
headers: {
|
107
|
-
'Content-Type': 'application/json'
|
108
|
-
},
|
109
|
-
body: JSON.stringify({
|
110
|
-
command: data.command,
|
111
|
-
params: data.params
|
112
|
-
})
|
113
|
-
});
|
114
|
-
const relaunchData = await relaunchResponse.json();
|
115
|
-
fetchCommands();
|
116
|
-
viewOutput(relaunchData.command_id);
|
193
|
+
async function openPopup(command_id, event) {
|
194
|
+
event.stopPropagation();
|
195
|
+
event.stopImmediatePropagation();
|
196
|
+
const popupUrl = `/popup/${command_id}${urlToken}`;
|
197
|
+
window.open(popupUrl, '_blank', 'width=1000,height=600');
|
117
198
|
}
|
118
199
|
|
119
|
-
async function
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
200
|
+
async function relaunchCommand(command_id, event) {
|
201
|
+
event.stopPropagation();
|
202
|
+
event.stopImmediatePropagation();
|
203
|
+
try {
|
204
|
+
const response = await fetch(`/command_status/${command_id}${urlToken}`);
|
205
|
+
if (!response.ok) {
|
206
|
+
throw new Error('Failed to fetch command status');
|
207
|
+
}
|
208
|
+
const data = await response.json();
|
209
|
+
if (data.error) {
|
210
|
+
alert(data.error);
|
211
|
+
return;
|
212
|
+
}
|
213
|
+
const relaunchResponse = await fetch(`/run_command${urlToken}`, {
|
214
|
+
method: 'POST',
|
215
|
+
headers: {
|
216
|
+
'Content-Type': 'application/json'
|
217
|
+
},
|
218
|
+
body: JSON.stringify({
|
219
|
+
command: data.command,
|
220
|
+
params: data.params
|
221
|
+
})
|
222
|
+
});
|
223
|
+
if (!relaunchResponse.ok) {
|
224
|
+
throw new Error('Failed to relaunch command');
|
225
|
+
}
|
226
|
+
const relaunchData = await relaunchResponse.json();
|
128
227
|
fetchCommands();
|
228
|
+
viewOutput(relaunchData.command_id);
|
229
|
+
} catch (error) {
|
230
|
+
console.log('Error relaunching command:', error);
|
231
|
+
alert('Failed to relaunch command. Please try again.');
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
async function stopCommand(command_id, event) {
|
236
|
+
event.stopPropagation();
|
237
|
+
event.stopImmediatePropagation();
|
238
|
+
try {
|
239
|
+
const response = await fetch(`/stop_command/${command_id}${urlToken}`, {
|
240
|
+
method: 'POST'
|
241
|
+
});
|
242
|
+
if (!response.ok) {
|
243
|
+
throw new Error('Failed to stop command');
|
244
|
+
}
|
245
|
+
const data = await response.json();
|
246
|
+
if (data.error) {
|
247
|
+
alert(data.error);
|
248
|
+
} else {
|
249
|
+
fetchCommands();
|
250
|
+
}
|
251
|
+
} catch (error) {
|
252
|
+
console.log('Error stopping command:', error);
|
253
|
+
alert('Failed to stop command. Please try again.');
|
129
254
|
}
|
130
255
|
}
|
131
256
|
|
@@ -146,12 +271,14 @@ function formatDuration(startTime, endTime) {
|
|
146
271
|
return `${hours}h ${minutes}m ${seconds}s`;
|
147
272
|
}
|
148
273
|
|
149
|
-
function copyToClipboard(text, element) {
|
274
|
+
function copyToClipboard(text, element, event) {
|
275
|
+
event.stopPropagation();
|
276
|
+
event.stopImmediatePropagation();
|
150
277
|
navigator.clipboard.writeText(text).then(() => {
|
151
278
|
element.classList.add('copy_clip_ok');
|
152
279
|
setTimeout(() => {
|
153
280
|
element.classList.remove('copy_clip_ok');
|
154
|
-
},
|
281
|
+
}, 1000);
|
155
282
|
});
|
156
283
|
}
|
157
284
|
|
@@ -159,8 +286,9 @@ function adjustOutputHeight() {
|
|
159
286
|
const outputDiv = document.getElementById('output');
|
160
287
|
const windowHeight = window.innerHeight;
|
161
288
|
const outputTop = outputDiv.getBoundingClientRect().top;
|
162
|
-
const maxHeight = windowHeight - outputTop -
|
163
|
-
outputDiv.style.
|
289
|
+
const maxHeight = windowHeight - outputTop - 60; // Adjusted for slider height
|
290
|
+
outputDiv.style.height = `${maxHeight}px`;
|
291
|
+
fitAddon.fit();
|
164
292
|
}
|
165
293
|
|
166
294
|
function initResizer() {
|
@@ -186,12 +314,22 @@ function initResizer() {
|
|
186
314
|
}
|
187
315
|
}
|
188
316
|
|
317
|
+
function sliderUpdateOutput()
|
318
|
+
{
|
319
|
+
const slider = document.getElementById('outputSlider');
|
320
|
+
const percentage = slider.value;
|
321
|
+
outputLength = Math.floor((fullOutput.length * percentage) / 100);
|
322
|
+
const limitedOutput = fullOutput.slice(0, outputLength);
|
323
|
+
terminal.clear();
|
324
|
+
terminal.reset();
|
325
|
+
terminal.write(limitedOutput);
|
326
|
+
document.getElementById('outputPercentage').innerText = `${percentage}%`;
|
327
|
+
}
|
328
|
+
|
329
|
+
document.getElementById('outputSlider').addEventListener('input', sliderUpdateOutput);
|
330
|
+
|
189
331
|
window.addEventListener('resize', adjustOutputHeight);
|
190
|
-
window.addEventListener('load',
|
191
|
-
adjustOutputHeight();
|
192
|
-
initResizer();
|
193
|
-
});
|
332
|
+
window.addEventListener('load', initResizer);
|
194
333
|
|
195
|
-
fetchExecutables();
|
196
334
|
fetchCommands();
|
197
|
-
setInterval(fetchCommands, 5000);
|
335
|
+
setInterval(fetchCommands, 5000);
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016-2023 xterm.js contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Minified by jsDelivr using Terser v5.19.2.
|
3
|
+
* Original file: /npm/ansi_up@5.0.0/ansi_up.js
|
4
|
+
*
|
5
|
+
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
6
|
+
*/
|
7
|
+
!function(e,t){if("function"==typeof define&&define.amd)define(["exports"],t);else if("object"==typeof exports&&"string"!=typeof exports.nodeName)t(exports);else{var n={};t(n),e.AnsiUp=n.default}}(this,(function(e){"use strict";var t,n=this&&this.__makeTemplateObject||function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e};!function(e){e[e.EOS=0]="EOS",e[e.Text=1]="Text",e[e.Incomplete=2]="Incomplete",e[e.ESC=3]="ESC",e[e.Unknown=4]="Unknown",e[e.SGR=5]="SGR",e[e.OSCURL=6]="OSCURL"}(t||(t={}));var i=function(){function e(){this.VERSION="5.0.0",this.setup_palettes(),this._use_classes=!1,this.bold=!1,this.fg=this.bg=null,this._buffer="",this._url_whitelist={http:1,https:1}}return Object.defineProperty(e.prototype,"use_classes",{get:function(){return this._use_classes},set:function(e){this._use_classes=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"url_whitelist",{get:function(){return this._url_whitelist},set:function(e){this._url_whitelist=e},enumerable:!1,configurable:!0}),e.prototype.setup_palettes=function(){var e=this;this.ansi_colors=[[{rgb:[0,0,0],class_name:"ansi-black"},{rgb:[187,0,0],class_name:"ansi-red"},{rgb:[0,187,0],class_name:"ansi-green"},{rgb:[187,187,0],class_name:"ansi-yellow"},{rgb:[0,0,187],class_name:"ansi-blue"},{rgb:[187,0,187],class_name:"ansi-magenta"},{rgb:[0,187,187],class_name:"ansi-cyan"},{rgb:[255,255,255],class_name:"ansi-white"}],[{rgb:[85,85,85],class_name:"ansi-bright-black"},{rgb:[255,85,85],class_name:"ansi-bright-red"},{rgb:[0,255,0],class_name:"ansi-bright-green"},{rgb:[255,255,85],class_name:"ansi-bright-yellow"},{rgb:[85,85,255],class_name:"ansi-bright-blue"},{rgb:[255,85,255],class_name:"ansi-bright-magenta"},{rgb:[85,255,255],class_name:"ansi-bright-cyan"},{rgb:[255,255,255],class_name:"ansi-bright-white"}]],this.palette_256=[],this.ansi_colors.forEach((function(t){t.forEach((function(t){e.palette_256.push(t)}))}));for(var t=[0,95,135,175,215,255],n=0;n<6;++n)for(var i=0;i<6;++i)for(var s=0;s<6;++s){var r={rgb:[t[n],t[i],t[s]],class_name:"truecolor"};this.palette_256.push(r)}for(var a=8,l=0;l<24;++l,a+=10){var f={rgb:[a,a,a],class_name:"truecolor"};this.palette_256.push(f)}},e.prototype.escape_txt_for_html=function(e){return e.replace(/[&<>"']/gm,(function(e){return"&"===e?"&":"<"===e?"<":">"===e?">":'"'===e?""":"'"===e?"'":void 0}))},e.prototype.append_buffer=function(e){var t=this._buffer+e;this._buffer=t},e.prototype.get_next_packet=function(){var e={kind:t.EOS,text:"",url:""},i=this._buffer.length;if(0==i)return e;var r=this._buffer.indexOf("");if(-1==r)return e.kind=t.Text,e.text=this._buffer,this._buffer="",e;if(r>0)return e.kind=t.Text,e.text=this._buffer.slice(0,r),this._buffer=this._buffer.slice(r),e;if(0==r){if(1==i)return e.kind=t.Incomplete,e;var a=this._buffer.charAt(1);if("["!=a&&"]"!=a)return e.kind=t.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;if("["==a){if(this._csi_regex||(this._csi_regex=s(n(["\n ^ # beginning of line\n #\n # First attempt\n (?: # legal sequence\n [ # CSI\n ([<-?]?) # private-mode char\n ([d;]*) # any digits or semicolons\n ([ -/]? # an intermediate modifier\n [@-~]) # the command\n )\n | # alternate (second attempt)\n (?: # illegal sequence\n [ # CSI\n [ -~]* # anything legal\n ([\0-:]) # anything illegal\n )\n "],["\n ^ # beginning of line\n #\n # First attempt\n (?: # legal sequence\n \\x1b\\[ # CSI\n ([\\x3c-\\x3f]?) # private-mode char\n ([\\d;]*) # any digits or semicolons\n ([\\x20-\\x2f]? # an intermediate modifier\n [\\x40-\\x7e]) # the command\n )\n | # alternate (second attempt)\n (?: # illegal sequence\n \\x1b\\[ # CSI\n [\\x20-\\x7e]* # anything legal\n ([\\x00-\\x1f:]) # anything illegal\n )\n "]))),null===(h=this._buffer.match(this._csi_regex)))return e.kind=t.Incomplete,e;if(h[4])return e.kind=t.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;""!=h[1]||"m"!=h[3]?e.kind=t.Unknown:e.kind=t.SGR,e.text=h[2];var l=h[0].length;return this._buffer=this._buffer.slice(l),e}if("]"==a){if(i<4)return e.kind=t.Incomplete,e;if("8"!=this._buffer.charAt(2)||";"!=this._buffer.charAt(3))return e.kind=t.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;this._osc_st||(this._osc_st=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=e.raw[0],s=/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,r=i.replace(s,"");return new RegExp(r,"g")}(n(["\n (?: # legal sequence\n (\\) # ESC | # alternate\n () # BEL (what xterm did)\n )\n | # alternate (second attempt)\n ( # illegal sequence\n [\0-] # anything illegal\n | # alternate\n [\b-] # anything illegal\n | # alternate\n [-] # anything illegal\n )\n "],["\n (?: # legal sequence\n (\\x1b\\\\) # ESC \\\n | # alternate\n (\\x07) # BEL (what xterm did)\n )\n | # alternate (second attempt)\n ( # illegal sequence\n [\\x00-\\x06] # anything illegal\n | # alternate\n [\\x08-\\x1a] # anything illegal\n | # alternate\n [\\x1c-\\x1f] # anything illegal\n )\n "]))),this._osc_st.lastIndex=0;var f=this._osc_st.exec(this._buffer);if(null===f)return e.kind=t.Incomplete,e;if(f[3])return e.kind=t.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;var h,o=this._osc_st.exec(this._buffer);if(null===o)return e.kind=t.Incomplete,e;if(o[3])return e.kind=t.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;if(this._osc_regex||(this._osc_regex=s(n(["\n ^ # beginning of line\n #\n ]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\\) # ESC | # alternate\n (?:) # BEL (what xterm did)\n )\n ([!-~]+) # TEXT capture\n ]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\) # ESC | # alternate\n (?:) # BEL (what xterm did)\n )\n "],["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x21-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "]))),null===(h=this._buffer.match(this._osc_regex)))return e.kind=t.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;e.kind=t.OSCURL,e.url=h[1],e.text=h[2];l=h[0].length;return this._buffer=this._buffer.slice(l),e}}},e.prototype.ansi_to_html=function(e){this.append_buffer(e);for(var n=[];;){var i=this.get_next_packet();if(i.kind==t.EOS||i.kind==t.Incomplete)break;i.kind!=t.ESC&&i.kind!=t.Unknown&&(i.kind==t.Text?n.push(this.transform_to_html(this.with_state(i))):i.kind==t.SGR?this.process_ansi(i):i.kind==t.OSCURL&&n.push(this.process_hyperlink(i)))}return n.join("")},e.prototype.with_state=function(e){return{bold:this.bold,fg:this.fg,bg:this.bg,text:e.text}},e.prototype.process_ansi=function(e){for(var t=e.text.split(";");t.length>0;){var n=t.shift(),i=parseInt(n,10);if(isNaN(i)||0===i)this.fg=this.bg=null,this.bold=!1;else if(1===i)this.bold=!0;else if(22===i)this.bold=!1;else if(39===i)this.fg=null;else if(49===i)this.bg=null;else if(i>=30&&i<38)this.fg=this.ansi_colors[0][i-30];else if(i>=40&&i<48)this.bg=this.ansi_colors[0][i-40];else if(i>=90&&i<98)this.fg=this.ansi_colors[1][i-90];else if(i>=100&&i<108)this.bg=this.ansi_colors[1][i-100];else if((38===i||48===i)&&t.length>0){var s=38===i,r=t.shift();if("5"===r&&t.length>0){var a=parseInt(t.shift(),10);a>=0&&a<=255&&(s?this.fg=this.palette_256[a]:this.bg=this.palette_256[a])}if("2"===r&&t.length>2){var l=parseInt(t.shift(),10),f=parseInt(t.shift(),10),h=parseInt(t.shift(),10);if(l>=0&&l<=255&&f>=0&&f<=255&&h>=0&&h<=255){var o={rgb:[l,f,h],class_name:"truecolor"};s?this.fg=o:this.bg=o}}}}},e.prototype.transform_to_html=function(e){var t=e.text;if(0===t.length)return t;if(t=this.escape_txt_for_html(t),!e.bold&&null===e.fg&&null===e.bg)return t;var n=[],i=[],s=e.fg,r=e.bg;e.bold&&n.push("font-weight:bold"),this._use_classes?(s&&("truecolor"!==s.class_name?i.push(s.class_name+"-fg"):n.push("color:rgb("+s.rgb.join(",")+")")),r&&("truecolor"!==r.class_name?i.push(r.class_name+"-bg"):n.push("background-color:rgb("+r.rgb.join(",")+")"))):(s&&n.push("color:rgb("+s.rgb.join(",")+")"),r&&n.push("background-color:rgb("+r.rgb+")"));var a="",l="";return i.length&&(a=' class="'+i.join(" ")+'"'),n.length&&(l=' style="'+n.join(";")+'"'),"<span"+l+a+">"+t+"</span>"},e.prototype.process_hyperlink=function(e){var t=e.url.split(":");return t.length<1?"":this._url_whitelist[t[0]]?'<a href="'+this.escape_txt_for_html(e.url)+'">'+this.escape_txt_for_html(e.text)+"</a>":""},e}();function s(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,"");return new RegExp(i)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=i}));
|
@@ -0,0 +1 @@
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FitAddon=t():e.FitAddon=t()}(self,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0,t.FitAddon=class{activate(e){this._terminal=e}dispose(){}fit(){const e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;const t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal)return;if(!this._terminal.element||!this._terminal.element.parentElement)return;const e=this._terminal._core,t=e._renderService.dimensions;if(0===t.css.cell.width||0===t.css.cell.height)return;const r=0===this._terminal.options.scrollback?0:e.viewport.scrollBarWidth,i=window.getComputedStyle(this._terminal.element.parentElement),o=parseInt(i.getPropertyValue("height")),s=Math.max(0,parseInt(i.getPropertyValue("width"))),n=window.getComputedStyle(this._terminal.element),l=o-(parseInt(n.getPropertyValue("padding-top"))+parseInt(n.getPropertyValue("padding-bottom"))),a=s-(parseInt(n.getPropertyValue("padding-right"))+parseInt(n.getPropertyValue("padding-left")))-r;return{cols:Math.max(2,Math.floor(a/t.css.cell.width)),rows:Math.max(1,Math.floor(l/t.css.cell.height))}}}})(),e})()));
|