pywebexec 1.1.18__py3-none-any.whl → 1.2.1__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 CHANGED
@@ -15,6 +15,7 @@ from gunicorn.app.base import Application
15
15
  import ipaddress
16
16
  from socket import gethostname, gethostbyname_ex
17
17
  import ssl
18
+ import re
18
19
  if os.environ.get('PYWEBEXEC_LDAP_SERVER'):
19
20
  from ldap3 import Server, Connection, ALL, SIMPLE, SUBTREE, Tls
20
21
 
@@ -136,10 +137,38 @@ class StandaloneApplication(Application):
136
137
  return self.application
137
138
 
138
139
 
140
+ ANSI_ESCAPE = re.compile(br'(?:\x1B[@-Z\\-_]|\x1B([(]B|>)|(?:\x1B\[|\x9B)[0-?]*[ -/]*[@-~]|\x1B\[[0-9]{1,2};[0-9]{1,2}[m|K]|\x1B\[[0-9;]*[mGKHF]|[\x00-\x1F\x7F])')
141
+
142
+ def strip_ansi_control_chars(text):
143
+ """Remove ANSI and control characters from the text."""
144
+ # To clean
145
+ # ansi_escape = re.compile(br'''
146
+ # (
147
+ # \x1B[@-_]| # ANSI ESCape sequences
148
+ # \x1B\[[0-9]{1,2};[0-9]{1,2}[m|K]| # ANSI color sequences
149
+ # \x1B\[[0-9;]*[mGKHF]| # ANSI color sequences
150
+ # \x1B\[.*?[ -/]*[@-~]| # ANSI CSI sequences
151
+ # \x1B\].*?\x07| # ANSI OSC sequences
152
+ # \x1B=P| # ANSI DCS sequences
153
+ # \x1B\\| # ANSI ST sequences
154
+ # \x1B\^| # ANSI PM sequences
155
+ # \x1B_.*?\x1B\\| # ANSI APC sequences
156
+ # [\x00-\x1F\x7F]| # Control characters
157
+ # \x1B([(]B|>)
158
+ # )
159
+ # ''', re.VERBOSE)
160
+
161
+ # ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|[(]B)|>')
162
+ # ansi_escape = re.compile(br'(?:\x1B\[[0-9]{1,2};[0-9]{1,2}[m|K]|\x1B[@-Z\\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x1B\[|\x9B)[0-?]*[ -/]*[@-~]|\x1B([(]B|>))')
163
+ return ANSI_ESCAPE.sub(b'', text)
164
+
165
+
139
166
  def decode_line(line: bytes) -> str:
140
167
  """try decode line exception on binary"""
141
168
  try:
142
- return line.decode()
169
+ print(line.decode())
170
+ print("=>", strip_ansi_control_chars(line).decode())
171
+ return strip_ansi_control_chars(line).decode().strip(" ")
143
172
  except UnicodeDecodeError:
144
173
  return ""
145
174
 
@@ -149,8 +178,11 @@ def last_line(fd, maxline=1000):
149
178
  line = "\n"
150
179
  fd.seek(0, os.SEEK_END)
151
180
  size = 0
152
- while line in ["\n", "\r"] and size < maxline:
181
+ last_pos = 0
182
+ while line in ["", "\n", "\r"] and size < maxline:
153
183
  try: # catch if file empty / only empty lines
184
+ if last_pos:
185
+ fd.seek(last_pos-2, os.SEEK_SET)
154
186
  while fd.read(1) not in [b"\n", b"\r"]:
155
187
  fd.seek(-2, os.SEEK_CUR)
156
188
  size += 1
@@ -158,8 +190,8 @@ def last_line(fd, maxline=1000):
158
190
  fd.seek(0)
159
191
  line = decode_line(fd.readline())
160
192
  break
193
+ last_pos = fd.tell()
161
194
  line = decode_line(fd.readline())
162
- fd.seek(-4, os.SEEK_CUR)
163
195
  return line.strip()
164
196
 
165
197
 
@@ -246,7 +278,7 @@ def parseargs():
246
278
  "-t",
