@spences10/pi-tui-modal 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export { run_with_progress_modal } from './modal/progress.js';
2
+ export type { ProgressModalController, ProgressModalOptions, ProgressModalUpdate, } from './modal/progress.js';
1
3
  export { show_confirm_modal, show_input_modal, show_modal, show_picker_modal, show_settings_modal, show_text_modal, } from './modal/show.js';
2
- export type { ConfirmModalOptions, InputModalOptions, ModalBody, ModalBorderStyle, ModalControls, ModalLayout, ModalMetadata, ModalOptions, ModalStyle, ModalText, PickerModalOptions, SettingsModalOptions, TextModalOptions, } from './modal/types.js';
4
+ export type { ConfirmModalOptions, InputModalOptions, ModalBody, ModalBorderStyle, ModalControls, ModalLayout, ModalMetadata, ModalOptions, ModalStyle, ModalText, ModalTheme, PickerModalOptions, SettingsModalOptions, TextModalOptions, } from './modal/types.js';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export { run_with_progress_modal } from './modal/progress.js';
1
2
  export { show_confirm_modal, show_input_modal, show_modal, show_picker_modal, show_settings_modal, show_text_modal, } from './modal/show.js';
2
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GACf,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAM9D,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GACf,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { ExtensionCommandContext } from '@earendil-works/pi-coding-agent';
2
+ import type { ModalOptions } from './types.js';
3
+ export interface ProgressModalUpdate {
4
+ message?: string;
5
+ current?: string;
6
+ completed?: number;
7
+ total?: number;
8
+ line?: string;
9
+ }
10
+ export interface ProgressModalController {
11
+ signal: AbortSignal;
12
+ update: (update: ProgressModalUpdate) => void;
13
+ }
14
+ export interface ProgressModalOptions extends ModalOptions {
15
+ message: string;
16
+ max_activity_lines?: number;
17
+ cancel_label?: string;
18
+ }
19
+ export declare function run_with_progress_modal<T>(ctx: ExtensionCommandContext, options: ProgressModalOptions, task: (controller: ProgressModalController) => Promise<T>): Promise<T | undefined>;
@@ -0,0 +1,120 @@
1
+ import { Key, matchesKey, truncateToWidth, } from '@earendil-works/pi-tui';
2
+ import { show_modal } from './show.js';
3
+ class ProgressModalBody {
4
+ tui;
5
+ theme;
6
+ state;
7
+ on_cancel;
8
+ max_activity_lines;
9
+ frame = 0;
10
+ frames = [
11
+ '⠋',
12
+ '⠙',
13
+ '⠹',
14
+ '⠸',
15
+ '⠼',
16
+ '⠴',
17
+ '⠦',
18
+ '⠧',
19
+ '⠇',
20
+ '⠏',
21
+ ];
22
+ interval;
23
+ constructor(tui, theme, state, on_cancel, max_activity_lines) {
24
+ this.tui = tui;
25
+ this.theme = theme;
26
+ this.state = state;
27
+ this.on_cancel = on_cancel;
28
+ this.max_activity_lines = max_activity_lines;
29
+ this.interval = setInterval(() => {
30
+ this.frame = (this.frame + 1) % this.frames.length;
31
+ this.tui.requestRender();
32
+ }, 120);
33
+ }
34
+ render(width) {
35
+ const spinner = this.theme.fg('accent', this.frames[this.frame] ?? '•');
36
+ const count = this.state.total !== undefined &&
37
+ this.state.completed !== undefined
38
+ ? this.theme.fg('dim', ` ${this.state.completed}/${this.state.total}`)
39
+ : '';
40
+ const lines = [`${spinner} ${this.state.message}${count}`];
41
+ if (this.state.current) {
42
+ lines.push(this.theme.fg('muted', `Current: ${this.state.current}`));
43
+ }
44
+ if (this.state.lines.length > 0) {
45
+ lines.push('', this.theme.fg('dim', 'Recent activity'));
46
+ lines.push(...this.state.lines.slice(-this.max_activity_lines));
47
+ }
48
+ return lines.map((line) => truncateToWidth(line, width));
49
+ }
50
+ handleInput(data) {
51
+ if (matchesKey(data, Key.escape))
52
+ this.on_cancel();
53
+ }
54
+ invalidate() { }
55
+ dispose() {
56
+ clearInterval(this.interval);
57
+ }
58
+ }
59
+ export async function run_with_progress_modal(ctx, options, task) {
60
+ const result = await show_modal(ctx, {
61
+ ...options,
62
+ footer: options.footer ?? `${options.cancel_label ?? 'esc'} cancel`,
63
+ overlay_options: {
64
+ width: '70%',
65
+ minWidth: 50,
66
+ maxHeight: '70%',
67
+ ...options.overlay_options,
68
+ },
69
+ }, ({ done }, theme, _layout, tui) => {
70
+ const abort_controller = new AbortController();
71
+ const state = {
72
+ message: options.message,
73
+ lines: [],
74
+ cancelled: false,
75
+ };
76
+ const update = (update) => {
77
+ if (update.message !== undefined)
78
+ state.message = update.message;
79
+ if (update.current !== undefined)
80
+ state.current = update.current;
81
+ if (update.completed !== undefined)
82
+ state.completed = update.completed;
83
+ if (update.total !== undefined)
84
+ state.total = update.total;
85
+ if (update.line)
86
+ state.lines.push(update.line);
87
+ tui.requestRender();
88
+ };
89
+ const body = new ProgressModalBody(tui, theme, state, () => {
90
+ if (state.cancelled)
91
+ return;
92
+ state.cancelled = true;
93
+ state.message = 'Cancelling...';
94
+ abort_controller.abort();
95
+ tui.requestRender();
96
+ }, options.max_activity_lines ?? 8);
97
+ void task({ signal: abort_controller.signal, update })
98
+ .then((value) => {
99
+ done(state.cancelled
100
+ ? { status: 'cancelled' }
101
+ : { status: 'success', value });
102
+ })
103
+ .catch((error) => {
104
+ if (state.cancelled || abort_controller.signal.aborted) {
105
+ done({ status: 'cancelled' });
106
+ return;
107
+ }
108
+ done({ status: 'error', error });
109
+ });
110
+ return body;
111
+ });
112
+ if (result.status === 'cancelled') {
113
+ ctx.ui.notify('Cancelled', 'info');
114
+ return undefined;
115
+ }
116
+ if (result.status === 'error')
117
+ throw result.error;
118
+ return result.value;
119
+ }
120
+ //# sourceMappingURL=progress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/modal/progress.ts"],"names":[],"mappings":"AACA,OAAO,EACN,GAAG,EACH,UAAU,EACV,eAAe,GAEf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAoCvC,MAAM,iBAAiB;IAiBJ;IACA;IACA;IACA;IACA;IApBV,KAAK,GAAG,CAAC,CAAC;IACD,MAAM,GAAG;QACzB,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;KACH,CAAC;IACe,QAAQ,CAAiB;IAE1C,YACkB,GAAQ,EACR,KAAiB,EACjB,KAAoB,EACpB,SAAqB,EACrB,kBAA0B;QAJ1B,QAAG,GAAH,GAAG,CAAK;QACR,UAAK,GAAL,KAAK,CAAY;QACjB,UAAK,GAAL,KAAK,CAAe;QACpB,cAAS,GAAT,SAAS,CAAY;QACrB,uBAAkB,GAAlB,kBAAkB,CAAQ;QAE3C,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;YAChC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACnD,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC1B,CAAC,EAAE,GAAG,CAAC,CAAC;IACT,CAAC;IAED,MAAM,CAAC,KAAa;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAC5B,QAAQ,EACR,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAC9B,CAAC;QACF,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M,CAAC,MAAM,KAAK,OAAO;QAAE,MAAM,MAAM,CAAC,KAAK,CAAC;IAClD,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spences10/pi-tui-modal",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Shared Pi TUI modal helpers for picker and settings overlays",
5
5
  "keywords": [
6
6
  "modal",
@@ -33,7 +33,7 @@
33
33
  "@earendil-works/pi-tui": "^0.74.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "^25.7.0",
36
+ "@types/node": "^25.8.0",
37
37
  "typescript": "^6.0.3",
38
38
  "vitest": "^4.1.6"
39
39
  },