| 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 | // HACK: This uses ! to align with the API, this should be fixed when 5283 is resolved |
| 41 | private _onChange!: Emitter<IProgressState>; |
| 42 | public onChange!: Event<IProgressState>; |
| 43 | |
| 44 | public dispose(): void { |
| 45 | this._seqHandler?.dispose(); |
| 46 | this._onChange?.dispose(); |
| 47 | } |
| 48 | |
| 49 | public activate(terminal: Terminal): void { |
| 50 | this._seqHandler = terminal.parser.registerOscHandler(9, data => { |
| 51 | if (!data.startsWith('4;')) { |
| 52 | return false; |
| 53 | } |
| 54 | const parts = data.split(';'); |
| 55 | |
| 56 | if (parts.length > 3) { |
| 57 | return true; // faulty sequence, just exit |
| 58 | } |
| 59 | if (parts.length === 2) { |
| 60 | parts.push(''); |
| 61 | } |
| 62 | const st = toInt(parts[1]); |
| 63 | const pr = toInt(parts[2]); |
| 64 | |
| 65 | switch (st) { |
| 66 | case ProgressType.REMOVE: |
| 67 | this.progress = { state: st, value: 0 }; |
| 68 | break; |
| 69 | case ProgressType.SET: |
| 70 | if (pr < 0) return true; // faulty sequence, just exit |
| 71 | this.progress = { state: st, value: pr }; |
| 72 | break; |
| 73 | case ProgressType.ERROR: |
| 74 | case ProgressType.PAUSE: |
| 75 | if (pr < 0) return true; // faulty sequence, just exit |
| 76 | this.progress = { state: st, value: pr || this._pr }; |
| 77 | break; |
| 78 | case ProgressType.INDETERMINATE: |
| 79 | this.progress = { state: st, value: this._pr }; |
| 80 | break; |
| 81 | } |
| 82 | return true; |
| 83 | }); |
| 84 | // FIXME: borrow emitter ctor from xterm, to be changed once #5283 is resolved |
| 85 | this._onChange = new (terminal as any)._core._onData.constructor(); |
| 86 | this.onChange = this._onChange!.event; |
| 87 | } |
| 88 | |
| 89 | public get progress(): IProgressState { |
| 90 | return { state: this._st, value: this._pr }; |
| 91 | } |
| 92 | |
| 93 | public set progress(progress: IProgressState) { |
nothing calls this directly
no outgoing calls
no test coverage detected