247
279
  "--title",
248
280
  type=str,
249
- default="pywebexec",
281
+ default="PyWebExec",
250
282
  help="Web html title",
251
283
  )
252
284
  parser.add_argument("-c", "--cert", type=str, help="Path to https certificate")
@@ -317,6 +349,7 @@ def update_command_status(command_id, status, command=None, params=None, start_t
317
349
  if status != 'running':
318
350
  output_file_path = get_output_file_path(command_id)
319
351
  if os.path.exists(output_file_path):
352
+ print(output_file_path)
320
353
  status_data['last_output_line'] = get_last_non_empty_line_of_file(output_file_path)
321
354
  with open(status_file_path, 'w') as f:
322
355
  json.dump(status_data, f)
@@ -474,7 +507,7 @@ def stop_command(command_id):
474
507
  end_time = datetime.now().isoformat()
475
508
  try:
476
509
  os.kill(pid, 15) # Send SIGTERM
477
- update_command_status(command_id, 'aborted', end_time=end_time, exit_code=-15)
510
+ #update_command_status(command_id, 'aborted', end_time=end_time, exit_code=-15)
478
511
  return jsonify({'message': 'Command aborted'})
479
512
  except Exception as e:
480
513
  status_data = read_command_status(command_id) or {}
@@ -518,6 +551,11 @@ def list_commands():
518
551
  except AttributeError:
519
552
  params = " ".join([shlex.quote(p) if " " in p else p for p in status['params']])
520
553
  command = status.get('command', '-') + ' ' + params
554
+ last_line = status.get('last_output_line')
555
+ if last_line is None:
556
+ output_file_path = get_output_file_path(command_id)
557
+ if os.path.exists(output_file_path):
558
+ last_line = get_last_non_empty_line_of_file(output_file_path)
521
559
  commands.append({
522
560
  'command_id': command_id,
523
561
  'status': status['status'],
@@ -525,7 +563,7 @@ def list_commands():
525
563
  'end_time': status.get('end_time', 'N/A'),
526
564
  'command': command,
527
565
  'exit_code': status.get('exit_code', 'N/A'),
528
- 'last_output_line': status.get('last_output_line', get_last_non_empty_line_of_file(get_output_file_path(command_id))),
566
+ 'last_output_line': last_line,
529
567
  })
530
568
  # Sort commands by start_time in descending order
531
569
  commands.sort(key=lambda x: x['start_time'], reverse=True)
@@ -1,5 +1,6 @@
1
1
  body {
2
- font-family: Arial, sans-serif;
2
+ font-family: Arial, sans-serif;
3
+ overflow: hidden;
3
4
  }
4
5
  .table-container {
5
6
  height: 270px;
@@ -36,12 +37,12 @@ select { /* Safari bug */
36
37
  }
37
38
  .output {
38
39
  white-space: pre-wrap;
39
- background: #f0f0f0;
40
+ background: #111;
40
41
  padding: 10px;
41
42
  border: 1px solid #ccc;
42
43
  font-family: monospace;
43
44
  border-radius: 10px;
44
- overflow-y: auto;
45
+ overflow-y: hidden;
45
46
  }
46
47
  .copy-icon { cursor: pointer; }
47
48
  .monospace { font-family: monospace; }
@@ -156,6 +157,7 @@ body.dimmed * {
156
157
  height: 100%;
157
158
  background-color: rgba(0, 0, 0, 0.5);
158
159
  z-index: 1000;
160
+ overflow-y: hidden;
159
161
  }
160
162
  .dimmer-text {
161
163
  color: white;
@@ -166,3 +168,8 @@ body.dimmed * {
166
168
  left: 50%;
167
169
  transform: translate(-50%, -50%);
168
170
  }
171
+ .xterm-cursor {
172
+ display: none;
173
+ visibility: hidden;
174
+ height: 0px;
175
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * https://github.com/chjj/term.js
5
+ * @license MIT
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ * Originally forked from (with the author's permission):
26
+ * Fabrice Bellard's javascript vt100 for jslinux:
27
+ * http://bellard.org/jslinux/
28
+ * Copyright (c) 2011 Fabrice Bellard
29
+ * The original design remains. The terminal itself
30
+ * has been extended to include xterm CSI codes, among
31
+ * other features.
32
+ */
33
+
34
+ /**
35
+ * Default styles for xterm.js
36
+ */
37
+
38
+ .xterm {
39
+ cursor: text;
40
+ position: relative;
41
+ user-select: none;
42
+ -ms-user-select: none;
43
+ -webkit-user-select: none;
44
+ }
45
+
46
+ .xterm.focus,
47
+ .xterm:focus {
48
+ outline: none;
49
+ }
50
+
51
+ .xterm .xterm-helpers {
52
+ position: absolute;
53
+ top: 0;
54
+ /**
55
+ * The z-index of the helpers must be higher than the canvases in order for
56
+ * IMEs to appear on top.
57
+ */
58
+ z-index: 5;
59
+ }
60
+
61
+ .xterm .xterm-helper-textarea {
62
+ padding: 0;
63
+ border: 0;
64
+ margin: 0;
65
+ /* Move textarea out of the screen to the far left, so that the cursor is not visible */
66
+ position: absolute;
67
+ opacity: 0;
68
+ left: -9999em;
69
+ top: 0;
70
+ width: 0;
71
+ height: 0;
72
+ z-index: -5;
73
+ /** Prevent wrapping so the IME appears against the textarea at the correct position */
74
+ white-space: nowrap;
75
+ overflow: hidden;
76
+ resize: none;
77
+ }
78
+
79
+ .xterm .composition-view {
80
+ /* TODO: Composition position got messed up somewhere */
81
+ background: #000;
82
+ color: #FFF;
83
+ display: none;
84
+ position: absolute;
85
+ white-space: nowrap;
86
+ z-index: 1;
87
+ }
88
+
89
+ .xterm .composition-view.active {
90
+ display: block;
91
+ }
92
+
93
+ .xterm .xterm-viewport {
94
+ /* On OS X this is required in order for the scroll bar to appear fully opaque */
95
+ background-color: #000;
96
+ overflow-y: scroll;
97
+ cursor: default;
98
+ position: absolute;
99
+ right: 0;
100
+ left: 0;
101
+ top: 0;
102
+ bottom: 0;
103
+ }
104
+
105
+ .xterm .xterm-screen {
106
+ position: relative;
107
+ }
108
+
109
+ .xterm .xterm-screen canvas {
110
+ position: absolute;
111
+ left: 0;
112
+ top: 0;
113
+ }
114
+
115
+ .xterm .xterm-scroll-area {
116
+ visibility: hidden;
117
+ }
118
+
119
+ .xterm-char-measure-element {
120
+ display: inline-block;
121
+ visibility: hidden;
122
+ position: absolute;
123
+ top: 0;
124
+ left: -9999em;
125
+ line-height: normal;
126
+ }
127
+
128
+ .xterm.enable-mouse-events {
129
+ /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
130
+ cursor: default;
131
+ }
132
+
133
+ .xterm.xterm-cursor-pointer,
134
+ .xterm .xterm-cursor-pointer {
135
+ cursor: pointer;
136
+ }
137
+
138
+ .xterm.column-select.focus {
139
+ /* Column selection mode */
140
+ cursor: crosshair;
141
+ }
142
+
143
+ .xterm .xterm-accessibility,
144
+ .xterm .xterm-message {
145
+ position: absolute;
146
+ left: 0;
147
+ top: 0;
148
+ bottom: 0;
149
+ right: 0;
150
+ z-index: 10;
151
+ color: transparent;
152
+ pointer-events: none;
153
+ }
154
+
155
+ .xterm .live-region {
156
+ position: absolute;
157
+ left: -9999px;
158
+ width: 1px;
159
+ height: 1px;
160
+ overflow: hidden;
161
+ }
162
+
163
+ .xterm-dim {
164
+ /* Dim should not apply to background, so the opacity of the foreground color is applied
165
+ * explicitly in the generated class and reset to 1 here */
166
+ opacity: 1 !important;
167
+ }
168
+
169
+ .xterm-underline-1 { text-decoration: underline; }
170
+ .xterm-underline-2 { text-decoration: double underline; }
171
+ .xterm-underline-3 { text-decoration: wavy underline; }
172
+ .xterm-underline-4 { text-decoration: dotted underline; }
173
+ .xterm-underline-5 { text-decoration: dashed underline; }
174
+
175
+ .xterm-overline {
176
+ text-decoration: overline;
177
+ }
178
+
179
+ .xterm-overline.xterm-underline-1 { text-decoration: overline underline; }
180
+ .xterm-overline.xterm-underline-2 { text-decoration: overline double underline; }
181
+ .xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; }
182
+ .xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; }
183
+ .xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; }
184
+
185
+ .xterm-strikethrough {
186
+ text-decoration: line-through;
187
+ }
188
+
189
+ .xterm-screen .xterm-decoration-container .xterm-decoration {
190
+ z-index: 6;
191
+ position: absolute;
192
+ }
193
+
194
+ .xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer {
195
+ z-index: 7;
196
+ }
197
+
198
+ .xterm-decoration-overview-ruler {
199
+ z-index: 8;
200
+ position: absolute;
201
+ top: 0;
202
+ right: 0;
203
+ pointer-events: none;
204
+ }
205
+
206
+ .xterm-decoration-top {
207
+ z-index: 2;
208
+ position: relative;
209
+ }
@@ -1,5 +1,14 @@
1
1
  let currentCommandId = null;
2
2
  let outputInterval = null;
3
+ const terminal = new Terminal({
4
+ cursorBlink: false,
5
+ cursorHidden: true,
6
+ disableStdin: true
7
+ });
8
+ const fitAddon = new FitAddon.FitAddon();
9
+ terminal.loadAddon(fitAddon);
10
+ terminal.open(document.getElementById('output'));
11
+ fitAddon.fit();
3
12
 
4
13
  document.getElementById('launchForm').addEventListener('submit', async (event) => {
5
14
  event.preventDefault();
@@ -90,18 +99,17 @@ async function fetchExecutables() {
90
99
 
91
100
  async function fetchOutput(command_id) {
92
101
  try {
93
- const outputDiv = document.getElementById('output');
94
102
  const response = await fetch(`/command_output/${command_id}`);
95
103
  if (!response.ok) {
96
104
  return;
97
105
  }
98
106
  const data = await response.json();
99
107
  if (data.error) {
100
- outputDiv.innerHTML = data.error;
108
+ terminal.write(data.error);
101
109
  clearInterval(outputInterval);
102
110
  } else {
103
- outputDiv.innerHTML = data.output;
104
- outputDiv.scrollTop = outputDiv.scrollHeight;
111
+ terminal.clear();
112
+ terminal.write(data.output.replace(/\n/g, '\n\r'));
105
113
  if (data.status != 'running') {
106
114
  clearInterval(outputInterval);
107
115
  }
@@ -178,7 +186,6 @@ async function stopCommand(command_id) {
178
186
  if (data.error) {
179
187
  alert(data.error);
180
188
  } else {
181
- alert(data.message);
182
189
  fetchCommands();
183
190
  }
184
191
  } catch (error) {
@@ -220,7 +227,8 @@ function adjustOutputHeight() {
220
227
  const windowHeight = window.innerHeight;
221
228
  const outputTop = outputDiv.getBoundingClientRect().top;
222
229
  const maxHeight = windowHeight - outputTop - 30; // 20px for padding/margin
223
- outputDiv.style.maxHeight = `${maxHeight}px`;
230
+ outputDiv.style.height = `${maxHeight}px`;
231
+ fitAddon.fit();
224
232
  }
225
233
 
226
234
  function initResizer() {
@@ -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?"&amp;":"<"===e?"&lt;":">"===e?"&gt;":'"'===e?"&quot;":"'"===e?"&#x27;":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})()));