@xterm/addon-progress 0.1.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 +19 -0
- package/README.md +69 -0
- package/lib/addon-progress.js +2 -0
- package/lib/addon-progress.js.map +1 -0
- package/lib/addon-progress.mjs +18 -0
- package/lib/addon-progress.mjs.map +7 -0
- package/package.json +29 -0
- package/src/ProgressAddon.ts +101 -0
- package/typings/addon-progress.d.ts +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2024, The xterm.js authors (https://github.com/xtermjs/xterm.js)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
## @xterm/addon-progress
|
|
2
|
+
|
|
3
|
+
An xterm.js addon providing an interface for ConEmu's progress sequence.
|
|
4
|
+
See https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC for sequence details.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save @xterm/addon-progress
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Terminal } from '@xterm/xterm';
|
|
18
|
+
import { ProgressAddon, IProgressState } from '@xterm/addon-progress';
|
|
19
|
+
|
|
20
|
+
const terminal = new Terminal();
|
|
21
|
+
const progressAddon = new ProgressAddon();
|
|
22
|
+
terminal.loadAddon(progressAddon);
|
|
23
|
+
progressAddon.onChange({state, value}: IProgressState) => {
|
|
24
|
+
// state: 0-4 integer (see below for meaning)
|
|
25
|
+
// value: 0-100 integer (percent value)
|
|
26
|
+
|
|
27
|
+
// do your visualisation based on state/value here
|
|
28
|
+
...
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
See the full [API](https://github.com/xtermjs/xterm.js/blob/master/addons/addon-progress/typings/addon-progress.d.ts) for more advanced usage.
|
|
33
|
+
|
|
34
|
+
### Sequence
|
|
35
|
+
|
|
36
|
+
The sequence to set progress information has the following format:
|
|
37
|
+
|
|
38
|
+
```plain
|
|
39
|
+
ESC ] 9 ; 4 ; <state> ; <progress value> BEL
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
where state is a decimal number in 0 to 4 and progress value is a decimal number in 0 to 100.
|
|
43
|
+
The states have the following meaning:
|
|
44
|
+
|
|
45
|
+
- 0: Remove any progress indication. Also resets progress value to 0. A given progress value will be ignored.
|
|
46
|
+
- 1: Normal state to set a progress value. The value should be in 0..100, greater values are clamped to 100.
|
|
47
|
+
If the value is omitted, it will be set to 0.
|
|
48
|
+
- 2: Error state with an optional progress value. An omitted value will be set to 0,
|
|
49
|
+
which has a special meaning using the last active value.
|
|
50
|
+
- 3: Actual progress is "indeterminate", any progress value will be ignored. Meant to be used to indicate
|
|
51
|
+
a running task without progress information (e.g. by a spinner). A previously set progress value
|
|
52
|
+
by any other state sequence will be left untouched.
|
|
53
|
+
- 4: Pause or warning state with an optional progress value. An omitted value will be set to 0,
|
|
54
|
+
which has a special meaning using the last active value.
|
|
55
|
+
|
|
56
|
+
The addon resolves most of those semantic nuances and will provide these ready-to-go values:
|
|
57
|
+
- For the remove state (0) any progress value wont be parsed, thus is even allowed to contain garbage.
|
|
58
|
+
It will always emit `{state: 0, value: 0}`.
|
|
59
|
+
- For the set state (1) an omitted value will be set to 0 emitting `{state: 1, value: 0}`.
|
|
60
|
+
If a value was given, it must be decimal digits only, any characters outside will mark the whole sequence
|
|
61
|
+
as faulty (no sloppy integer parsing). The value will be clamped to max 100 giving
|
|
62
|
+
`{state: 1, value: parsedAndClampedValue}`.
|
|
63
|
+
- For the error and pause state (2 & 4) an omitted or zero value will emit `{state: 2|4, value: lastValue}`.
|
|
64
|
+
If a value was given, it must be decimal digits only, any characters outside will mark the whole sequence
|
|
65
|
+
as faulty (no sloppy integer parsing). The value will be clamped to max 100 giving
|
|
66
|
+
`{state: 2|4, value: parsedAndClampedValue}`.
|
|
67
|
+
- For the indeterminate state (3) a value notion will be ignored.
|
|
68
|
+
It still emits the value as `{state: 3, value: lastValue}`. Keep in mind not use that value while
|
|
69
|
+
that state is active, as a task might have entered that state without a proper reset at the beginning.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ProgressAddon=t():e.ProgressAddon=t()}(globalThis,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;function s(e){let t=0;for(let s=0;s<e.length;++s){const r=e.charCodeAt(s);if(r<48||57<r)return-1;t=10*t+r-48}return t}Object.defineProperty(t,"__esModule",{value:!0}),t.ProgressAddon=void 0,t.ProgressAddon=class{constructor(){this._st=0,this._pr=0}dispose(){this._seqHandler?.dispose(),this._onChange?.dispose()}activate(e){this._seqHandler=e.parser.registerOscHandler(9,(e=>{if(!e.startsWith("4;"))return!1;const t=e.split(";");if(t.length>3)return!0;2===t.length&&t.push("");const r=s(t[1]),o=s(t[2]);switch(r){case 0:this.progress={state:r,value:0};break;case 1:if(o<0)return!0;this.progress={state:r,value:o};break;case 2:case 4:if(o<0)return!0;this.progress={state:r,value:o||this._pr};break;case 3:this.progress={state:r,value:this._pr}}return!0})),this._onChange=new e._core._onData.constructor,this.onChange=this._onChange.event}get progress(){return{state:this._st,value:this._pr}}set progress(e){e.state<0||e.state>4?console.warn("progress state out of bounds, not applied"):(this._st=e.state,this._pr=Math.min(Math.max(e.value,0),100),this._onChange?.fire({state:this._st,value:this._pr}))}}})(),e})()));
|
|
2
|
+
//# sourceMappingURL=addon-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addon-progress.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,YAAY,I,gDCaf,SAASC,EAAMC,GACb,IAAIC,EAAI,EACR,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAEG,SAAUD,EAAG,CACjC,MAAME,EAAIJ,EAAEK,WAAWH,GACvB,GAAIE,EAAI,IAAQ,GAAOA,EACrB,OAAQ,EAEVH,EAAQ,GAAJA,EAASG,EAAI,EACnB,CACA,OAAOH,CACT,C,wEAGA,oCAEU,KAAAK,IAAG,EACH,KAAAC,IAAM,CA8DhB,CA1DS,OAAAC,GACLC,KAAKC,aAAaF,UAClBC,KAAKE,WAAWH,SAClB,CAEO,QAAAI,CAASC,GACdJ,KAAKC,YAAcG,EAASC,OAAOC,mBAAmB,GAAGC,IACvD,IAAKA,EAAKC,WAAW,MACnB,OAAO,EAET,MAAMC,EAAQF,EAAKG,MAAM,KAEzB,GAAID,EAAMf,OAAS,EACjB,OAAO,EAEY,IAAjBe,EAAMf,QACRe,EAAME,KAAK,IAEb,MAAMC,EAAKtB,EAAMmB,EAAM,IACjBI,EAAKvB,EAAMmB,EAAM,IAEvB,OAAQG,GACN,KAAK,EACHZ,KAAKc,SAAW,CAAEC,MAAOH,EAAII,MAAO,GACpC,MACF,KAAK,EACH,GAAIH,EAAK,EAAG,OAAO,EACnBb,KAAKc,SAAW,CAAEC,MAAOH,EAAII,MAAOH,GACpC,MACF,KAAK,EACL,KAAK,EACH,GAAIA,EAAK,EAAG,OAAO,EACnBb,KAAKc,SAAW,CAAEC,MAAOH,EAAII,MAAOH,GAAMb,KAAKF,KAC/C,MACF,KAAK,EACHE,KAAKc,SAAW,CAAEC,MAAOH,EAAII,MAAOhB,KAAKF,KAG7C,OAAO,CAAI,IAGbE,KAAKE,UAAY,IAAKE,EAAiBa,MAAMC,QAAQC,YACrDnB,KAAKoB,SAAWpB,KAAKE,UAAWmB,KAClC,CAEA,YAAWP,GACT,MAAO,CAAEC,MAAOf,KAAKH,IAAKmB,MAAOhB,KAAKF,IACxC,CAEA,YAAWgB,CAASA,GACdA,EAASC,MAAQ,GAAKD,EAASC,MAAQ,EACzCO,QAAQC,KAAK,8CAGfvB,KAAKH,IAAMiB,EAASC,MACpBf,KAAKF,IAAM0B,KAAKC,IAAID,KAAKE,IAAIZ,EAASE,MAAO,GAAI,KACjDhB,KAAKE,WAAWyB,KAAK,CAAEZ,MAAOf,KAAKH,IAAKmB,MAAOhB,KAAKF,MACtD,E","sources":["webpack://ProgressAddon/webpack/universalModuleDefinition","webpack://ProgressAddon/./src/ProgressAddon.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ProgressAddon\"] = factory();\n\telse\n\t\troot[\"ProgressAddon\"] = factory();\n})(globalThis, () => {\nreturn ","/**\n * Copyright (c) 2024 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';\nimport type { ProgressAddon as IProgressApi, IProgressState } from '@xterm/addon-progress';\nimport type { Emitter, Event } from 'vs/base/common/event';\n\n\nconst enum ProgressType {\n REMOVE = 0,\n SET = 1,\n ERROR = 2,\n INDETERMINATE = 3,\n PAUSE = 4\n}\n\n\n/**\n * Strict integer parsing, only decimal digits allowed.\n */\nfunction toInt(s: string): number {\n let v = 0;\n for (let i = 0; i < s.length; ++i) {\n const c = s.charCodeAt(i);\n if (c < 0x30 || 0x39 < c) {\n return -1;\n }\n v = v * 10 + c - 48;\n }\n return v;\n}\n\n\nexport class ProgressAddon implements ITerminalAddon, IProgressApi {\n private _seqHandler: IDisposable | undefined;\n private _st: ProgressType = ProgressType.REMOVE;\n private _pr = 0;\n private _onChange: Emitter<IProgressState> | undefined;\n public onChange: Event<IProgressState> | undefined;\n\n public dispose(): void {\n this._seqHandler?.dispose();\n this._onChange?.dispose();\n }\n\n public activate(terminal: Terminal): void {\n this._seqHandler = terminal.parser.registerOscHandler(9, data => {\n if (!data.startsWith('4;')) {\n return false;\n }\n const parts = data.split(';');\n\n if (parts.length > 3) {\n return true; // faulty sequence, just exit\n }\n if (parts.length === 2) {\n parts.push('');\n }\n const st = toInt(parts[1]);\n const pr = toInt(parts[2]);\n\n switch (st) {\n case ProgressType.REMOVE:\n this.progress = { state: st, value: 0 };\n break;\n case ProgressType.SET:\n if (pr < 0) return true; // faulty sequence, just exit\n this.progress = { state: st, value: pr };\n break;\n case ProgressType.ERROR:\n case ProgressType.PAUSE:\n if (pr < 0) return true; // faulty sequence, just exit\n this.progress = { state: st, value: pr || this._pr };\n break;\n case ProgressType.INDETERMINATE:\n this.progress = { state: st, value: this._pr };\n break;\n }\n return true;\n });\n // FIXME: borrow emitter ctor from xterm, to be changed once #5283 is resolved\n this._onChange = new (terminal as any)._core._onData.constructor();\n this.onChange = this._onChange!.event;\n }\n\n public get progress(): IProgressState {\n return { state: this._st, value: this._pr };\n }\n\n public set progress(progress: IProgressState) {\n if (progress.state < 0 || progress.state > 4) {\n console.warn(`progress state out of bounds, not applied`);\n return;\n }\n this._st = progress.state;\n this._pr = Math.min(Math.max(progress.value, 0), 100);\n this._onChange?.fire({ state: this._st, value: this._pr });\n }\n}\n"],"names":["root","factory","exports","module","define","amd","globalThis","toInt","s","v","i","length","c","charCodeAt","_st","_pr","dispose","this","_seqHandler","_onChange","activate","terminal","parser","registerOscHandler","data","startsWith","parts","split","push","st","pr","progress","state","value","_core","_onData","constructor","onChange","event","console","warn","Math","min","max","fire"],"sourceRoot":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
|
6
|
+
* @license MIT
|
|
7
|
+
*
|
|
8
|
+
* Originally forked from (with the author's permission):
|
|
9
|
+
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
10
|
+
* http://bellard.org/jslinux/
|
|
11
|
+
* Copyright (c) 2011 Fabrice Bellard
|
|
12
|
+
*/
|
|
13
|
+
/*---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
15
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
16
|
+
*--------------------------------------------------------------------------------------------*/
|
|
17
|
+
function i(n){let t=0;for(let s=0;s<n.length;++s){let e=n.charCodeAt(s);if(e<48||57<e)return-1;t=t*10+e-48}return t}var o=class{constructor(){this._st=0;this._pr=0}dispose(){this._seqHandler?.dispose(),this._onChange?.dispose()}activate(t){this._seqHandler=t.parser.registerOscHandler(9,s=>{if(!s.startsWith("4;"))return!1;let e=s.split(";");if(e.length>3)return!0;e.length===2&&e.push("");let r=i(e[1]),a=i(e[2]);switch(r){case 0:this.progress={state:r,value:0};break;case 1:if(a<0)return!0;this.progress={state:r,value:a};break;case 2:case 4:if(a<0)return!0;this.progress={state:r,value:a||this._pr};break;case 3:this.progress={state:r,value:this._pr};break}return!0}),this._onChange=new t._core._onData.constructor,this.onChange=this._onChange.event}get progress(){return{state:this._st,value:this._pr}}set progress(t){if(t.state<0||t.state>4){console.warn("progress state out of bounds, not applied");return}this._st=t.state,this._pr=Math.min(Math.max(t.value,0),100),this._onChange?.fire({state:this._st,value:this._pr})}};export{o as ProgressAddon};
|
|
18
|
+
//# sourceMappingURL=addon-progress.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ProgressAddon.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) 2024 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';\nimport type { ProgressAddon as IProgressApi, IProgressState } from '@xterm/addon-progress';\nimport type { Emitter, Event } from 'vs/base/common/event';\n\n\nconst enum ProgressType {\n REMOVE = 0,\n SET = 1,\n ERROR = 2,\n INDETERMINATE = 3,\n PAUSE = 4\n}\n\n\n/**\n * Strict integer parsing, only decimal digits allowed.\n */\nfunction toInt(s: string): number {\n let v = 0;\n for (let i = 0; i < s.length; ++i) {\n const c = s.charCodeAt(i);\n if (c < 0x30 || 0x39 < c) {\n return -1;\n }\n v = v * 10 + c - 48;\n }\n return v;\n}\n\n\nexport class ProgressAddon implements ITerminalAddon, IProgressApi {\n private _seqHandler: IDisposable | undefined;\n private _st: ProgressType = ProgressType.REMOVE;\n private _pr = 0;\n private _onChange: Emitter<IProgressState> | undefined;\n public onChange: Event<IProgressState> | undefined;\n\n public dispose(): void {\n this._seqHandler?.dispose();\n this._onChange?.dispose();\n }\n\n public activate(terminal: Terminal): void {\n this._seqHandler = terminal.parser.registerOscHandler(9, data => {\n if (!data.startsWith('4;')) {\n return false;\n }\n const parts = data.split(';');\n\n if (parts.length > 3) {\n return true; // faulty sequence, just exit\n }\n if (parts.length === 2) {\n parts.push('');\n }\n const st = toInt(parts[1]);\n const pr = toInt(parts[2]);\n\n switch (st) {\n case ProgressType.REMOVE:\n this.progress = { state: st, value: 0 };\n break;\n case ProgressType.SET:\n if (pr < 0) return true; // faulty sequence, just exit\n this.progress = { state: st, value: pr };\n break;\n case ProgressType.ERROR:\n case ProgressType.PAUSE:\n if (pr < 0) return true; // faulty sequence, just exit\n this.progress = { state: st, value: pr || this._pr };\n break;\n case ProgressType.INDETERMINATE:\n this.progress = { state: st, value: this._pr };\n break;\n }\n return true;\n });\n // FIXME: borrow emitter ctor from xterm, to be changed once #5283 is resolved\n this._onChange = new (terminal as any)._core._onData.constructor();\n this.onChange = this._onChange!.event;\n }\n\n public get progress(): IProgressState {\n return { state: this._st, value: this._pr };\n }\n\n public set progress(progress: IProgressState) {\n if (progress.state < 0 || progress.state > 4) {\n console.warn(`progress state out of bounds, not applied`);\n return;\n }\n this._st = progress.state;\n this._pr = Math.min(Math.max(progress.value, 0), 100);\n this._onChange?.fire({ state: this._st, value: this._pr });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAsBA,SAASA,EAAMC,EAAmB,CAChC,IAAIC,EAAI,EACR,QAASC,EAAI,EAAGA,EAAIF,EAAE,OAAQ,EAAEE,EAAG,CACjC,IAAMC,EAAIH,EAAE,WAAWE,CAAC,EACxB,GAAIC,EAAI,IAAQ,GAAOA,EACrB,MAAO,GAETF,EAAIA,EAAI,GAAKE,EAAI,EACnB,CACA,OAAOF,CACT,CAGO,IAAMG,EAAN,KAA4D,CAA5D,cAEL,KAAQ,IAAoB,EAC5B,KAAQ,IAAM,EAIP,SAAgB,CACrB,KAAK,aAAa,QAAQ,EAC1B,KAAK,WAAW,QAAQ,CAC1B,CAEO,SAASC,EAA0B,CACxC,KAAK,YAAcA,EAAS,OAAO,mBAAmB,EAAGC,GAAQ,CAC/D,GAAI,CAACA,EAAK,WAAW,IAAI,EACvB,MAAO,GAET,IAAMC,EAAQD,EAAK,MAAM,GAAG,EAE5B,GAAIC,EAAM,OAAS,EACjB,MAAO,GAELA,EAAM,SAAW,GACnBA,EAAM,KAAK,EAAE,EAEf,IAAMC,EAAKT,EAAMQ,EAAM,CAAC,CAAC,EACnBE,EAAKV,EAAMQ,EAAM,CAAC,CAAC,EAEzB,OAAQC,EAAI,CACV,IAAK,GACH,KAAK,SAAW,CAAE,MAAOA,EAAI,MAAO,CAAE,EACtC,MACF,IAAK,GACH,GAAIC,EAAK,EAAG,MAAO,GACnB,KAAK,SAAW,CAAE,MAAOD,EAAI,MAAOC,CAAG,EACvC,MACF,IAAK,GACL,IAAK,GACH,GAAIA,EAAK,EAAG,MAAO,GACnB,KAAK,SAAW,CAAE,MAAOD,EAAI,MAAOC,GAAM,KAAK,GAAI,EACnD,MACF,IAAK,GACH,KAAK,SAAW,CAAE,MAAOD,EAAI,MAAO,KAAK,GAAI,EAC7C,KACJ,CACA,MAAO,EACT,CAAC,EAED,KAAK,UAAY,IAAKH,EAAiB,MAAM,QAAQ,YACrD,KAAK,SAAW,KAAK,UAAW,KAClC,CAEA,IAAW,UAA2B,CACpC,MAAO,CAAE,MAAO,KAAK,IAAK,MAAO,KAAK,GAAI,CAC5C,CAEA,IAAW,SAASK,EAA0B,CAC5C,GAAIA,EAAS,MAAQ,GAAKA,EAAS,MAAQ,EAAG,CAC5C,QAAQ,KAAK,2CAA2C,EACxD,MACF,CACA,KAAK,IAAMA,EAAS,MACpB,KAAK,IAAM,KAAK,IAAI,KAAK,IAAIA,EAAS,MAAO,CAAC,EAAG,GAAG,EACpD,KAAK,WAAW,KAAK,CAAE,MAAO,KAAK,IAAK,MAAO,KAAK,GAAI,CAAC,CAC3D,CACF",
|
|
6
|
+
"names": ["toInt", "s", "v", "i", "c", "ProgressAddon", "terminal", "data", "parts", "st", "pr", "progress"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xterm/addon-progress",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "The xterm.js authors",
|
|
6
|
+
"url": "https://xtermjs.org/"
|
|
7
|
+
},
|
|
8
|
+
"main": "lib/addon-progress.js",
|
|
9
|
+
"module": "lib/addon-progress.mjs",
|
|
10
|
+
"types": "typings/addon-progress.d.ts",
|
|
11
|
+
"repository": "https://github.com/xtermjs/xterm.js/tree/master/addons/addon-progress",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"terminal",
|
|
15
|
+
"xterm",
|
|
16
|
+
"xterm.js"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "../../node_modules/.bin/tsc -p .",
|
|
20
|
+
"prepackage": "npm run build",
|
|
21
|
+
"package": "../../node_modules/.bin/webpack",
|
|
22
|
+
"prepublishOnly": "npm run package",
|
|
23
|
+
"start": "node ../../demo/start"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@xterm/xterm": "^5.6.0-beta.94"
|
|
27
|
+
},
|
|
28
|
+
"commit": "330e91ef080ae27ae92ced116fc0cc1346a1f16a"
|
|
29
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
|
|
7
|
+
import type { ProgressAddon as IProgressApi, IProgressState } from '@xterm/addon-progress';
|
|
8
|
+
import type { Emitter, Event } from 'vs/base/common/event';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const enum ProgressType {
|
|
12
|
+
REMOVE = 0,
|
|
13
|
+
SET = 1,
|
|
14
|
+
ERROR = 2,
|
|
15
|
+
INDETERMINATE = 3,
|
|
16
|
+
PAUSE = 4
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Strict integer parsing, only decimal digits allowed.
|
|
22
|
+
*/
|
|
23
|
+
function toInt(s: string): number {
|
|
24
|
+
let v = 0;
|
|
25
|
+
for (let i = 0; i < s.length; ++i) {
|
|
26
|
+
const c = s.charCodeAt(i);
|
|
27
|
+
if (c < 0x30 || 0x39 < c) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
v = v * 10 + c - 48;
|
|
31
|
+
}
|
|
32
|
+
return v;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export class ProgressAddon implements ITerminalAddon, IProgressApi {
|
|
37
|
+
private _seqHandler: IDisposable | undefined;
|
|
38
|
+
private _st: ProgressType = ProgressType.REMOVE;
|
|
39
|
+
private _pr = 0;
|
|
40
|
+
private _onChange: Emitter<IProgressState> | undefined;
|
|
41
|
+
public onChange: Event<IProgressState> | undefined;
|
|
42
|
+
|
|
43
|
+
public dispose(): void {
|
|
44
|
+
this._seqHandler?.dispose();
|
|
45
|
+
this._onChange?.dispose();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public activate(terminal: Terminal): void {
|
|
49
|
+
this._seqHandler = terminal.parser.registerOscHandler(9, data => {
|
|
50
|
+
if (!data.startsWith('4;')) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const parts = data.split(';');
|
|
54
|
+
|
|
55
|
+
if (parts.length > 3) {
|
|
56
|
+
return true; // faulty sequence, just exit
|
|
57
|
+
}
|
|
58
|
+
if (parts.length === 2) {
|
|
59
|
+
parts.push('');
|
|
60
|
+
}
|
|
61
|
+
const st = toInt(parts[1]);
|
|
62
|
+
const pr = toInt(parts[2]);
|
|
63
|
+
|
|
64
|
+
switch (st) {
|
|
65
|
+
case ProgressType.REMOVE:
|
|
66
|
+
this.progress = { state: st, value: 0 };
|
|
67
|
+
break;
|
|
68
|
+
case ProgressType.SET:
|
|
69
|
+
if (pr < 0) return true; // faulty sequence, just exit
|
|
70
|
+
this.progress = { state: st, value: pr };
|
|
71
|
+
break;
|
|
72
|
+
case ProgressType.ERROR:
|
|
73
|
+
case ProgressType.PAUSE:
|
|
74
|
+
if (pr < 0) return true; // faulty sequence, just exit
|
|
75
|
+
this.progress = { state: st, value: pr || this._pr };
|
|
76
|
+
break;
|
|
77
|
+
case ProgressType.INDETERMINATE:
|
|
78
|
+
this.progress = { state: st, value: this._pr };
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
// FIXME: borrow emitter ctor from xterm, to be changed once #5283 is resolved
|
|
84
|
+
this._onChange = new (terminal as any)._core._onData.constructor();
|
|
85
|
+
this.onChange = this._onChange!.event;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public get progress(): IProgressState {
|
|
89
|
+
return { state: this._st, value: this._pr };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public set progress(progress: IProgressState) {
|
|
93
|
+
if (progress.state < 0 || progress.state > 4) {
|
|
94
|
+
console.warn(`progress state out of bounds, not applied`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this._st = progress.state;
|
|
98
|
+
this._pr = Math.min(Math.max(progress.value, 0), 100);
|
|
99
|
+
this._onChange?.fire({ state: this._st, value: this._pr });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
|
|
7
|
+
import type { Event } from 'vs/base/common/event';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
declare module '@xterm/addon-progress' {
|
|
11
|
+
/**
|
|
12
|
+
* An xterm.js addon that provides an interface for ConEmu's progress
|
|
13
|
+
* sequence.
|
|
14
|
+
*/
|
|
15
|
+
export class ProgressAddon implements ITerminalAddon, IDisposable {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new progress addon
|
|
19
|
+
*/
|
|
20
|
+
constructor();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Activates the addon
|
|
24
|
+
* @param terminal The terminal the addon is being loaded in.
|
|
25
|
+
*/
|
|
26
|
+
public activate(terminal: Terminal): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Disposes the addon.
|
|
30
|
+
*/
|
|
31
|
+
public dispose(): void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An event that fires when the tracked progress changes.
|
|
35
|
+
*/
|
|
36
|
+
public readonly onChange: Event<IProgressState> | undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Gets or sets the current progress tracked by the addon.
|
|
40
|
+
* This can also be used to reset a stuck progress indicator
|
|
41
|
+
* back to initial with `{state: 0, value: 0}`
|
|
42
|
+
* or to restore an indicator.
|
|
43
|
+
*/
|
|
44
|
+
public progress: IProgressState;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Progress state tracked by the addon.
|
|
49
|
+
*/
|
|
50
|
+
export interface IProgressState {
|
|
51
|
+
state: 0 | 1 | 2 | 3 | 4;
|
|
52
|
+
value: number;
|
|
53
|
+
}
|
|
54
|
+
}
|