rename types, remove rc import in d.ts

This commit is contained in:
Jörg Breitbart
2025-01-09 02:05:36 +01:00
parent 96a3be3ca8
commit 8101132352
4 changed files with 22 additions and 22 deletions
+2 -2
View File
@@ -15,12 +15,12 @@ npm install --save @xterm/addon-progress
```ts
import { Terminal } from '@xterm/xterm';
import { ProgressAddon } from '@xterm/addon-progress';
import { ProgressAddon, IProgressState } from '@xterm/addon-progress';
const terminal = new Terminal();
const progressAddon = new ProgressAddon();
terminal.loadAddon(progressAddon);
progressAddon.onChange({state, value}: IProgress) => {
progressAddon.onChange({state, value}: IProgressState) => {
// state: 0-4 integer (see below for meaning)
// value: 0-100 integer (percent value)
+12 -12
View File
@@ -4,11 +4,11 @@
*/
import type { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
import type { ProgressAddon as IProgressApi, IProgress } from '@xterm/addon-progress';
import type { ProgressAddon as IProgressApi, IProgressState } from '@xterm/addon-progress';
import type { Emitter, Event } from 'vs/base/common/event';
export const enum ProgressState {
const enum ProgressType {
REMOVE = 0,
SET = 1,
ERROR = 2,
@@ -35,10 +35,10 @@ function toInt(s: string): number {
export class ProgressAddon implements ITerminalAddon, IProgressApi {
private _seqHandler: IDisposable | undefined;
private _st: ProgressState = ProgressState.REMOVE;
private _st: ProgressType = ProgressType.REMOVE;
private _pr = 0;
private _onChange: Emitter<IProgress> | undefined;
public onChange: Event<IProgress> | undefined;
private _onChange: Emitter<IProgressState> | undefined;
public onChange: Event<IProgressState> | undefined;
public dispose(): void {
this._seqHandler?.dispose();
@@ -62,19 +62,19 @@ export class ProgressAddon implements ITerminalAddon, IProgressApi {
const pr = toInt(parts[2]);
switch (st) {
case ProgressState.REMOVE:
case ProgressType.REMOVE:
this.progress = { state: st, value: 0 };
break;
case ProgressState.SET:
case ProgressType.SET:
if (pr < 0) return true; // faulty sequence, just exit
this.progress = { state: st, value: pr };
break;
case ProgressState.ERROR:
case ProgressState.PAUSE:
case ProgressType.ERROR:
case ProgressType.PAUSE:
if (pr < 0) return true; // faulty sequence, just exit
this.progress = { state: st, value: pr || this._pr };
break;
case ProgressState.INDETERMINATE:
case ProgressType.INDETERMINATE:
this.progress = { state: st, value: this._pr };
break;
}
@@ -85,11 +85,11 @@ export class ProgressAddon implements ITerminalAddon, IProgressApi {
this.onChange = this._onChange!.event;
}
public get progress(): IProgress {
public get progress(): IProgressState {
return { state: this._st, value: this._pr };
}
public set progress(progress: IProgress) {
public set progress(progress: IProgressState) {
if (progress.state < 0 || progress.state > 4) {
console.warn(`progress state out of bounds, not applied`);
return;
+6 -6
View File
@@ -5,7 +5,7 @@
import { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
import type { Event } from 'vs/base/common/event';
import type { ProgressState } from '../src/ProgressAddon';
declare module '@xterm/addon-progress' {
/**
@@ -33,7 +33,7 @@ declare module '@xterm/addon-progress' {
/**
* An event that fires when the tracked progress changes.
*/
public readonly onChange: Event<IProgress> | undefined;
public readonly onChange: Event<IProgressState> | undefined;
/**
* Gets or sets the current progress tracked by the addon.
@@ -41,14 +41,14 @@ declare module '@xterm/addon-progress' {
* back to initial with `{state: 0, value: 0}`
* or to restore an indicator.
*/
public progress: IProgress;
public progress: IProgressState;
}
/**
* Progress tracked by the addon.
* Progress state tracked by the addon.
*/
export interface IProgress {
state: ProgressState;
export interface IProgressState {
state: 0 | 1 | 2 | 3 | 4;
value: number;
}
}
+2 -2
View File
@@ -21,7 +21,7 @@ import { AttachAddon } from '@xterm/addon-attach';
import { ClipboardAddon } from '@xterm/addon-clipboard';
import { FitAddon } from '@xterm/addon-fit';
import { LigaturesAddon } from '@xterm/addon-ligatures';
import { ProgressAddon, IProgress } from '@xterm/addon-progress';
import { ProgressAddon, IProgressState } from '@xterm/addon-progress';
import { SearchAddon, ISearchOptions } from '@xterm/addon-search';
import { SerializeAddon } from '@xterm/addon-serialize';
import { WebLinksAddon } from '@xterm/addon-web-links';
@@ -1454,7 +1454,7 @@ function progressButtons(): void {
const STATES = { 0: 'remove', 1: 'set', 2: 'error', 3: 'indeterminate', 4: 'pause' };
const COLORS = { 0: '', 1: 'green', 2: 'red', 3: '', 4: 'yellow' };
function progressHandler({state, value}: IProgress) {
function progressHandler({state, value}: IProgressState) {
// Simulate windows taskbar hack by windows terminal:
// Since the taskbar has no means to indicate error/pause state other than by coloring
// the current progress, we move 0 to 10% and distribute higher values in the remaining 90 %