diff --git a/src/dialog.ts b/src/dialog.ts index 4b23073..1313715 100644 --- a/src/dialog.ts +++ b/src/dialog.ts @@ -81,6 +81,7 @@ export default class Dialog extends EventEmitter { process: ChildProcessWithoutNullStreams; output: string = ""; error: string = ""; + killing = false; constructor( public type_option: string, public args: DialogOptions, @@ -170,7 +171,7 @@ export default class Dialog extends EventEmitter { if (code !== 0) { if (!spawned) { reject({ code, message: this.error }); - } else { + } else if (!this.killing) { this.emit("error", code); } } else { @@ -190,4 +191,9 @@ export default class Dialog extends EventEmitter { }); }); } + + hide() { + this.killing = true; + return this.process.kill(); + } } diff --git a/src/index.ts b/src/index.ts index f8bfc1e..8aa0807 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,4 +6,5 @@ export { ItemsSelectedResponse, } from "./list"; export { default as Entry } from "./entry"; +export { default as Progress } from "./progress"; export { default as TextInfo } from "./text-info"; diff --git a/src/progress.ts b/src/progress.ts new file mode 100644 index 0000000..6d8bfb1 --- /dev/null +++ b/src/progress.ts @@ -0,0 +1,26 @@ +import Dialog, { DialogOptions } from "./dialog"; + +type ProgressOptions = Partial<{ text: string; pulsate: true; noCancel: true }>; + +export default class Progress { + private dialog: Dialog; + + async show(options: ProgressOptions): Promise { + this.dialog = new Dialog("progress", Progress.prepareOptions(options)); + await this.dialog.show(); + } + + static prepareOptions(options: ProgressOptions): DialogOptions { + const ret: DialogOptions = {}; + if (typeof options.text === "string") { + ret.text = options.text; + } + ret.pulsate = options.pulsate; + ret["no-cancel"] = options.noCancel; + return ret; + } + + async hide() { + return this.dialog.hide(); + } +}