Skip to content

Commit

Permalink
Merge pull request #5290 from Tyriar/progress_polish
Browse files Browse the repository at this point in the history
Progress polish
  • Loading branch information
Tyriar authored Jan 9, 2025
2 parents 330e91e + dc9084b commit 6188f76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
5 changes: 3 additions & 2 deletions addons/addon-progress/src/ProgressAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export class ProgressAddon implements ITerminalAddon, IProgressApi {
private _seqHandler: IDisposable | undefined;
private _st: ProgressType = ProgressType.REMOVE;
private _pr = 0;
private _onChange: Emitter<IProgressState> | undefined;
public onChange: Event<IProgressState> | undefined;
// HACK: This uses ! to align with the API, this should be fixed when 5283 is resolved
private _onChange!: Emitter<IProgressState>;
public onChange!: Event<IProgressState>;

public dispose(): void {
this._seqHandler?.dispose();
Expand Down
36 changes: 25 additions & 11 deletions addons/addon-progress/typings/addon-progress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
* @license MIT
*/

import { Terminal, ITerminalAddon, IDisposable } from '@xterm/xterm';
import type { Event } from 'vs/base/common/event';

import { Terminal, ITerminalAddon, IDisposable, IEvent } from '@xterm/xterm';

declare module '@xterm/addon-progress' {
/**
* An xterm.js addon that provides an interface for ConEmu's progress
* sequence.
*/
export class ProgressAddon implements ITerminalAddon, IDisposable {

/**
* Creates a new progress addon
*/
Expand All @@ -24,7 +22,7 @@ declare module '@xterm/addon-progress' {
* @param terminal The terminal the addon is being loaded in.
*/
public activate(terminal: Terminal): void;

/**
* Disposes the addon.
*/
Expand All @@ -33,22 +31,38 @@ declare module '@xterm/addon-progress' {
/**
* An event that fires when the tracked progress changes.
*/
public readonly onChange: Event<IProgressState> | undefined;
public readonly onChange: IEvent<IProgressState> | undefined;

/**
* Gets or sets the current progress tracked by the addon.
* This can also be used to reset a stuck progress indicator
* back to initial with `{state: 0, value: 0}`
* or to restore an indicator.
* Gets or sets the current progress tracked by the addon. This can be used
* to reset a stuck progress indicator back to initial with
* `{ state: 0, value: 0 }` or to restore an indicator.
*/
public progress: IProgressState;
}

/**
* Progress state tracked by the addon.
*/
export interface IProgressState {
/**
* The progress state.
*
* - `0`: No progress. Setting this will resets progress value to 0
* regardless of the {@link value} used.
* - `1`: Normal percentage-based from 0 to 100.
* - `2`: Error with an optional progress value from 0 to 100.
* - `3`: Indeterminate progress, any progress value will be ignored. This
* is used to indicate work is happening but a percentage value cannot be
* determined.
* - `4`: Pause or warning state with an optional progress value.
*/
state: 0 | 1 | 2 | 3 | 4;

/**
* The percentage value of progress from 0 to 100. See {@link state} for
* whether this is relevant.
*/
value: number;
}
}

0 comments on commit 6188f76

Please sign in to comment.