Skip to content

progress-addon#5251

Merged
Tyriar merged 17 commits into
xtermjs:masterfrom
jerch:progress-addon
Jan 9, 2025
Merged

progress-addon#5251
Tyriar merged 17 commits into
xtermjs:masterfrom
jerch:progress-addon

Conversation

@jerch

@jerch jerch commented Dec 15, 2024

Copy link
Copy Markdown
Member

This addon implements ConEmu's progress sequence, for more context see #5250.

The addon tries to hide most of the sequence's shenanigans behind a convenient API:

const progressAddon = new ProgressAddon();
terminal.loadAddon(progressAddon);
progressAddon.register((state, value) => {
  // state: 0-4 integer
  // value: 0-100 integer
  
  // do your visualisation based on state/progress here
  ...
});

Fixes #5250.

@Tyriar Tyriar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really solid 👏

Depending on app support, this could be really nice to integrate with the VS Code tab progress:

image


/** progress object interface */
export interface IProgress {
state: 0 | 1 | 2 | 3 | 4;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could pull this into type ProgressState?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved this by adding:

import type { ProgressState } from '../src/ProgressAddon';

It feels abit like a bad hack (cyclic import?), but works locally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be referencing src from typing files. The more isolated the better as otherwise it can cause huge problems since libraries will suddenly be looking at and maybe linting against our source code, not just the types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah, good point. Gonna try to find a better workaround. Sadly enums are tricky to use with d.ts files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below.

Comment thread addons/addon-progress/typings/addon-progress.d.ts Outdated
Comment thread addons/addon-progress/typings/addon-progress.d.ts Outdated
@Tyriar Tyriar added this to the 6.0.0 milestone Dec 16, 2024
@Tyriar Tyriar self-assigned this Dec 16, 2024
@jerch

jerch commented Jan 7, 2025

Copy link
Copy Markdown
Member Author

@Tyriar applied your remarks, up for review again.

@jerch

jerch commented Jan 7, 2025

Copy link
Copy Markdown
Member Author

@Tyriar Found a way to borrow the emitter ctor from xterm until #5283 is resolved. With this change things are back to normal with only 1.4kB minified 💪 :

asset addon-progress.js 1.4 KiB [compared for emit] [minimized] (name: main) 1 related asset
./out/ProgressAddon.js 2.25 KiB [built] [code generated]

@Tyriar Tyriar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just some small polish things

Comment thread addons/addon-progress/README.md Outdated
});
// FIXME: borrow emitter ctor from xterm, to be changed once #5283 is resolved
this._onChange = new (terminal as any)._core._onData.constructor();
this.onChange = this._onChange!.event;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don' think the ! is needed?

@jerch jerch Jan 9, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesnt work without. My guess - the any cast above keeps the undefined as part of the type, so TS doesnt see this as undefined-guarded here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, this is temporary

Comment thread addons/addon-progress/typings/addon-progress.d.ts Outdated
Comment thread addons/addon-progress/typings/addon-progress.d.ts
Comment thread addons/addon-progress/typings/addon-progress.d.ts Outdated
jerch and others added 3 commits January 9, 2025 01:06
* Progress state tracked by the addon.
*/
export interface IProgressState {
state: 0 | 1 | 2 | 3 | 4;

@jerch jerch Jan 9, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar Tried using a const enum inside the d.ts - this worked fine for TS itself and webpack build, but not with esbuild. So I changed it back to that integer union thingy. (Btw that plain union type is easier to understand for JS folks...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine 👌

@Tyriar Tyriar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Will try adopt in vscode now microsoft/vscode#237564

@Tyriar Tyriar enabled auto-merge January 9, 2025 12:58
@Tyriar Tyriar merged commit 330e91e into xtermjs:master Jan 9, 2025
@Tyriar

Tyriar commented Jan 9, 2025

Copy link
Copy Markdown
Member

FYI in case you didn't see this kovidgoyal/kitty#8011 (comment)

@Tyriar

Tyriar commented Jan 9, 2025

Copy link
Copy Markdown
Member

I see winget uses indeterminate progress, do you know of another application that implements value/% based? (cargo coming soon)

@jerch

jerch commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

FYI in case you didn't see this kovidgoyal/kitty#8011 (comment)

Yeah, thats the reason why I had to exclude handling of OSC 9 that dont continue with ;4. There is a better more advanced spec for notifications than the old OSC 9 stuff, imho it got moved to OSC 99 with more advanced bells&whistles.

I see winget uses indeterminate progress, do you know of another application that implements value/% based? (cargo coming soon)

Nope, I dont. Systemd prolly uses that, but no clue in windows world.

@Tyriar

Tyriar commented Jan 9, 2025

Copy link
Copy Markdown
Member

winget's usage is a little unexpected since it seems to break up subtasks:

image

Not how I would have done it. I guess the progress state change should be debounced a little on my end to avoid a spinner flickering.

@jerch

jerch commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

@Tyriar Yeah, debouncing might be needed. The sequence isnt all that good in its spec - it is also unclear, how long to show the progress indicator or when to remove it (I'd guess that it should be removed after some time of inactivity, or after a window focus toggle etc)

@Tyriar

Tyriar commented Jan 9, 2025

Copy link
Copy Markdown
Member

In my implementation I considered clearing the state after a command is run. I guess it's kind of a necessity if the proc crashes/ctrl+c doesn't handle it, etc.

@jerch

jerch commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

I guess it needs a timeout running down, as we never know for sure when the terminal client app crashed or gave up for whatever reason.

@Tyriar

Tyriar commented Jan 9, 2025

Copy link
Copy Markdown
Member

I have it clearing when shell integration tells us any command finished: microsoft/vscode@86b257e

Seems like a fairly safe thing to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConEmu OSC progressbar support

3 participants