Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress-addon #5251

Merged
merged 17 commits into from
Jan 9, 2025
Merged

progress-addon #5251

merged 17 commits into from
Jan 9, 2025

Conversation

jerch
Copy link
Member

@jerch jerch commented Dec 15, 2024

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.

Copy link
Member

@Tyriar Tyriar left a comment

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
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
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
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
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
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.

addons/addon-progress/typings/addon-progress.d.ts Outdated Show resolved Hide resolved
addons/addon-progress/typings/addon-progress.d.ts Outdated Show resolved Hide resolved
@Tyriar Tyriar added this to the 6.0.0 milestone Dec 16, 2024
@Tyriar Tyriar self-assigned this Dec 16, 2024
@jerch
Copy link
Member Author

jerch commented Jan 7, 2025

@Tyriar applied your remarks, up for review again.

@jerch
Copy link
Member Author

jerch commented Jan 7, 2025

@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]

Copy link
Member

@Tyriar Tyriar left a comment

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

addons/addon-progress/README.md Outdated Show resolved Hide resolved
});
// 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
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?

Copy link
Member Author

@jerch jerch Jan 9, 2025

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
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

addons/addon-progress/typings/addon-progress.d.ts Outdated Show resolved Hide resolved
addons/addon-progress/typings/addon-progress.d.ts Outdated Show resolved Hide resolved
addons/addon-progress/typings/addon-progress.d.ts Outdated Show resolved Hide resolved
* Progress state tracked by the addon.
*/
export interface IProgressState {
state: 0 | 1 | 2 | 3 | 4;
Copy link
Member Author

@jerch jerch Jan 9, 2025

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
Member

Choose a reason for hiding this comment

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

That's fine 👌

Copy link
Member

@Tyriar Tyriar left a comment

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
12 checks passed
@Tyriar
Copy link
Member

Tyriar commented Jan 9, 2025

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

@Tyriar
Copy link
Member

Tyriar commented Jan 9, 2025

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

@jerch
Copy link
Member Author

jerch commented Jan 9, 2025

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
Copy link
Member

Tyriar commented Jan 9, 2025

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
Copy link
Member Author

jerch commented Jan 9, 2025

@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
Copy link
Member

Tyriar commented Jan 9, 2025

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
Copy link
Member Author

jerch commented Jan 9, 2025

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
Copy link
Member

Tyriar commented Jan 9, 2025

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
2 participants